Circuit and Schedule Assembler (qiskit.assembler)#

Circuit Assembler#

qiskit.assembler.assemble_circuits(circuits, run_config, qobj_id, qobj_header)[ソース]#

Assembles a list of circuits into a qobj that can be run on the backend.

パラメータ:
  • circuits (List[QuantumCircuit]) – circuit(s) to assemble

  • run_config (RunConfig) – configuration of the runtime environment

  • qobj_id (int) – identifier for the generated qobj

  • qobj_header (QobjHeader) – header to pass to the results

戻り値:

The qobj to be run on the backends

戻り値の型:

QasmQobj

サンプル

from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.assembler import assemble_circuits
from qiskit.assembler.run_config import RunConfig
# Build a circuit to convert into a Qobj
q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q, c)
qc.h(q[0])
qc.cx(q[0], q[1])
qc.measure(q, c)
# Assemble a Qobj from the input circuit
qobj = assemble_circuits(circuits=[qc],
                         qobj_id="custom-id",
                         qobj_header=[],
                         run_config=RunConfig(shots=2000, memory=True, init_qubits=True))

Schedule Assembler#

qiskit.assembler.assemble_schedules(schedules, qobj_id, qobj_header, run_config)[ソース]#

Assembles a list of schedules into a qobj that can be run on the backend.

パラメータ:
戻り値:

The Qobj to be run on the backends.

例外:

QiskitError – when frequency settings are not supplied.

戻り値の型:

PulseQobj

サンプル

from qiskit import pulse
from qiskit.assembler import assemble_schedules
from qiskit.assembler.run_config import RunConfig
# Construct a Qobj header for the output Qobj
header = {"backend_name": "FakeOpenPulse2Q", "backend_version": "0.0.0"}
# Build a configuration object for the output Qobj
config = RunConfig(shots=1024,
                   memory=False,
                   meas_level=1,
                   meas_return='avg',
                   memory_slot_size=100,
                   parametric_pulses=[],
                   init_qubits=True,
                   qubit_lo_freq=[4900000000.0, 5000000000.0],
                   meas_lo_freq=[6500000000.0, 6600000000.0],
                   schedule_los=[])
# Build a Pulse schedule to assemble into a Qobj
schedule = pulse.Schedule()
schedule += pulse.Play(pulse.Waveform([0.1] * 16, name="test0"),
                       pulse.DriveChannel(0),
                       name="test1")
schedule += pulse.Play(pulse.Waveform([0.1] * 16, name="test1"),
                       pulse.DriveChannel(0),
                       name="test2")
schedule += pulse.Play(pulse.Waveform([0.5] * 16, name="test0"),
                       pulse.DriveChannel(0),
                       name="test1")
# Assemble a Qobj from the schedule.
pulseQobj = assemble_schedules(schedules=[schedule],
                               qobj_id="custom-id",
                               qobj_header=header,
                               run_config=config)

Disassembler#

qiskit.assembler.disassemble(qobj)[ソース]#

Disassemble a qobj and return the circuits or pulse schedules, run_config, and user header.

注釈

disassemble(assemble(qc)) is not guaranteed to produce an exactly equal circuit to the input, due to limitations in the QasmQobj format that need to be maintained for backend system compatibility. This is most likely to be the case when using newer features of QuantumCircuit. In most cases, the output should be equivalent, if not quite equal.

パラメータ:

qobj (Qobj) – The input qobj object to disassemble

戻り値:

The disassembled program which consists of:

  • programs: A list of quantum circuits or pulse schedules

  • run_config: The dict of the run config

  • user_qobj_header: The dict of any user headers in the qobj

戻り値の型:

Union[CircuitModule, PulseModule]

サンプル

from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.compiler.assembler import assemble
from qiskit.assembler.disassemble import disassemble
# Create a circuit to assemble into a qobj
q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q, c)
qc.h(q[0])
qc.cx(q[0], q[1])
qc.measure(q, c)
# Assemble the circuit into a Qobj
qobj = assemble(qc, shots=2000, memory=True)
# Disassemble the qobj back into a circuit
circuits, run_config_out, headers = disassemble(qobj)

RunConfig#

RunConfig([shots, seed_simulator, memory, ...])

Class for Run Configuration.