Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Qobj into PulseQobj and QASM Qobj #1969

Merged
merged 18 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions qiskit/compiler/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

"""Assemble function for converting a list of circuits into a qobj"""
import uuid
import sympy

import numpy
import sympy

from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.qobj import Qobj, QobjConfig, QobjExperiment, QobjInstruction, QobjHeader
from qiskit.qobj import QobjExperimentConfig, QobjExperimentHeader, QobjConditional
from qiskit.compiler.run_config import RunConfig
from qiskit.qobj.utils import QobjType
from qiskit.qobj import QASMQobj
from qiskit.qobj import QASMQobjConfig, QASMQobjExperiment, QASMQobjInstruction, QASMQobjHeader
from qiskit.qobj import QASMQobjExperimentConfig, QASMQobjExperimentHeader
from qiskit.qobj import QobjConditional


def assemble_circuits(circuits, run_config=None, qobj_header=None, qobj_id=None):
Expand All @@ -23,18 +25,18 @@ def assemble_circuits(circuits, run_config=None, qobj_header=None, qobj_id=None)
Args:
circuits (list[QuantumCircuits] or QuantumCircuit): circuits to assemble
run_config (RunConfig): RunConfig object
qobj_header (QobjHeader): header to pass to the results
qobj_header (QASMQobjHeader): header to pass to the results
qobj_id (int): identifier for the generated qobj

Returns:
Qobj: the Qobj to be run on the backends
QASMQobj: the Qobj to be run on the backends
"""
qobj_header = qobj_header or QobjHeader()
qobj_header = qobj_header or QASMQobjHeader()
run_config = run_config or RunConfig()
if isinstance(circuits, QuantumCircuit):
circuits = [circuits]

userconfig = QobjConfig(**run_config.to_dict())
userconfig = QASMQobjConfig(**run_config.to_dict())
experiments = []
max_n_qubits = 0
max_memory_slots = 0
Expand All @@ -60,19 +62,19 @@ def assemble_circuits(circuits, run_config=None, qobj_header=None, qobj_id=None)

# TODO: why do we need creq_sizes and qreg_sizes in header
# TODO: we need to rethink memory_slots as they are tied to classical bit
experimentheader = QobjExperimentHeader(qubit_labels=qubit_labels,
n_qubits=n_qubits,
qreg_sizes=qreg_sizes,
clbit_labels=clbit_labels,
memory_slots=memory_slots,
creg_sizes=creg_sizes,
name=circuit.name)
experimentheader = QASMQobjExperimentHeader(qubit_labels=qubit_labels,
n_qubits=n_qubits,
qreg_sizes=qreg_sizes,
clbit_labels=clbit_labels,
memory_slots=memory_slots,
creg_sizes=creg_sizes,
name=circuit.name)
# TODO: why do we need n_qubits and memory_slots in both the header and the config
experimentconfig = QobjExperimentConfig(n_qubits=n_qubits, memory_slots=memory_slots)
experimentconfig = QASMQobjExperimentConfig(n_qubits=n_qubits, memory_slots=memory_slots)

instructions = []
for opt in circuit.data:
current_instruction = QobjInstruction(name=opt.name)
current_instruction = QASMQobjInstruction(name=opt.name)
if opt.qargs:
qubit_indices = [qubit_labels.index([qubit[0].name, qubit[1]])
for qubit in opt.qargs]
Expand Down Expand Up @@ -107,8 +109,8 @@ def assemble_circuits(circuits, run_config=None, qobj_header=None, qobj_id=None)
val="0x%X" % opt.control[1])

instructions.append(current_instruction)
experiments.append(QobjExperiment(instructions=instructions, header=experimentheader,
config=experimentconfig))
experiments.append(QASMQobjExperiment(instructions=instructions, header=experimentheader,
config=experimentconfig))
if n_qubits > max_n_qubits:
max_n_qubits = n_qubits
if memory_slots > max_memory_slots:
Expand All @@ -117,6 +119,5 @@ def assemble_circuits(circuits, run_config=None, qobj_header=None, qobj_id=None)
userconfig.memory_slots = max_memory_slots
userconfig.n_qubits = max_n_qubits

return Qobj(qobj_id=qobj_id or str(uuid.uuid4()), config=userconfig,
experiments=experiments, header=qobj_header,
type=QobjType.QASM.value)
return QASMQobj(qobj_id=qobj_id or str(uuid.uuid4()), config=userconfig,
experiments=experiments, header=qobj_header)
6 changes: 3 additions & 3 deletions qiskit/converters/circuits_to_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""Compile function for converting a list of circuits to the qobj"""
import warnings

from qiskit.qobj import QobjHeader
from qiskit.qobj import QASMQobjHeader
from qiskit.compiler.run_config import RunConfig
from qiskit.compiler import assemble_circuits

Expand All @@ -22,7 +22,7 @@ def circuits_to_qobj(circuits, qobj_header=None, run_config=None,

Args:
circuits (list[QuantumCircuits] or QuantumCircuit): circuits to compile
qobj_header (QobjHeader): header to pass to the results
qobj_header (QASMQobjHeader): header to pass to the results
run_config (RunConfig): RunConfig object

qobj_id (int): TODO: delete after qiskit-terra 0.8
Expand All @@ -42,7 +42,7 @@ def circuits_to_qobj(circuits, qobj_header=None, run_config=None,
'Use qiskit.compiler.assemble_circuits() to serialize circuits into a qobj.',
DeprecationWarning)

qobj_header = qobj_header or QobjHeader()
qobj_header = qobj_header or QASMQobjHeader()
run_config = run_config or RunConfig()

if backend_name:
Expand Down
8 changes: 4 additions & 4 deletions qiskit/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from qiskit.compiler import assemble_circuits, transpile
from qiskit.compiler import RunConfig, TranspileConfig
from qiskit.qobj import QobjHeader
from qiskit.qobj import QASMQobjHeader

logger = logging.getLogger(__name__)

Expand All @@ -35,7 +35,7 @@ def execute(circuits, backend, qobj_header=None, config=None, basis_gates=None,
Args:
circuits (QuantumCircuit or list[QuantumCircuit]): circuits to execute
backend (BaseBackend): a backend to execute the circuits on
qobj_header (QobjHeader): user input to go into the header
qobj_header (QASMQobjHeader): user input to go into the header
config (dict): dictionary of parameters (e.g. noise) used by runner
basis_gates (list[str]): list of basis gate names supported by the
target. Default: ['u1','u2','u3','cx','id']
Expand Down Expand Up @@ -96,7 +96,7 @@ def execute_circuits(circuits, backend, qobj_header=None,
Args:
circuits (QuantumCircuit or list[QuantumCircuit]): circuits to execute
backend (BaseBackend): a backend to execute the circuits on
qobj_header (QobjHeader): User input to go in the header
qobj_header (QASMQobjHeader): User input to go in the header
transpile_config (TranspileConfig): Configurations for the transpiler
run_config (RunConfig): Run Configuration
kwargs: extra arguments used by AER for running configurable backends.
Expand All @@ -113,7 +113,7 @@ def execute_circuits(circuits, backend, qobj_header=None,
# ------

# filling in the header with the backend name the qobj was run on
qobj_header = qobj_header or QobjHeader()
qobj_header = qobj_header or QASMQobjHeader()
qobj_header.backend_name = backend.name()

# default values
Expand Down
9 changes: 7 additions & 2 deletions qiskit/qobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

"""Module for the Qobj structure."""

from .qobj import Qobj
from .qobj import Qobj, QASMQobj, PulseQobj
from .models import (QobjConfig, QobjExperiment, QobjInstruction, QobjHeader,
QobjExperimentHeader, QobjConditional, QobjExperimentConfig)
QobjExperimentConfig, QobjExperimentHeader,
QobjConditional, QobjPulseLibrary, QobjMeasurementOption,
QASMQobjConfig, QASMQobjExperiment, QASMQobjInstruction, QASMQobjHeader,
QASMQobjExperimentHeader, QASMQobjExperimentConfig,
PulseQobjConfig, PulseQobjExperiment, PulseQobjInstruction,
PulseQobjHeader, PulseQobjExperimentHeader, PulseQobjExperimentConfig)
from .exceptions import QobjValidationError

from ._validation import validate_qobj_against_schema
Loading