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

Follow through with PendingDeprecationWarnings #8023

Closed
39 changes: 28 additions & 11 deletions qiskit/circuit/qpy_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@

"""Alias for Qiskit QPY import."""

# TODO deprecate this in 0.21.0
from qiskit.qpy import dump, load

# For backward compatibility. Provide, Runtime, Experiment call these private functions.
from qiskit.qpy import (
_write_instruction,
_read_instruction,
_write_parameter_expression,
_read_parameter_expression,
_read_parameter_expression_v3,
)
import warnings

from qiskit import qpy


deprecated_names = {
"dump",
"load",
# For backward compatibility. Provide, Runtime, Experiment call these private functions.
"_write_instruction",
"_read_instruction",
"_write_parameter_expression",
"_write_parameter_expression",
"_read_parameter_expression_v3",
}
mtreinish marked this conversation as resolved.
Show resolved Hide resolved


def __getattr__(name):
if name in deprecated_names:
warnings.warn(
"The qiskit.circuit.qpy_serialization module is deprecated and has been supersceded "
Copy link
Contributor

Choose a reason for hiding this comment

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

😉

Suggested change
"The qiskit.circuit.qpy_serialization module is deprecated and has been supersceded "
"The qiskit.circuit.qpy_serialization module is deprecated and has been superseded "

f"by the qiskit.qpy module. The {name} function should be accessed from the qiskit.qpy "
"module instead.",
DeprecationWarning,
stacklevel=2,
)
return getattr(qpy, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
2 changes: 1 addition & 1 deletion qiskit/providers/basicaer/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def run(self, qobj, **backend_options):
else:
warnings.warn(
"Using a qobj for run() is deprecated and will be removed in a future release.",
PendingDeprecationWarning,
DeprecationWarning,
stacklevel=2,
)
qobj_options = qobj.config
Expand Down
5 changes: 5 additions & 0 deletions qiskit/providers/basicaer/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ def run(self, qobj, **backend_options):
qobj = assemble(qobj, self, **out_options)
qobj_options = qobj.config
else:
warnings.warn(
"Using a qobj for run() is deprecated and will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)
qobj_options = None
self._set_options(qobj_config=qobj_options, backend_options=backend_options)
job_id = str(uuid.uuid4())
Expand Down
5 changes: 2 additions & 3 deletions qiskit/transpiler/passes/scheduling/alap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def __init__(self, *args, **kwargs):
warnings.warn(
"The ALAPSchedule class has been supersceded by the ALAPScheduleAnalysis class "
"which performs the as analysis pass that requires a padding pass to later modify "
"the circuit. This class will be deprecated in a future release and subsequently "
"removed after that.",
PendingDeprecationWarning,
"the circuit. This class is deprecated and will be removed in a future release",
DeprecationWarning,
)

def run(self, dag):
Expand Down
5 changes: 2 additions & 3 deletions qiskit/transpiler/passes/scheduling/asap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def __init__(self, *args, **kwargs):
warnings.warn(
"The ASAPSchedule class has been supersceded by the ASAPScheduleAnalysis class "
"which performs the as analysis pass that requires a padding pass to later modify "
"the circuit. This class will be deprecated in a future release and subsequently "
"removed after that.",
PendingDeprecationWarning,
"the circuit. This class is deprecated and will be removed in a future release",
DeprecationWarning,
)

def run(self, dag):
Expand Down
5 changes: 2 additions & 3 deletions qiskit/transpiler/passes/scheduling/dynamical_decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ def __init__(self, durations, dd_sequence, qubits=None, spacing=None, skip_reset
"The DynamicalDecoupling class has been supersceded by the "
"DynamicalDecouplingPadding class which performs the same function but "
"requires scheduling and alignment analysis passes to run prior to it. "
"This class will be deprecated in a future release and subsequently "
"removed after that.",
PendingDeprecationWarning,
"This class is deprecated and will be removed in a future release",
Copy link
Member

Choose a reason for hiding this comment

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

Can i request that we postpone this deprecation until a future release while we build more confidence that the PadDynamicalDecoupling is the way to go (for other kinds of DD)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'll remove the deprecation of this and the matching scheduling passes and we can revisit for 0.22

Copy link
Contributor

Choose a reason for hiding this comment

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

@ajavadia is this ready to be deprecated or do we want to keep it still? 🙂

DeprecationWarning,
)
super().__init__()
self._durations = durations
Expand Down
35 changes: 35 additions & 0 deletions releasenotes/notes/deprecate-pendings-eeedde71d76a8cbd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
deprecations:
- |
The ``qiskit.circuit.qpy_serialization`` module has been deprecated and
will be removed in a future release. It has been replaced by the
:mod:`qiskit.qpy` module. This was done as ``qpy`` is no longer isolated to
just serializing :class:`~.QuantumCircuit` objects. You can just update
imports from ``qiskit.circuit.qpy_serialization`` to :mod:`qiskit.qpy` and
everything should behave as before.
- |
Support for passing a :class:`~.QasmQobj` object as the input to the
:meth:`~.QasmSimulatorPy.run` methods of the BasicAer simulator
backends classes: :class:`~.QasmSimulatorPy`,
:class:`~.StatevectorSimulatorPy`, and :class:`~.UnitarySimulatorPy` has
been deprecated and will be removed in a future release. Instead you should
directly pass the :class:`~QuantumCircuit` objects and run time options
to the :meth:`~.QasmSimulatorPy.run` method directly and using
:func:`~.assemble` to build a :class:`~.QasmQobj` prior to calling
:meth:`~.QasmSimulatorPy.run` is no longer necessary.
- |
The :class:`~.DynamicalDecoupling` transpiler pass has been deprecated and
will be removed in a future release. Instead the
:class:`~.PadDynamicalDecoupling` pass should be used in conjunction with
a scheduling analysis pass such as :class:`~.ALAPScheduleAnalysis` or
:class:`~.ASAPScheduleAnalysis`.
- |
The :class:`~.ASAPSchedule` pass has been deprecated and will be removed
in a future release. Instead the :class:`~.ASAPScheduleAnalysis` pass should
be used in conjunction with a padding pass such as :class:`~PadDelay` or
:class:`~.PadDynamicalDecoupling`.
- |
The :class:`~.ALAPSchedule` pass has been deprecated and will be removed
in a future release. Instead the :class:`~.ALAPScheduleAnalysis` pass should
be used in conjunction with a padding pass such as :class:`~PadDelay` or
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
be used in conjunction with a padding pass such as :class:`~PadDelay` or
be used in conjunction with a padding pass such as :class:`~.PadDelay` or

:class:`~.PadDynamicalDecoupling`.
4 changes: 2 additions & 2 deletions test/python/basicaer/test_basicaer_qobj_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_qobj_headers_in_result(self):
qobj.header = QobjHeader.from_dict(custom_qobj_header)
# Update the Qobj.experiment header.
qobj.experiments[0].header.some_field = "extra info"

result = backend.run(qobj).result()
with self.assertWarns(DeprecationWarning):
result = backend.run(qobj).result()
self.assertEqual(result.header.to_dict(), custom_qobj_header)
self.assertEqual(result.results[0].header.some_field, "extra info")
15 changes: 8 additions & 7 deletions test/python/basicaer/test_qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from qiskit import execute
from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister
from qiskit.compiler import transpile, assemble
from qiskit.compiler import transpile
from qiskit.providers.basicaer import QasmSimulatorPy
from qiskit.test import providers

Expand All @@ -47,8 +47,7 @@ def setUp(self):
qasm_filename = os.path.join(qasm_dir, "example.qasm")
transpiled_circuit = QuantumCircuit.from_qasm_file(qasm_filename)
transpiled_circuit.name = "test"
transpiled_circuit = transpile(transpiled_circuit, backend=self.backend)
self.qobj = assemble(transpiled_circuit, shots=1000, seed_simulator=self.seed)
self.transpiled_circuit = transpile(transpiled_circuit, backend=self.backend)
logger = getLogger()
self.addCleanup(logger.setLevel, logger.level)
logger.setLevel("DEBUG")
Expand All @@ -74,9 +73,9 @@ def test_submission_log_time(self):

def test_qasm_simulator_single_shot(self):
"""Test single shot run."""
shots = 1
self.qobj.config.shots = shots
result = self.backend.run(self.qobj).result()
result = self.backend.run(
self.transpiled_circuit, shots=1, seed_simulator=self.seed
).result()
self.assertEqual(result.success, True)

def test_measure_sampler_repeated_qubits(self):
Expand Down Expand Up @@ -152,7 +151,9 @@ def test_measure_sampler_partial_qubit(self):

def test_qasm_simulator(self):
"""Test data counts output for single circuit run against reference."""
result = self.backend.run(self.qobj).result()
result = self.backend.run(
self.transpiled_circuit, shots=1000, seed_simulator=self.seed
).result()
shots = 1024
threshold = 0.04 * shots
counts = result.get_counts("test")
Expand Down
15 changes: 10 additions & 5 deletions test/python/compiler/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ def test_example_multiple_compile(self):
ghz_backend = transpile(ghz, backend=backend, coupling_map=coupling_map)
bell_qobj = assemble(bell_backend, shots=shots, seed_simulator=10)
ghz_qobj = assemble(ghz_backend, shots=shots, seed_simulator=10)
bell_result = backend.run(bell_qobj).result()
ghz_result = backend.run(ghz_qobj).result()
with self.assertWarns(DeprecationWarning):
bell_result = backend.run(bell_qobj).result()
with self.assertWarns(DeprecationWarning):
ghz_result = backend.run(ghz_qobj).result()

threshold = 0.05 * shots
counts_bell = bell_result.get_counts()
Expand Down Expand Up @@ -101,7 +103,8 @@ def test_compile_coupling_map(self):
qc, backend=backend, coupling_map=coupling_map, initial_layout=initial_layout
)
qobj = assemble(qc_b, shots=shots, seed_simulator=88)
job = backend.run(qobj)
with self.assertWarns(DeprecationWarning):
job = backend.run(qobj)
result = job.result()
qasm_to_check = qc.qasm()
self.assertEqual(len(qasm_to_check), 173)
Expand Down Expand Up @@ -261,9 +264,11 @@ def test_compile_pass_manager(self):
qc.measure(qr, cr)
backend = BasicAer.get_backend("qasm_simulator")
qrtrue = assemble(transpile(qc, backend, seed_transpiler=8), seed_simulator=42)
rtrue = backend.run(qrtrue).result()
with self.assertWarns(DeprecationWarning):
rtrue = backend.run(qrtrue).result()
qrfalse = assemble(PassManager().run(qc), seed_simulator=42)
rfalse = backend.run(qrfalse).result()
with self.assertWarns(DeprecationWarning):
rfalse = backend.run(qrfalse).result()
self.assertEqual(rtrue.get_counts(), rfalse.get_counts())

def test_mapper_overoptimization(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ def setUp(self):
self.time_conversion_pass = TimeUnitConversion(inst_durations=instruction_durations)
# reproduce old behavior of 0.20.0 before #7655
# currently default write latency is 0
self.scheduling_pass = ALAPSchedule(
durations=instruction_durations,
clbit_write_latency=1600,
conditional_latency=0,
)
with self.assertWarns(DeprecationWarning):
self.scheduling_pass = ALAPSchedule(
durations=instruction_durations,
clbit_write_latency=1600,
conditional_latency=0,
)
self.align_measure_pass = AlignMeasures(alignment=16)

def test_t1_experiment_type(self):
Expand Down
Loading