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

Deprecate Qobj and assemble #12649

Merged
merged 59 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2e99d5a
deprecate qobj and assemble
1ucian0 Jun 24, 2024
76e6dd5
reno
1ucian0 Jun 24, 2024
b57241c
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jun 27, 2024
a398425
shallow deprecation of assemble
1ucian0 Jun 27, 2024
6d96cc8
test.python.compiler.test_disassembler
1ucian0 Jun 27, 2024
e0a3999
fakebackend pulse
1ucian0 Jun 28, 2024
79f67c2
test.python.circuit.test_parameters
1ucian0 Jun 28, 2024
66c6490
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jun 28, 2024
2bba185
PulseQobjInstruction is used by GenericBackendV2
1ucian0 Jun 28, 2024
b809ace
test.python.scheduler.test_basic_scheduler
1ucian0 Jun 28, 2024
e5c5b43
test.python.result.test_result
1ucian0 Jun 28, 2024
7edd883
test.python.pulse.test_calibration_entries
1ucian0 Jun 28, 2024
b5e8b28
test.python.compiler.test_assembler
1ucian0 Jun 28, 2024
a2ee3b3
test.python.transpiler.test_star_prerouting
1ucian0 Jul 1, 2024
8a56629
test.python.pulse.test_instruction_schedule_map
1ucian0 Jul 1, 2024
249ccb7
test.python.providers.basic_provider.test_basic_simulator
1ucian0 Jul 1, 2024
e48d295
test.python.primitives.test_backend_sampler_v2
1ucian0 Jul 1, 2024
50a350a
test.python.compiler.test_disassembler
1ucian0 Jul 1, 2024
fefb294
test.python.compiler.test_compiler
1ucian0 Jul 1, 2024
da38a72
test.python.circuit.test_scheduled_circuit
1ucian0 Jul 1, 2024
a418008
test.python.providers.test_fake_backends
1ucian0 Jul 1, 2024
a3f0c79
test.python.circuit.test_unitary
1ucian0 Jul 1, 2024
2c99f28
test.python.transpiler.test_sabre_swap
1ucian0 Jul 1, 2024
5124403
test.python.providers.fake_provider.test_fake_backends
1ucian0 Jul 1, 2024
884d394
Aer using Provider ABC
1ucian0 Jul 1, 2024
ada3d38
aer warnings
1ucian0 Jul 2, 2024
593fabb
reno
1ucian0 Jul 2, 2024
1d781b0
another pass on reno
1ucian0 Jul 3, 2024
621e72a
test.python.pulse
1ucian0 Jul 3, 2024
3898c77
test.python.compiler.test_compiler
1ucian0 Jul 3, 2024
c2f2fdb
add module to fiterwarning
1ucian0 Jul 3, 2024
73dd5af
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jul 4, 2024
82032bc
test.python.compiler.test_transpiler
1ucian0 Jul 4, 2024
963b1ae
fixing obscure expcetion handleing for comparison
1ucian0 Jul 4, 2024
d185d7e
Apply suggestions from code review
1ucian0 Jul 21, 2024
ac54cd8
remove catch
1ucian0 Jul 21, 2024
9cd165b
new deprecate warning message
1ucian0 Jul 21, 2024
01c6716
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jul 21, 2024
a45431a
lint qiskit/assembler/assemble_circuits.py
1ucian0 Jul 22, 2024
4751fe1
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jul 22, 2024
fa7f32d
concurrency warnings
1ucian0 Jul 22, 2024
2a085b5
ignore aer warnings
1ucian0 Jul 22, 2024
5e63bef
Update test/python/providers/fake_provider/test_fake_backends.py
1ucian0 Jul 23, 2024
83332e5
Update test/python/circuit/test_parameters.py
1ucian0 Jul 23, 2024
60cc9c5
Update qiskit/providers/models/pulsedefaults.py
1ucian0 Jul 23, 2024
1362b1b
Update test/python/providers/fake_provider/test_fake_backends.py
1ucian0 Jul 23, 2024
787090f
Update test/python/providers/fake_provider/test_generic_backend_v2.py
1ucian0 Jul 23, 2024
20a0c5c
lint
1ucian0 Jul 23, 2024
bd216a1
https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717954
1ucian0 Jul 23, 2024
c1c3b32
https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717732
1ucian0 Jul 23, 2024
7a2b3f7
Update test/python/transpiler/test_sabre_swap.py
1ucian0 Jul 23, 2024
5f19ae9
Update qiskit/providers/models/pulsedefaults.py
1ucian0 Jul 23, 2024
f8760ee
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jul 23, 2024
a761b2d
ignore Treating CircuitInstruction...
1ucian0 Jul 23, 2024
264f2af
another unnecessary catch from aer
1ucian0 Jul 24, 2024
4c76ad0
another unnecessary catch from aer, again
1ucian0 Jul 24, 2024
9741934
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jul 24, 2024
4e83c99
Merge branch 'main' of github.com:Qiskit/qiskit-terra into deprecate/…
1ucian0 Jul 25, 2024
b69bdf9
removing more unnecesary catches
1ucian0 Jul 25, 2024
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
171 changes: 107 additions & 64 deletions qiskit/assembler/assemble_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

"""Assemble function for converting a list of circuits into a qobj."""
import copy
import warnings
from collections import defaultdict
from typing import Dict, List, Optional, Tuple

Expand All @@ -35,6 +36,7 @@
QobjHeader,
)
from qiskit.utils.parallel import parallel_map
from qiskit.utils import deprecate_func


PulseLibrary = Dict[str, List[complex]]
Expand Down Expand Up @@ -87,20 +89,26 @@ def _assemble_circuit(
metadata = circuit.metadata
if metadata is None:
metadata = {}
header = QobjExperimentHeader(
qubit_labels=qubit_labels,
n_qubits=num_qubits,
qreg_sizes=qreg_sizes,
clbit_labels=clbit_labels,
memory_slots=memory_slots,
creg_sizes=creg_sizes,
name=circuit.name,
global_phase=float(circuit.global_phase),
metadata=metadata,
)
with warnings.catch_warnings():
# The class QobjExperimentHeader is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
header = QobjExperimentHeader(
qubit_labels=qubit_labels,
n_qubits=num_qubits,
qreg_sizes=qreg_sizes,
clbit_labels=clbit_labels,
memory_slots=memory_slots,
creg_sizes=creg_sizes,
name=circuit.name,
global_phase=float(circuit.global_phase),
metadata=metadata,
)

# TODO: why do we need n_qubits and memory_slots in both the header and the config
config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots)
with warnings.catch_warnings():
# The class QasmQobjExperimentConfig is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots)
calibrations, pulse_library = _assemble_pulse_gates(circuit, run_config)
if calibrations:
config.calibrations = calibrations
Expand All @@ -118,7 +126,7 @@ def _assemble_circuit(

instructions = []
for op_context in circuit.data:
instruction = op_context.operation.assemble()
instruction = op_context.operation._assemble()
1ucian0 marked this conversation as resolved.
Show resolved Hide resolved

# Add register attributes to the instruction
qargs = op_context.qubits
Expand Down Expand Up @@ -151,13 +159,16 @@ def _assemble_circuit(
]

conditional_reg_idx = memory_slots + max_conditional_idx
conversion_bfunc = QasmQobjInstruction(
name="bfunc",
mask="0x%X" % mask, # pylint: disable=consider-using-f-string
relation="==",
val="0x%X" % val, # pylint: disable=consider-using-f-string
register=conditional_reg_idx,
)
with warnings.catch_warnings():
# The class QasmQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
conversion_bfunc = QasmQobjInstruction(
name="bfunc",
mask="0x%X" % mask, # pylint: disable=consider-using-f-string
relation="==",
val="0x%X" % val, # pylint: disable=consider-using-f-string
register=conditional_reg_idx,
)
instructions.append(conversion_bfunc)
instruction.conditional = conditional_reg_idx
max_conditional_idx += 1
Expand All @@ -166,10 +177,13 @@ def _assemble_circuit(
del instruction._condition

instructions.append(instruction)
return (
QasmQobjExperiment(instructions=instructions, header=header, config=config),
pulse_library,
)
with warnings.catch_warnings():
# The class QasmQobjExperiment is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
return (
QasmQobjExperiment(instructions=instructions, header=header, config=config),
pulse_library,
)


def _assemble_pulse_gates(
Expand Down Expand Up @@ -299,42 +313,14 @@ def _configure_experiment_los(
return experiments


def assemble_circuits(
def _assemble_circuits(
circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader
) -> QasmQobj:
"""Assembles a list of circuits into a qobj that can be run on the backend.

Args:
circuits: circuit(s) to assemble
run_config: configuration of the runtime environment
qobj_id: identifier for the generated qobj
qobj_header: header to pass to the results

Returns:
The qobj to be run on the backends

Examples:

.. code-block:: python

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))
"""
# assemble the circuit experiments
experiments_and_pulse_libs = parallel_map(_assemble_circuit, circuits, [run_config])
with warnings.catch_warnings():
# Still constructs Qobj, that is deprecated. The message is hard to trace to a module,
# because concurrency is hard.
warnings.filterwarnings("ignore", category=DeprecationWarning)
experiments_and_pulse_libs = parallel_map(_assemble_circuit, circuits, [run_config])
experiments = []
pulse_library = {}
for exp, lib in experiments_and_pulse_libs:
Expand All @@ -346,10 +332,16 @@ def assemble_circuits(
experiments, calibrations = _extract_common_calibrations(experiments)

# configure LO freqs per circuit
lo_converter = converters.LoConfigConverter(QasmQobjExperimentConfig, **run_config.to_dict())
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
lo_converter = converters.LoConfigConverter(
QasmQobjExperimentConfig, **run_config.to_dict()
)
experiments = _configure_experiment_los(experiments, lo_converter, run_config)

qobj_config = QasmQobjConfig()
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
qobj_config = QasmQobjConfig()
if run_config:
qobj_config_dict = run_config.to_dict()

Expand Down Expand Up @@ -379,7 +371,10 @@ def assemble_circuits(
if m_los:
qobj_config_dict["meas_lo_freq"] = [freq / 1e9 for freq in m_los]

qobj_config = QasmQobjConfig(**qobj_config_dict)
with warnings.catch_warnings():
# The class QasmQobjConfig is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
qobj_config = QasmQobjConfig(**qobj_config_dict)

qubit_sizes = []
memory_slot_sizes = []
Expand All @@ -402,7 +397,55 @@ def assemble_circuits(

if calibrations and calibrations.gates:
qobj_config.calibrations = calibrations
with warnings.catch_warnings():
# The class QasmQobj is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
return QasmQobj(
qobj_id=qobj_id, config=qobj_config, experiments=experiments, header=qobj_header
)

return QasmQobj(
qobj_id=qobj_id, config=qobj_config, experiments=experiments, header=qobj_header
)

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated `BackendV1` "
"workflow, and no longer necessary for `BackendV2`. If a user workflow requires "
"`Qobj` it likely relies on deprecated functionality and should be updated to "
"use `BackendV2`.",
)
def assemble_circuits(
circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader
) -> QasmQobj:
"""Assembles a list of circuits into a qobj that can be run on the backend.

Args:
circuits: circuit(s) to assemble
run_config: configuration of the runtime environment
qobj_id: identifier for the generated qobj
qobj_header: header to pass to the results

Returns:
The qobj to be run on the backends

Examples:

.. code-block:: python

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))
"""
# assemble the circuit experiments
return _assemble_circuits(circuits, run_config, qobj_id, qobj_header)
9 changes: 9 additions & 0 deletions qiskit/assembler/disassemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from qiskit.qobj import PulseQobjInstruction
from qiskit.qobj.converters import QobjToInstructionConverter
from qiskit.utils import deprecate_func

# A ``CircuitModule`` is a representation of a circuit execution on the backend.
# It is currently a list of quantum circuits to execute, a run Qobj dictionary
Expand All @@ -37,6 +38,14 @@
PulseModule = NewType("PulseModule", Tuple[List[pulse.Schedule], Dict[str, Any], Dict[str, Any]])


@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def disassemble(qobj) -> Union[CircuitModule, PulseModule]:
"""Disassemble a qobj and return the circuits or pulse schedules, run_config, and user header.

Expand Down
19 changes: 17 additions & 2 deletions qiskit/circuit/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from __future__ import annotations

import copy
import warnings
from itertools import zip_longest
import math
from typing import List, Type
Expand All @@ -47,7 +48,7 @@
from qiskit.circuit.operation import Operation

from qiskit.circuit.annotated_operation import AnnotatedOperation, InverseModifier

from qiskit.utils import deprecate_func

_CUTOFF_PRECISION = 1e-10

Expand Down Expand Up @@ -359,9 +360,23 @@ def unit(self, unit):
"""Set the time unit of duration."""
self._unit = unit

@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def assemble(self):
"""Assemble a QasmQobjInstruction"""
instruction = QasmQobjInstruction(name=self.name)
return self._assemble()

def _assemble(self):
with warnings.catch_warnings():
# The class QasmQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
instruction = QasmQobjInstruction(name=self.name)
# Evaluate parameters
if self.params:
params = [x.evalf(x) if hasattr(x, "evalf") else x for x in self.params]
Expand Down
Loading
Loading