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
24 changes: 24 additions & 0 deletions qiskit/circuit/qpy_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

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

import warnings

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

Expand All @@ -25,3 +27,25 @@
_read_parameter_expression,
_read_parameter_expression_v3,
)

deprecated_names = {
"dump",
"load",
"_write_instruction",
"_read_instruction",
"_write_parameter_expression",
"_write_parameter_expression",
}
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 globals()[name]
raise AttributeError(f"module {__name__} has no attribute {name}")
mtreinish marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion qiskit/transpiler/passes/scheduling/alap.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, *args, **kwargs):
"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,
DeprecationWarning,
mtreinish marked this conversation as resolved.
Show resolved Hide resolved
)

def run(self, dag):
Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/passes/scheduling/asap.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, *args, **kwargs):
"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,
DeprecationWarning,
)

def run(self, dag):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(self, durations, dd_sequence, qubits=None, spacing=None, skip_reset
"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,
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 by the
mtreinish marked this conversation as resolved.
Show resolved Hide resolved
: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
70 changes: 44 additions & 26 deletions test/python/transpiler/legacy_scheduling/test_scheduling_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def test_alap_agree_with_reverse_asap_reverse(self):
[("h", 0, 200), ("cx", [0, 1], 700), ("measure", None, 1000)]
)

pm = PassManager(ALAPSchedule(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(ALAPSchedule(durations))
alap_qc = pm.run(qc)

pm = PassManager(ASAPSchedule(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(ASAPSchedule(durations))
new_qc = pm.run(qc.reverse_ops())
new_qc = new_qc.reverse_ops()
new_qc.name = new_qc.name
Expand Down Expand Up @@ -78,7 +80,8 @@ def test_classically_controlled_gate_after_measure(self, schedule_pass):
qc.x(1).c_if(0, True)

durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)])
pm = PassManager(schedule_pass(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(schedule_pass(durations))
scheduled = pm.run(qc)

expected = QuantumCircuit(2, 1)
Expand Down Expand Up @@ -118,7 +121,8 @@ def test_measure_after_measure(self, schedule_pass):
qc.measure(1, 0)

durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)])
pm = PassManager(schedule_pass(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(schedule_pass(durations))
scheduled = pm.run(qc)

expected = QuantumCircuit(2, 1)
Expand Down Expand Up @@ -165,7 +169,8 @@ def test_c_if_on_different_qubits(self, schedule_pass):
qc.x(2).c_if(0, True)

durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)])
pm = PassManager(schedule_pass(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(schedule_pass(durations))
scheduled = pm.run(qc)

expected = QuantumCircuit(3, 1)
Expand Down Expand Up @@ -205,7 +210,8 @@ def test_shorter_measure_after_measure(self, schedule_pass):
qc.measure(1, 0)

durations = InstructionDurations([("measure", [0], 1000), ("measure", [1], 700)])
pm = PassManager(schedule_pass(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(schedule_pass(durations))
scheduled = pm.run(qc)

expected = QuantumCircuit(2, 1)
Expand Down Expand Up @@ -248,7 +254,8 @@ def test_measure_after_c_if(self, schedule_pass):
qc.measure(2, 0)

durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)])
pm = PassManager(schedule_pass(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(schedule_pass(durations))
scheduled = pm.run(qc)

expected = QuantumCircuit(3, 1)
Expand Down Expand Up @@ -302,7 +309,8 @@ def test_parallel_gate_different_length(self):
durations = InstructionDurations(
[("x", [0], 200), ("x", [1], 400), ("measure", None, 1000)]
)
pm = PassManager(ALAPSchedule(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(ALAPSchedule(durations))
qc_alap = pm.run(qc)

alap_expected = QuantumCircuit(2, 2)
Expand All @@ -314,7 +322,8 @@ def test_parallel_gate_different_length(self):

self.assertEqual(qc_alap, alap_expected)

pm = PassManager(ASAPSchedule(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(ASAPSchedule(durations))
qc_asap = pm.run(qc)

asap_expected = QuantumCircuit(2, 2)
Expand Down Expand Up @@ -366,7 +375,8 @@ def test_parallel_gate_different_length_with_barrier(self):
durations = InstructionDurations(
[("x", [0], 200), ("x", [1], 400), ("measure", None, 1000)]
)
pm = PassManager(ALAPSchedule(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(ALAPSchedule(durations))
qc_alap = pm.run(qc)

alap_expected = QuantumCircuit(2, 2)
Expand All @@ -379,7 +389,8 @@ def test_parallel_gate_different_length_with_barrier(self):

self.assertEqual(qc_alap, alap_expected)

pm = PassManager(ASAPSchedule(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(ASAPSchedule(durations))
qc_asap = pm.run(qc)

asap_expected = QuantumCircuit(2, 2)
Expand Down Expand Up @@ -441,8 +452,10 @@ def test_measure_after_c_if_on_edge_locking(self):
durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)])

# lock at the end edge
actual_asap = PassManager(ASAPSchedule(durations, clbit_write_latency=1000)).run(qc)
actual_alap = PassManager(ALAPSchedule(durations, clbit_write_latency=1000)).run(qc)
with self.assertWarns(DeprecationWarning):
actual_asap = PassManager(ASAPSchedule(durations, clbit_write_latency=1000)).run(qc)
with self.assertWarns(DeprecationWarning):
actual_alap = PassManager(ALAPSchedule(durations, clbit_write_latency=1000)).run(qc)

# start times of 2nd measure depends on ASAP/ALAP
expected_asap = QuantumCircuit(3, 1)
Expand Down Expand Up @@ -490,12 +503,14 @@ def test_active_reset_circuit(self, write_lat, cond_lat):
qc.x(0).c_if(0, 1)

durations = InstructionDurations([("x", None, 100), ("measure", None, 1000)])
actual_asap = PassManager(
ASAPSchedule(durations, clbit_write_latency=write_lat, conditional_latency=cond_lat)
).run(qc)
actual_alap = PassManager(
ALAPSchedule(durations, clbit_write_latency=write_lat, conditional_latency=cond_lat)
).run(qc)
with self.assertWarns(DeprecationWarning):
actual_asap = PassManager(
ASAPSchedule(durations, clbit_write_latency=write_lat, conditional_latency=cond_lat)
).run(qc)
with self.assertWarns(DeprecationWarning):
actual_alap = PassManager(
ALAPSchedule(durations, clbit_write_latency=write_lat, conditional_latency=cond_lat)
).run(qc)

expected = QuantumCircuit(1, 1)
expected.measure(0, 0)
Expand Down Expand Up @@ -613,12 +628,14 @@ def test_random_complicated_circuit(self):
[("x", None, 100), ("measure", None, 1000), ("cx", None, 200)]
)

actual_asap = PassManager(
ASAPSchedule(durations, clbit_write_latency=100, conditional_latency=200)
).run(qc)
actual_alap = PassManager(
ALAPSchedule(durations, clbit_write_latency=100, conditional_latency=200)
).run(qc)
with self.assertWarns(DeprecationWarning):
actual_asap = PassManager(
ASAPSchedule(durations, clbit_write_latency=100, conditional_latency=200)
).run(qc)
with self.assertWarns(DeprecationWarning):
actual_alap = PassManager(
ALAPSchedule(durations, clbit_write_latency=100, conditional_latency=200)
).run(qc)

expected_asap = QuantumCircuit(3, 1)
expected_asap.delay(100, 0)
Expand Down Expand Up @@ -707,7 +724,8 @@ def test_dag_introduces_extra_dependency_between_conditionals(self):
qc.x(1).c_if(0, True)

durations = InstructionDurations([("x", None, 160)])
pm = PassManager(ASAPSchedule(durations))
with self.assertWarns(DeprecationWarning):
pm = PassManager(ASAPSchedule(durations))
scheduled = pm.run(qc)

expected = QuantumCircuit(2, 1)
Expand Down
Loading