From b7c99223239269ba0b7baac5fd0dc3b427a11eae Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Wed, 29 Mar 2023 09:12:15 -0600 Subject: [PATCH 1/4] Apply new deprecation decorators to assembler, compiler, and dagcircuit folders --- qiskit/assembler/run_config.py | 18 ++++++++++-------- qiskit/compiler/assembler.py | 16 +++++++++------- qiskit/dagcircuit/dagcircuit.py | 10 +++++----- qiskit/dagcircuit/dagnode.py | 31 +++++++++++++++++++++---------- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/qiskit/assembler/run_config.py b/qiskit/assembler/run_config.py index 78da74f4b08e..cc02b9820eb2 100644 --- a/qiskit/assembler/run_config.py +++ b/qiskit/assembler/run_config.py @@ -13,7 +13,8 @@ """Models for RunConfig and its related components.""" from types import SimpleNamespace -import warnings + +from qiskit.utils.deprecation import deprecate_arg class RunConfig(SimpleNamespace): @@ -30,6 +31,14 @@ class RunConfig(SimpleNamespace): parameter_binds (list[dict]): List of parameter bindings """ + @deprecate_arg( + "max_credits", + since="0.20.0", + additional_msg=( + "This argument has no effect on modern IBM Quantum systems, and no alternative is" + "necessary." + ), + ) def __init__( self, shots=None, @@ -55,13 +64,6 @@ def __init__( self.shots = shots if max_credits is not None: self.max_credits = max_credits - warnings.warn( - "The `max_credits` parameter is deprecated as of Qiskit Terra 0.20.0, " - "and will be removed in a future release. This parameter has no effect on " - "modern IBM Quantum systems, and no alternative is necessary.", - DeprecationWarning, - stacklevel=2, - ) if seed_simulator is not None: self.seed_simulator = seed_simulator if memory is not None: diff --git a/qiskit/compiler/assembler.py b/qiskit/compiler/assembler.py index 640d23076b0e..243d8b8102c0 100644 --- a/qiskit/compiler/assembler.py +++ b/qiskit/compiler/assembler.py @@ -29,6 +29,7 @@ from qiskit.pulse.channels import PulseChannel from qiskit.qobj import Qobj, QobjHeader from qiskit.qobj.utils import MeasLevel, MeasReturnType +from qiskit.utils.deprecation import deprecate_arg logger = logging.getLogger(__name__) @@ -39,6 +40,14 @@ def _log_assembly_time(start_time, end_time): # TODO: parallelize over the experiments (serialize each separately, then add global header/config) +@deprecate_arg( + "max_credits", + since="0.20.0", + additional_msg=( + "This argument has no effect on modern IBM Quantum systems, and no alternative is" + "necessary." + ), +) def assemble( experiments: Union[ QuantumCircuit, @@ -159,13 +168,6 @@ def assemble( """ if max_credits is not None: max_credits = None - warnings.warn( - "The `max_credits` parameter is deprecated as of Qiskit Terra 0.20.0, " - "and will be removed in a future release. This parameter has no effect on " - "modern IBM Quantum systems, and no alternative is necessary.", - DeprecationWarning, - stacklevel=2, - ) start_time = time() experiments = experiments if isinstance(experiments, list) else [experiments] pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments) diff --git a/qiskit/dagcircuit/dagcircuit.py b/qiskit/dagcircuit/dagcircuit.py index ed3dfc1fd618..f0002a063260 100644 --- a/qiskit/dagcircuit/dagcircuit.py +++ b/qiskit/dagcircuit/dagcircuit.py @@ -38,7 +38,7 @@ from qiskit.circuit.parameterexpression import ParameterExpression from qiskit.dagcircuit.exceptions import DAGCircuitError from qiskit.dagcircuit.dagnode import DAGNode, DAGOpNode, DAGInNode, DAGOutNode -from qiskit.utils.deprecation import deprecate_function +from qiskit.utils.deprecation import deprecate_func class DAGCircuit: @@ -526,10 +526,10 @@ def _add_op_node(self, op, qargs, cargs): self._increment_op(op) return node_index - @deprecate_function( - "The DAGCircuit._copy_circuit_metadata method is deprecated as of 0.20.0. It will be " - "removed no earlier than 3 months after the release date. You should use the " - "DAGCircuit.copy_empty_like method instead, which acts identically.", + @deprecate_func( + additional_msg=( + "Instead, use the method ``DAGCircuit.copy_empty_like()``, which acts identically." + ), since="0.20.0", ) def _copy_circuit_metadata(self): diff --git a/qiskit/dagcircuit/dagnode.py b/qiskit/dagcircuit/dagnode.py index 022c57fa4aff..aa0198883a04 100644 --- a/qiskit/dagcircuit/dagnode.py +++ b/qiskit/dagcircuit/dagnode.py @@ -13,10 +13,10 @@ """Objects to represent the information at a node in the DAGCircuit.""" -import warnings from typing import Iterable from qiskit.circuit import Qubit, Clbit +from qiskit.utils.deprecation import deprecate_arg def _condition_as_indices(operation, bit_indices): @@ -49,6 +49,26 @@ def __str__(self): return str(id(self)) @staticmethod + @deprecate_arg( + "bit_indices1", + deprecation_description="Not setting bit_indices1 in DAGNode.semantic_eq()", + additional_msg=( + "To ease the transition, bit_indices1 and bit_indices2 will for now be " + "pre-populated based on the values found in Bit.index and Bit.register." + ), + since="0.21.0", + predicate=lambda arg: arg is None, + ) + @deprecate_arg( + "bit_indices2", + deprecation_description="Not setting bit_indices2 in DAGNode.semantic_eq()", + additional_msg=( + "To ease the transition, bit_indices1 and bit_indices2 will for now be " + "pre-populated based on the values found in Bit.index and Bit.register." + ), + since="0.21.0", + predicate=lambda arg: arg is None, + ) def semantic_eq(node1, node2, bit_indices1=None, bit_indices2=None): """ Check if DAG nodes are considered equivalent, e.g., as a node_match for nx.is_isomorphic. @@ -65,15 +85,6 @@ def semantic_eq(node1, node2, bit_indices1=None, bit_indices2=None): Bool: If node1 == node2 """ if bit_indices1 is None or bit_indices2 is None: - warnings.warn( - "DAGNode.semantic_eq now expects two bit-to-circuit index " - "mappings as arguments. To ease the transition, these will be " - "pre-populated based on the values found in Bit.index and " - "Bit.register. However, this behavior is deprecated and a future " - "release will require the mappings to be provided as arguments.", - DeprecationWarning, - ) - bit_indices1 = {arg: arg for arg in node1.qargs + node1.cargs} bit_indices2 = {arg: arg for arg in node2.qargs + node2.cargs} From 9a1a7479b2874c5cb45d94ab9725c1e3c3b7b432 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Wed, 29 Mar 2023 14:20:11 -0600 Subject: [PATCH 2/4] Fix quantum_instance.py triggering deprecation for max_credits --- qiskit/utils/quantum_instance.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qiskit/utils/quantum_instance.py b/qiskit/utils/quantum_instance.py index 69423395681f..a293cbc4c0ae 100644 --- a/qiskit/utils/quantum_instance.py +++ b/qiskit/utils/quantum_instance.py @@ -274,7 +274,12 @@ def __init__( stacklevel=2, ) - run_config = RunConfig(shots=shots, max_credits=max_credits) + # Remove this warnings filter when removing the deprecated `max_credits` arg. We + # filter here so that we don't "double warn" if max_credits was set. + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + run_config = RunConfig(shots=shots, max_credits=max_credits) + if seed_simulator is not None: run_config.seed_simulator = seed_simulator From dcccd0508262691b18a3cb774df707e582073b71 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Tue, 2 May 2023 11:02:29 -0600 Subject: [PATCH 3/4] Review feedback --- qiskit/dagcircuit/dagcircuit.py | 2 +- qiskit/dagcircuit/dagnode.py | 30 +++++++++--------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/qiskit/dagcircuit/dagcircuit.py b/qiskit/dagcircuit/dagcircuit.py index 5c54054a7a9e..c4b3e7c0e04f 100644 --- a/qiskit/dagcircuit/dagcircuit.py +++ b/qiskit/dagcircuit/dagcircuit.py @@ -528,7 +528,7 @@ def _add_op_node(self, op, qargs, cargs): @deprecate_func( additional_msg=( - "Instead, use the method ``DAGCircuit.copy_empty_like()``, which acts identically." + "Instead, use :meth:`~copy_empty_like()`, which acts identically." ), since="0.20.0", ) diff --git a/qiskit/dagcircuit/dagnode.py b/qiskit/dagcircuit/dagnode.py index aa0198883a04..52b0e963c776 100644 --- a/qiskit/dagcircuit/dagnode.py +++ b/qiskit/dagcircuit/dagnode.py @@ -13,10 +13,10 @@ """Objects to represent the information at a node in the DAGCircuit.""" +import warnings from typing import Iterable from qiskit.circuit import Qubit, Clbit -from qiskit.utils.deprecation import deprecate_arg def _condition_as_indices(operation, bit_indices): @@ -49,26 +49,6 @@ def __str__(self): return str(id(self)) @staticmethod - @deprecate_arg( - "bit_indices1", - deprecation_description="Not setting bit_indices1 in DAGNode.semantic_eq()", - additional_msg=( - "To ease the transition, bit_indices1 and bit_indices2 will for now be " - "pre-populated based on the values found in Bit.index and Bit.register." - ), - since="0.21.0", - predicate=lambda arg: arg is None, - ) - @deprecate_arg( - "bit_indices2", - deprecation_description="Not setting bit_indices2 in DAGNode.semantic_eq()", - additional_msg=( - "To ease the transition, bit_indices1 and bit_indices2 will for now be " - "pre-populated based on the values found in Bit.index and Bit.register." - ), - since="0.21.0", - predicate=lambda arg: arg is None, - ) def semantic_eq(node1, node2, bit_indices1=None, bit_indices2=None): """ Check if DAG nodes are considered equivalent, e.g., as a node_match for nx.is_isomorphic. @@ -85,6 +65,14 @@ def semantic_eq(node1, node2, bit_indices1=None, bit_indices2=None): Bool: If node1 == node2 """ if bit_indices1 is None or bit_indices2 is None: + warnings.warn( + "DAGNode.semantic_eq now expects two bit-to-circuit index " + "mappings as arguments. To ease the transition, these will be " + "pre-populated based on the values found in Bit.index and " + "Bit.register. However, this behavior is deprecated and a future " + "release will require the mappings to be provided as arguments.", + DeprecationWarning, + ) bit_indices1 = {arg: arg for arg in node1.qargs + node1.cargs} bit_indices2 = {arg: arg for arg in node2.qargs + node2.cargs} From 1236e29b39f5f98ffa56fc4dcbe5ecb786dcfed7 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Tue, 2 May 2023 11:03:19 -0600 Subject: [PATCH 4/4] Fmt - oops --- qiskit/dagcircuit/dagcircuit.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qiskit/dagcircuit/dagcircuit.py b/qiskit/dagcircuit/dagcircuit.py index c4b3e7c0e04f..fbc60591d1f7 100644 --- a/qiskit/dagcircuit/dagcircuit.py +++ b/qiskit/dagcircuit/dagcircuit.py @@ -527,9 +527,7 @@ def _add_op_node(self, op, qargs, cargs): return node_index @deprecate_func( - additional_msg=( - "Instead, use :meth:`~copy_empty_like()`, which acts identically." - ), + additional_msg="Instead, use :meth:`~copy_empty_like()`, which acts identically.", since="0.20.0", ) def _copy_circuit_metadata(self):