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 BasicSimulator.configuration #13367

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 17 additions & 4 deletions qiskit/compiler/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ def assemble(
)


# Note for future: this method is used in `BasicSimulator` and may need to be kept past the
# `assemble` removal deadline (2.0). If it is kept (potentially in a different location),
# we will need an alternative for the backend.configuration() access that currently takes
# place in L566 (`parse_circuit_args`) and L351 (`parse_common_args`)
# because backend.configuration() is also set for removal in 2.0.
# The ultimate goal will be to move away from relying on any kind of `assemble` implementation
# because of how tightly coupled it is to these legacy data structures. But as a transition step,
# given that we would only have to support the subcase of `BasicSimulator`, we could probably just
# inline the relevant config values that are already hardcoded in the basic simulator configuration
# generator.
Comment on lines +192 to +201
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, it should not be hard to rewrite the run_experiment method of basic simulator to avoid needing qobj. The assemble usage in there is kind of a weird legacy from BaseBackend which required a qobj get passed to the run() method.

def _assemble(
experiments: Union[
QuantumCircuit,
Expand Down Expand Up @@ -229,7 +239,7 @@ def _assemble(
experiments = experiments if isinstance(experiments, list) else [experiments]
pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments)
with warnings.catch_warnings():
# The Qobj is deprecated
# The Qobj class is deprecated, the backend.configuration() method is too
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
qobj_id, qobj_header, run_config_common_dict = _parse_common_args(
backend,
Expand Down Expand Up @@ -554,9 +564,12 @@ def _parse_circuit_args(
run_config_dict = {"parameter_binds": parameter_binds, **run_config}
if parametric_pulses is None:
if backend:
run_config_dict["parametric_pulses"] = getattr(
backend.configuration(), "parametric_pulses", []
)
with warnings.catch_warnings():
# TODO (2.0): See comment on L192 regarding backend.configuration removal
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
run_config_dict["parametric_pulses"] = getattr(
backend.configuration(), "parametric_pulses", []
)
else:
run_config_dict["parametric_pulses"] = []
else:
Expand Down
12 changes: 11 additions & 1 deletion qiskit/providers/basic_provider/basic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from qiskit.qobj import QasmQobj, QasmQobjConfig, QasmQobjExperiment
from qiskit.result import Result
from qiskit.transpiler import Target
from qiskit.utils.deprecation import deprecate_func

from .basic_provider_job import BasicProviderJob
from .basic_provider_tools import single_gate_matrix
Expand Down Expand Up @@ -212,6 +213,14 @@ def _build_basic_target(self) -> Target:
)
return target

@deprecate_func(
since="1.3.0",
removal_timeline="in Qiskit 2.0.0",
additional_msg="The `BackendConfiguration` class is part of the deprecated `BackendV1` "
"workflow, and no longer necessary for `BackendV2`. The individual configuration elements "
"can be retrieved directly from the backend or from the contained `Target` instance "
"(`backend.target)`).",
)
def configuration(self) -> BackendConfiguration:
"""Return the simulator backend configuration.

Expand Down Expand Up @@ -532,7 +541,8 @@ def run(
"initial_statevector": np.array([1, 0, 0, 1j]) / math.sqrt(2),
}
"""
# TODO: replace assemble with new run flow
# TODO: replace assemble with new run flow. If this is not achieved before 2.0,
# see removal note on `def _assemble`, L192 of qiskit/compiler/assembler.py
from qiskit.compiler.assembler import _assemble

out_options = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
deprecations_providers:
- |
The :meth:`.BasicSimulator.configuration` method is deprecated and will be removed in 2.0.0.
This method returned a legacy ``providers.models.BackendConfiguration`` instance which is part
of the deprecated ``BackendV1`` model. This model has been replaced with :class:`.BackendV2`,
where the constraints are stored directly in the backend instance or the underlying :class:`.Target`
(``backend.target``).

Here is a quick guide for accessing the most common ``BackendConfiguration`` attributes in the
:class:`BackendV2` model:""

BackendV1 model (deprecated) ------------> BackendV2 model
---------------------------- ---------------
backend.configuration().backend_name backend.name
backend.configuration().backend_version backend.backend_version
backend.configuration().n_qubits backend.num_qubits
backend.configuration().num_qubits backend.num_qubits
backend.configuration().basis_gates backend.target.operation_names (*)
backend.configuration().coupling_map backend.target.build_coupling_map()
backend.configuration().local No representation
backend.configuration().simulator No representation
backend.configuration().conditional No representation
backend.configuration().open_pulse No representation
backend.configuration().memory No representation
backend.configuration().max_shots No representation

(*) Note that ``backend.target.operation_names`` includes ``basis_gates`` and additional
non-gate instructions, in some implementations it might be necessary to filter the output.

See `this guide <https://docs.quantum.ibm.com/api/qiskit/providers#migrating-from-backendv1-to-backendv2>`__
for more information on migrating to the ``BackendV2`` model.
4 changes: 3 additions & 1 deletion test/python/providers/basic_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class BasicProviderBackendTestMixin:

def test_configuration(self):
"""Test backend.configuration()."""
configuration = self.backend.configuration()
with self.assertWarns(DeprecationWarning):
# The method is deprecated
configuration = self.backend.configuration()
return configuration

def test_run_circuit(self):
Expand Down