1212
1313"""Assemble function for converting a list of circuits into a qobj."""
1414import copy
15+ import warnings
1516from collections import defaultdict
1617from typing import Dict , List , Optional , Tuple
1718
3536 QobjHeader ,
3637)
3738from qiskit .utils .parallel import parallel_map
39+ from qiskit .utils import deprecate_func
3840
3941
4042PulseLibrary = Dict [str , List [complex ]]
@@ -87,20 +89,26 @@ def _assemble_circuit(
8789 metadata = circuit .metadata
8890 if metadata is None :
8991 metadata = {}
90- header = QobjExperimentHeader (
91- qubit_labels = qubit_labels ,
92- n_qubits = num_qubits ,
93- qreg_sizes = qreg_sizes ,
94- clbit_labels = clbit_labels ,
95- memory_slots = memory_slots ,
96- creg_sizes = creg_sizes ,
97- name = circuit .name ,
98- global_phase = float (circuit .global_phase ),
99- metadata = metadata ,
100- )
92+ with warnings .catch_warnings ():
93+ # The class QobjExperimentHeader is deprecated
94+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
95+ header = QobjExperimentHeader (
96+ qubit_labels = qubit_labels ,
97+ n_qubits = num_qubits ,
98+ qreg_sizes = qreg_sizes ,
99+ clbit_labels = clbit_labels ,
100+ memory_slots = memory_slots ,
101+ creg_sizes = creg_sizes ,
102+ name = circuit .name ,
103+ global_phase = float (circuit .global_phase ),
104+ metadata = metadata ,
105+ )
101106
102107 # TODO: why do we need n_qubits and memory_slots in both the header and the config
103- config = QasmQobjExperimentConfig (n_qubits = num_qubits , memory_slots = memory_slots )
108+ with warnings .catch_warnings ():
109+ # The class QasmQobjExperimentConfig is deprecated
110+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
111+ config = QasmQobjExperimentConfig (n_qubits = num_qubits , memory_slots = memory_slots )
104112 calibrations , pulse_library = _assemble_pulse_gates (circuit , run_config )
105113 if calibrations :
106114 config .calibrations = calibrations
@@ -118,7 +126,7 @@ def _assemble_circuit(
118126
119127 instructions = []
120128 for op_context in circuit .data :
121- instruction = op_context .operation .assemble ()
129+ instruction = op_context .operation ._assemble ()
122130
123131 # Add register attributes to the instruction
124132 qargs = op_context .qubits
@@ -151,13 +159,16 @@ def _assemble_circuit(
151159 ]
152160
153161 conditional_reg_idx = memory_slots + max_conditional_idx
154- conversion_bfunc = QasmQobjInstruction (
155- name = "bfunc" ,
156- mask = "0x%X" % mask , # pylint: disable=consider-using-f-string
157- relation = "==" ,
158- val = "0x%X" % val , # pylint: disable=consider-using-f-string
159- register = conditional_reg_idx ,
160- )
162+ with warnings .catch_warnings ():
163+ # The class QasmQobjInstruction is deprecated
164+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
165+ conversion_bfunc = QasmQobjInstruction (
166+ name = "bfunc" ,
167+ mask = "0x%X" % mask , # pylint: disable=consider-using-f-string
168+ relation = "==" ,
169+ val = "0x%X" % val , # pylint: disable=consider-using-f-string
170+ register = conditional_reg_idx ,
171+ )
161172 instructions .append (conversion_bfunc )
162173 instruction .conditional = conditional_reg_idx
163174 max_conditional_idx += 1
@@ -166,10 +177,13 @@ def _assemble_circuit(
166177 del instruction ._condition
167178
168179 instructions .append (instruction )
169- return (
170- QasmQobjExperiment (instructions = instructions , header = header , config = config ),
171- pulse_library ,
172- )
180+ with warnings .catch_warnings ():
181+ # The class QasmQobjExperiment is deprecated
182+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
183+ return (
184+ QasmQobjExperiment (instructions = instructions , header = header , config = config ),
185+ pulse_library ,
186+ )
173187
174188
175189def _assemble_pulse_gates (
@@ -299,42 +313,14 @@ def _configure_experiment_los(
299313 return experiments
300314
301315
302- def assemble_circuits (
316+ def _assemble_circuits (
303317 circuits : List [QuantumCircuit ], run_config : RunConfig , qobj_id : int , qobj_header : QobjHeader
304318) -> QasmQobj :
305- """Assembles a list of circuits into a qobj that can be run on the backend.
306-
307- Args:
308- circuits: circuit(s) to assemble
309- run_config: configuration of the runtime environment
310- qobj_id: identifier for the generated qobj
311- qobj_header: header to pass to the results
312-
313- Returns:
314- The qobj to be run on the backends
315-
316- Examples:
317-
318- .. code-block:: python
319-
320- from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
321- from qiskit.assembler import assemble_circuits
322- from qiskit.assembler.run_config import RunConfig
323- # Build a circuit to convert into a Qobj
324- q = QuantumRegister(2)
325- c = ClassicalRegister(2)
326- qc = QuantumCircuit(q, c)
327- qc.h(q[0])
328- qc.cx(q[0], q[1])
329- qc.measure(q, c)
330- # Assemble a Qobj from the input circuit
331- qobj = assemble_circuits(circuits=[qc],
332- qobj_id="custom-id",
333- qobj_header=[],
334- run_config=RunConfig(shots=2000, memory=True, init_qubits=True))
335- """
336- # assemble the circuit experiments
337- experiments_and_pulse_libs = parallel_map (_assemble_circuit , circuits , [run_config ])
319+ with warnings .catch_warnings ():
320+ # Still constructs Qobj, that is deprecated. The message is hard to trace to a module,
321+ # because concurrency is hard.
322+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
323+ experiments_and_pulse_libs = parallel_map (_assemble_circuit , circuits , [run_config ])
338324 experiments = []
339325 pulse_library = {}
340326 for exp , lib in experiments_and_pulse_libs :
@@ -346,10 +332,16 @@ def assemble_circuits(
346332 experiments , calibrations = _extract_common_calibrations (experiments )
347333
348334 # configure LO freqs per circuit
349- lo_converter = converters .LoConfigConverter (QasmQobjExperimentConfig , ** run_config .to_dict ())
335+ with warnings .catch_warnings ():
336+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
337+ lo_converter = converters .LoConfigConverter (
338+ QasmQobjExperimentConfig , ** run_config .to_dict ()
339+ )
350340 experiments = _configure_experiment_los (experiments , lo_converter , run_config )
351341
352- qobj_config = QasmQobjConfig ()
342+ with warnings .catch_warnings ():
343+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
344+ qobj_config = QasmQobjConfig ()
353345 if run_config :
354346 qobj_config_dict = run_config .to_dict ()
355347
@@ -379,7 +371,10 @@ def assemble_circuits(
379371 if m_los :
380372 qobj_config_dict ["meas_lo_freq" ] = [freq / 1e9 for freq in m_los ]
381373
382- qobj_config = QasmQobjConfig (** qobj_config_dict )
374+ with warnings .catch_warnings ():
375+ # The class QasmQobjConfig is deprecated
376+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
377+ qobj_config = QasmQobjConfig (** qobj_config_dict )
383378
384379 qubit_sizes = []
385380 memory_slot_sizes = []
@@ -402,7 +397,55 @@ def assemble_circuits(
402397
403398 if calibrations and calibrations .gates :
404399 qobj_config .calibrations = calibrations
400+ with warnings .catch_warnings ():
401+ # The class QasmQobj is deprecated
402+ warnings .filterwarnings ("ignore" , category = DeprecationWarning , module = "qiskit" )
403+ return QasmQobj (
404+ qobj_id = qobj_id , config = qobj_config , experiments = experiments , header = qobj_header
405+ )
405406
406- return QasmQobj (
407- qobj_id = qobj_id , config = qobj_config , experiments = experiments , header = qobj_header
408- )
407+
408+ @deprecate_func (
409+ since = "1.2" ,
410+ removal_timeline = "in the 2.0 release" ,
411+ additional_msg = "The `Qobj` class and related functionality are part of the deprecated `BackendV1` "
412+ "workflow, and no longer necessary for `BackendV2`. If a user workflow requires "
413+ "`Qobj` it likely relies on deprecated functionality and should be updated to "
414+ "use `BackendV2`." ,
415+ )
416+ def assemble_circuits (
417+ circuits : List [QuantumCircuit ], run_config : RunConfig , qobj_id : int , qobj_header : QobjHeader
418+ ) -> QasmQobj :
419+ """Assembles a list of circuits into a qobj that can be run on the backend.
420+
421+ Args:
422+ circuits: circuit(s) to assemble
423+ run_config: configuration of the runtime environment
424+ qobj_id: identifier for the generated qobj
425+ qobj_header: header to pass to the results
426+
427+ Returns:
428+ The qobj to be run on the backends
429+
430+ Examples:
431+
432+ .. code-block:: python
433+
434+ from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
435+ from qiskit.assembler import assemble_circuits
436+ from qiskit.assembler.run_config import RunConfig
437+ # Build a circuit to convert into a Qobj
438+ q = QuantumRegister(2)
439+ c = ClassicalRegister(2)
440+ qc = QuantumCircuit(q, c)
441+ qc.h(q[0])
442+ qc.cx(q[0], q[1])
443+ qc.measure(q, c)
444+ # Assemble a Qobj from the input circuit
445+ qobj = assemble_circuits(circuits=[qc],
446+ qobj_id="custom-id",
447+ qobj_header=[],
448+ run_config=RunConfig(shots=2000, memory=True, init_qubits=True))
449+ """
450+ # assemble the circuit experiments
451+ return _assemble_circuits (circuits , run_config , qobj_id , qobj_header )
0 commit comments