diff --git a/qiskit/circuit/barrier.py b/qiskit/circuit/barrier.py index c339066b4dce..d04769b68d39 100644 --- a/qiskit/circuit/barrier.py +++ b/qiskit/circuit/barrier.py @@ -19,6 +19,7 @@ from __future__ import annotations from qiskit.exceptions import QiskitError +from qiskit.utils import deprecate_func from .instruction import Instruction @@ -44,5 +45,6 @@ def inverse(self, annotated: bool = False): """Special case. Return self.""" return Barrier(self.num_qubits) + @deprecate_func(since="1.3.0", removal_timeline="in 2.0.0") def c_if(self, classical, val): raise QiskitError("Barriers are compiler directives and cannot be conditional.") diff --git a/qiskit/circuit/delay.py b/qiskit/circuit/delay.py index 25e7a6f3356c..157ae4c39069 100644 --- a/qiskit/circuit/delay.py +++ b/qiskit/circuit/delay.py @@ -19,6 +19,7 @@ from qiskit.circuit.gate import Gate from qiskit.circuit import _utils from qiskit.circuit.parameterexpression import ParameterExpression +from qiskit.utils import deprecate_func @_utils.with_gate_array(np.eye(2, dtype=complex)) @@ -42,6 +43,7 @@ def inverse(self, annotated: bool = False): """Special case. Return self.""" return self + @deprecate_func(since="1.3.0", removal_timeline="in 2.0.0") def c_if(self, classical, val): raise CircuitError("Conditional Delay is not yet implemented.") diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py index 557d7df21ee1..100a1f31a0a9 100644 --- a/qiskit/circuit/instruction.py +++ b/qiskit/circuit/instruction.py @@ -160,6 +160,7 @@ def to_mutable(self): return self.copy() @property + @deprecate_func(since="1.3.0", removal_timeline="in 2.0.0", is_property=True, stacklevel=2) def condition(self): """The classical condition on the instruction.""" return self._condition @@ -499,6 +500,7 @@ def inverse(self, annotated: bool = False): inverse_gate.definition = inverse_definition return inverse_gate + @deprecate_func(since="1.3.0", removal_timeline="in 2.0.0") def c_if(self, classical, val): """Set a classical equality condition on this instruction between the register or cbit ``classical`` and value ``val``. diff --git a/qiskit/circuit/instructionset.py b/qiskit/circuit/instructionset.py index cc8a050fd2b0..a3f06a90040c 100644 --- a/qiskit/circuit/instructionset.py +++ b/qiskit/circuit/instructionset.py @@ -20,6 +20,7 @@ from typing import Callable from qiskit.circuit.exceptions import CircuitError +from qiskit.utils import deprecate_func from .classicalregister import Clbit, ClassicalRegister from .operation import Operation from .quantumcircuitdata import CircuitInstruction @@ -105,6 +106,7 @@ def inverse(self, annotated: bool = False): ) return self + @deprecate_func(since="1.3.0", removal_timeline="in 2.0.0") def c_if(self, classical: Clbit | ClassicalRegister | int, val: int) -> "InstructionSet": """Set a classical equality condition on all the instructions in this set between the :obj:`.ClassicalRegister` or :obj:`.Clbit` ``classical`` and value ``val``. diff --git a/qiskit/circuit/singleton.py b/qiskit/circuit/singleton.py index 874b979ff588..a315f8aaa619 100644 --- a/qiskit/circuit/singleton.py +++ b/qiskit/circuit/singleton.py @@ -251,6 +251,7 @@ class XGate(Gate, metaclass=_SingletonMeta, overrides=_SingletonGateOverrides): import functools +from qiskit.utils import deprecate_func from .instruction import Instruction from .gate import Gate from .controlledgate import ControlledGate, _ctrl_state_to_int @@ -489,6 +490,7 @@ class they are providing overrides for has more lazy attributes or user-exposed instruction._params = _frozenlist(instruction._params) return instruction + @deprecate_func(since="1.3.0", removal_timeline="in 2.0.0") def c_if(self, classical, val): return self.to_mutable().c_if(classical, val) diff --git a/qiskit/circuit/store.py b/qiskit/circuit/store.py index 6bbc5439332d..43e81ce61056 100644 --- a/qiskit/circuit/store.py +++ b/qiskit/circuit/store.py @@ -16,6 +16,7 @@ import typing +from qiskit.utils import deprecate_func from .exceptions import CircuitError from .classical import expr, types from .instruction import Instruction @@ -88,6 +89,7 @@ def rvalue(self): """Get the r-value :class:`~.expr.Expr` node that is being written into the l-value.""" return self.params[1] + @deprecate_func(since="1.3.0", removal_timeline="in 2.0.0") def c_if(self, classical, val): """:meta hidden:""" raise NotImplementedError( diff --git a/qiskit/qasm2/parse.py b/qiskit/qasm2/parse.py index 6cdb0f70bba0..746866a52f8b 100644 --- a/qiskit/qasm2/parse.py +++ b/qiskit/qasm2/parse.py @@ -11,7 +11,7 @@ # that they have been altered from the originals. """Python-space bytecode interpreter for the output of the main Rust parser logic.""" - +import warnings import dataclasses import math from typing import Iterable, Callable @@ -255,6 +255,11 @@ def from_bytecode(bytecode, custom_instructions: Iterable[CustomInstruction]): CircuitInstruction(gates[gate_id](*parameters), [qubits[q] for q in op_qubits]) ) elif opcode == OpCode.ConditionedGate: + warnings.warn( + "Conditioned gates in qasm2 will be loaded as an IfElseOp starting in Qiskit 2.0", + FutureWarning, + stacklevel=3, + ) gate_id, parameters, op_qubits, creg, value = op.operands gate = gates[gate_id](*parameters).c_if(qc.cregs[creg], value) qc._append(CircuitInstruction(gate, [qubits[q] for q in op_qubits])) @@ -262,12 +267,22 @@ def from_bytecode(bytecode, custom_instructions: Iterable[CustomInstruction]): qubit, clbit = op.operands qc._append(CircuitInstruction(Measure(), (qubits[qubit],), (clbits[clbit],))) elif opcode == OpCode.ConditionedMeasure: + warnings.warn( + "Conditioned measurements in qasm2 will be loaded as an IfElseOp starting in Qiskit 2.0", + FutureWarning, + stacklevel=3, + ) qubit, clbit, creg, value = op.operands measure = Measure().c_if(qc.cregs[creg], value) qc._append(CircuitInstruction(measure, (qubits[qubit],), (clbits[clbit],))) elif opcode == OpCode.Reset: qc._append(CircuitInstruction(Reset(), (qubits[op.operands[0]],))) elif opcode == OpCode.ConditionedReset: + warnings.warn( + "Conditioned resets in qasm2 will be loaded as an IfElseOp starting in Qiskit 2.0", + FutureWarning, + stacklevel=3, + ) qubit, creg, value = op.operands reset = Reset().c_if(qc.cregs[creg], value) qc._append(CircuitInstruction(reset, (qubits[qubit],))) diff --git a/qiskit/qpy/binary_io/circuits.py b/qiskit/qpy/binary_io/circuits.py index 142639a4e164..a9aa46f7dce2 100644 --- a/qiskit/qpy/binary_io/circuits.py +++ b/qiskit/qpy/binary_io/circuits.py @@ -318,6 +318,13 @@ def _read_instruction( use_symengine, standalone_vars, ) + if condition is not None: + warnings.warn( + f"The .condition attribute on {gate_name} will be loaded as an IfElseOp " + "starting in Qiskit 2.0", + FutureWarning, + stacklevel=3, + ) inst_obj.condition = condition if instruction.label_size > 0: inst_obj.label = label @@ -414,6 +421,12 @@ def _read_instruction( gate = gate_class(*params) if condition: if not isinstance(gate, ControlFlowOp): + warnings.warn( + f"The .condition attribute on {gate} will be loaded as an " + "IfElseOp starting in Qiskit 2.0", + FutureWarning, + stacklevel=3, + ) gate = gate.c_if(*condition) else: gate.condition = condition diff --git a/qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py b/qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py index a73f9690ae0e..52f56aebbace 100644 --- a/qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py +++ b/qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py @@ -22,6 +22,7 @@ ) from qiskit.dagcircuit import DAGCircuit from qiskit.transpiler.basepasses import TransformationPass +from qiskit.utils import deprecate_func class ConvertConditionsToIfOps(TransformationPass): @@ -31,6 +32,10 @@ class ConvertConditionsToIfOps(TransformationPass): This is a simple pass aimed at easing the conversion from the old style of using :meth:`.InstructionSet.c_if` into the new style of using more complex conditional logic.""" + @deprecate_func(since="1.3.0", removal_timeline="in Qiskit 2.0.0") + def __init__(self): + super().__init__() + def _run_inner(self, dag): """Run the pass on one :class:`.DAGCircuit`, mutating it. Returns ``True`` if the circuit was modified and ``False`` if not.""" diff --git a/releasenotes/notes/deprecate-condition_c_if-9548e5522814fe9c.yaml b/releasenotes/notes/deprecate-condition_c_if-9548e5522814fe9c.yaml new file mode 100644 index 000000000000..20c5ec38a022 --- /dev/null +++ b/releasenotes/notes/deprecate-condition_c_if-9548e5522814fe9c.yaml @@ -0,0 +1,38 @@ +--- +deprecations_circuits: + - | + Deprecated the :attr:`.Instruction.condition` and the + :meth:`.Instruction.c_if` method. This attribute and method will be removed + in Qiskit 2.0 and along with any other uses of this in the Qiskit data + model. This functionality has been superseded by the :class:`.IfElseOp` + which can be used to describe a classically condition in a circuit. For + example, a circuit using :attr:`.Instruction.condition` like:: + + from qiskit.circuit import QuantumCircuit + + qc = QuantumCircuit(2, 2) + qc.h(0) + qc.x(0).c_if(0, 1) + qc.z(1.c_if(1, 0) + qc.measure(0, 0) + qc.measure(1, 1) + + can be rewritten using as:: + + qc = QuantumCircuit(2, 2) + qc.h(0) + with expected.if_test((expected.clbits[0], True)): + qc.x(0) + with expected.if_test((expected.clbits[1], False)): + qc.z(1) + qc.measure(0, 0) + qc.measure(1, 1) + + The now deprecated :class:`.ConvertConditionsToIfOps` transpiler pass can + be used to automate this conversion for existing circuits. +deprecations_transpiler: + - | + The transpiler pass :class:`.ConvertConditionsToIfOps` has been deprecated + and will be removed in Qiskit 2.0.0. This class is now deprecated because + the underlying data model for :attr:`.Instruction.condition` which this + pass is converting from has been deprecated and will be removed in 2.0.0. diff --git a/test/python/circuit/classical/test_expr_constructors.py b/test/python/circuit/classical/test_expr_constructors.py index 012697a17dd0..2be64fbef9f3 100644 --- a/test/python/circuit/classical/test_expr_constructors.py +++ b/test/python/circuit/classical/test_expr_constructors.py @@ -26,7 +26,8 @@ def test_lift_legacy_condition(self): clbit = Clbit() inst = Instruction("custom", 1, 0, []) - inst.c_if(cr, 7) + with self.assertWarns(DeprecationWarning): + inst.c_if(cr, 7) self.assertEqual( expr.lift_legacy_condition(inst.condition), expr.Binary( @@ -38,7 +39,8 @@ def test_lift_legacy_condition(self): ) inst = Instruction("custom", 1, 0, []) - inst.c_if(cr, 255) + with self.assertWarns(DeprecationWarning): + inst.c_if(cr, 255) self.assertEqual( expr.lift_legacy_condition(inst.condition), expr.Binary( @@ -50,7 +52,8 @@ def test_lift_legacy_condition(self): ) inst = Instruction("custom", 1, 0, []) - inst.c_if(clbit, False) + with self.assertWarns(DeprecationWarning): + inst.c_if(clbit, False) self.assertEqual( expr.lift_legacy_condition(inst.condition), expr.Unary( @@ -61,7 +64,8 @@ def test_lift_legacy_condition(self): ) inst = Instruction("custom", 1, 0, []) - inst.c_if(clbit, True) + with self.assertWarns(DeprecationWarning): + inst.c_if(clbit, True) self.assertEqual( expr.lift_legacy_condition(inst.condition), expr.Var(clbit, types.Bool()), diff --git a/test/python/circuit/library/test_permutation.py b/test/python/circuit/library/test_permutation.py index a2ec59431fe3..34ae89ce4aa4 100644 --- a/test/python/circuit/library/test_permutation.py +++ b/test/python/circuit/library/test_permutation.py @@ -149,7 +149,8 @@ def test_reverse_ops(self): def test_conditional(self): """Test adding conditional permutations.""" qc = QuantumCircuit(5, 1) - qc.append(PermutationGate([1, 2, 0]), [2, 3, 4]).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.append(PermutationGate([1, 2, 0]), [2, 3, 4]).c_if(0, 1) self.assertIsNotNone(qc.data[0].operation.condition) def test_qasm(self): diff --git a/test/python/circuit/library/test_qft.py b/test/python/circuit/library/test_qft.py index 85837f0ac80c..77510f3cfb9c 100644 --- a/test/python/circuit/library/test_qft.py +++ b/test/python/circuit/library/test_qft.py @@ -272,7 +272,8 @@ def test_reverse_ops(self): def test_conditional(self): """Test adding conditional to a QFTGate.""" qc = QuantumCircuit(5, 1) - qc.append(QFTGate(4), [1, 2, 0, 4]).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.append(QFTGate(4), [1, 2, 0, 4]).c_if(0, 1) self.assertIsNotNone(qc.data[0].operation.condition) def test_qasm(self): diff --git a/test/python/circuit/test_circuit_load_from_qpy.py b/test/python/circuit/test_circuit_load_from_qpy.py index db8663ace558..65d441417d76 100644 --- a/test/python/circuit/test_circuit_load_from_qpy.py +++ b/test/python/circuit/test_circuit_load_from_qpy.py @@ -138,11 +138,13 @@ def test_qpy_full_path(self): def test_circuit_with_conditional(self): """Test that instructions with conditions are correctly serialized.""" qc = QuantumCircuit(1, 1) - qc.x(0).c_if(qc.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(qc.cregs[0], 1) qpy_file = io.BytesIO() dump(qc, qpy_file) qpy_file.seek(0) - new_circ = load(qpy_file)[0] + with self.assertWarns(DeprecationWarning): + new_circ = load(qpy_file)[0] self.assertEqual(qc, new_circ) self.assertDeprecatedBitProperties(qc, new_circ) @@ -408,13 +410,15 @@ def test_multiple_circuits(self): """Test multiple circuits can be serialized together.""" circuits = [] for i in range(10): - circuits.append( - random_circuit(10, 10, measure=True, conditional=True, reset=True, seed=42 + i) - ) + with self.assertWarns(DeprecationWarning): + circuits.append( + random_circuit(10, 10, measure=True, conditional=True, reset=True, seed=42 + i) + ) qpy_file = io.BytesIO() dump(circuits, qpy_file) qpy_file.seek(0) - new_circs = load(qpy_file) + with self.assertWarns(DeprecationWarning): + new_circs = load(qpy_file) self.assertEqual(circuits, new_circs) for old, new in zip(circuits, new_circs): self.assertDeprecatedBitProperties(old, new) @@ -674,12 +678,14 @@ def test_circuit_with_conditional_with_label(self): """Test that instructions with conditions are correctly serialized.""" qc = QuantumCircuit(1, 1) gate = XGate(label="My conditional x gate") - gate.c_if(qc.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + gate.c_if(qc.cregs[0], 1) qc.append(gate, [0]) qpy_file = io.BytesIO() dump(qc, qpy_file) qpy_file.seek(0) - new_circ = load(qpy_file)[0] + with self.assertWarns(DeprecationWarning): + new_circ = load(qpy_file)[0] self.assertEqual(qc, new_circ) self.assertEqual( [x.operation.label for x in qc.data], [x.operation.label for x in new_circ.data] @@ -755,12 +761,14 @@ def test_single_bit_teleportation(self): qc = QuantumCircuit(qr, cr, name="Reset Test") qc.x(0) qc.measure(0, cr[0]) - qc.x(0).c_if(cr[0], 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(cr[0], 1) qc.measure(0, cr[1]) qpy_file = io.BytesIO() dump(qc, qpy_file) qpy_file.seek(0) - new_circ = load(qpy_file)[0] + with self.assertWarns(DeprecationWarning): + new_circ = load(qpy_file)[0] self.assertEqual(qc, new_circ) self.assertEqual( [x.operation.label for x in qc.data], [x.operation.label for x in new_circ.data] @@ -1138,11 +1146,13 @@ def test_qpy_with_for_loop(self): qc.h(0) qc.cx(0, 1) qc.measure(0, 0) - qc.break_loop().c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.break_loop().c_if(0, True) qpy_file = io.BytesIO() dump(qc, qpy_file) qpy_file.seek(0) - new_circuit = load(qpy_file)[0] + with self.assertWarns(DeprecationWarning): + new_circuit = load(qpy_file)[0] self.assertEqual(qc, new_circuit) self.assertDeprecatedBitProperties(qc, new_circuit) @@ -1154,11 +1164,13 @@ def test_qpy_with_for_loop_iterator(self): qc.h(0) qc.cx(0, 1) qc.measure(0, 0) - qc.break_loop().c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.break_loop().c_if(0, True) qpy_file = io.BytesIO() dump(qc, qpy_file) qpy_file.seek(0) - new_circuit = load(qpy_file)[0] + with self.assertWarns(DeprecationWarning): + new_circuit = load(qpy_file)[0] self.assertEqual(qc, new_circuit) self.assertDeprecatedBitProperties(qc, new_circuit) diff --git a/test/python/circuit/test_circuit_operations.py b/test/python/circuit/test_circuit_operations.py index f374f82504a6..7899f5877ff6 100644 --- a/test/python/circuit/test_circuit_operations.py +++ b/test/python/circuit/test_circuit_operations.py @@ -1035,18 +1035,21 @@ def test_repeat(self): qc.h(0) qc.cx(0, 1) qc.barrier() - qc.h(0).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.h(0).c_if(cr, 1) with self.subTest("repeat 0 times"): rep = qc.repeat(0) self.assertEqual(rep, QuantumCircuit(qr, cr)) with self.subTest("repeat 3 times"): - inst = qc.to_instruction() + with self.assertWarns(DeprecationWarning): + inst = qc.to_instruction() ref = QuantumCircuit(qr, cr) for _ in range(3): ref.append(inst, ref.qubits, ref.clbits) - rep = qc.repeat(3) + with self.assertWarns(DeprecationWarning): + rep = qc.repeat(3) self.assertEqual(rep, ref) @data(0, 1, 4) @@ -1292,13 +1295,15 @@ def test_reverse_bits_with_registerless_bits(self): qc = QuantumCircuit([q0, q1], [c0, c1]) qc.h(0) qc.cx(0, 1) - qc.x(0).c_if(1, True) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(1, True) qc.measure(0, 0) expected = QuantumCircuit([c1, c0], [q1, q0]) expected.h(1) expected.cx(1, 0) - expected.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, True) expected.measure(1, 1) self.assertEqual(qc.reverse_bits(), expected) @@ -1389,29 +1394,41 @@ def test_compare_circuits_with_single_bit_conditions(self): qreg = QuantumRegister(1, name="q") creg = ClassicalRegister(1, name="c") qc1 = QuantumCircuit(qreg, creg, [Clbit()]) - qc1.x(0).c_if(qc1.cregs[0], 1) - qc1.x(0).c_if(qc1.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.clbits[-1], True) qc2 = QuantumCircuit(qreg, creg, [Clbit()]) - qc2.x(0).c_if(qc2.cregs[0], 1) - qc2.x(0).c_if(qc2.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.clbits[-1], True) self.assertEqual(qc1, qc2) # Order of operations transposed. qc1 = QuantumCircuit(qreg, creg, [Clbit()]) - qc1.x(0).c_if(qc1.cregs[0], 1) - qc1.x(0).c_if(qc1.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.clbits[-1], True) qc2 = QuantumCircuit(qreg, creg, [Clbit()]) - qc2.x(0).c_if(qc2.clbits[-1], True) - qc2.x(0).c_if(qc2.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.cregs[0], 1) self.assertNotEqual(qc1, qc2) # Single-bit condition values not the same. qc1 = QuantumCircuit(qreg, creg, [Clbit()]) - qc1.x(0).c_if(qc1.cregs[0], 1) - qc1.x(0).c_if(qc1.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.clbits[-1], True) qc2 = QuantumCircuit(qreg, creg, [Clbit()]) - qc2.x(0).c_if(qc2.cregs[0], 1) - qc2.x(0).c_if(qc2.clbits[-1], False) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.clbits[-1], False) self.assertNotEqual(qc1, qc2) def test_compare_a_circuit_with_none(self): diff --git a/test/python/circuit/test_circuit_properties.py b/test/python/circuit/test_circuit_properties.py index d51dd0c75616..fa9e6e5b169d 100644 --- a/test/python/circuit/test_circuit_properties.py +++ b/test/python/circuit/test_circuit_properties.py @@ -226,8 +226,10 @@ def test_circuit_depth_conditionals1(self): qc.cx(q[2], q[3]) qc.measure(q[0], c[0]) qc.measure(q[1], c[1]) - qc.h(q[2]).c_if(c, 2) - qc.h(q[3]).c_if(c, 4) + with self.assertWarns(DeprecationWarning): + qc.h(q[2]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.h(q[3]).c_if(c, 4) self.assertEqual(qc.depth(), 5) def test_circuit_depth_conditionals2(self): @@ -258,8 +260,10 @@ def test_circuit_depth_conditionals2(self): qc.cx(q[2], q[3]) qc.measure(q[0], c[0]) qc.measure(q[0], c[0]) - qc.h(q[2]).c_if(c, 2) - qc.h(q[3]).c_if(c, 4) + with self.assertWarns(DeprecationWarning): + qc.h(q[2]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.h(q[3]).c_if(c, 4) self.assertEqual(qc.depth(), 6) def test_circuit_depth_conditionals3(self): @@ -287,7 +291,8 @@ def test_circuit_depth_conditionals3(self): qc.h(q[2]) qc.h(q[3]) qc.measure(q[0], c[0]) - qc.cx(q[0], q[3]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.cx(q[0], q[3]).c_if(c, 2) qc.measure(q[1], c[1]) qc.measure(q[2], c[2]) @@ -320,8 +325,10 @@ def test_circuit_depth_bit_conditionals1(self): qc.h(q[3]) qc.measure(q[0], c[0]) qc.measure(q[2], c[2]) - qc.h(q[1]).c_if(c[0], True) - qc.h(q[3]).c_if(c[2], False) + with self.assertWarns(DeprecationWarning): + qc.h(q[1]).c_if(c[0], True) + with self.assertWarns(DeprecationWarning): + qc.h(q[3]).c_if(c[2], False) self.assertEqual(qc.depth(), 3) def test_circuit_depth_bit_conditionals2(self): @@ -362,12 +369,18 @@ def test_circuit_depth_bit_conditionals2(self): qc.h(q[3]) qc.measure(q[0], c[0]) qc.measure(q[2], c[2]) - qc.h(q[1]).c_if(c[1], True) - qc.h(q[3]).c_if(c[3], True) - qc.cx(0, 1).c_if(c[0], False) - qc.cx(2, 3).c_if(c[2], False) - qc.ch(0, 2).c_if(c[1], True) - qc.ch(1, 3).c_if(c[3], True) + with self.assertWarns(DeprecationWarning): + qc.h(q[1]).c_if(c[1], True) + with self.assertWarns(DeprecationWarning): + qc.h(q[3]).c_if(c[3], True) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(c[0], False) + with self.assertWarns(DeprecationWarning): + qc.cx(2, 3).c_if(c[2], False) + with self.assertWarns(DeprecationWarning): + qc.ch(0, 2).c_if(c[1], True) + with self.assertWarns(DeprecationWarning): + qc.ch(1, 3).c_if(c[3], True) self.assertEqual(qc.depth(), 4) def test_circuit_depth_bit_conditionals3(self): @@ -395,9 +408,12 @@ def test_circuit_depth_bit_conditionals3(self): qc.h(q[2]) qc.h(q[3]) qc.measure(q[0], c[0]) - qc.h(1).c_if(c[0], True) - qc.h(q[2]).c_if(c, 2) - qc.h(3).c_if(c[3], True) + with self.assertWarns(DeprecationWarning): + qc.h(1).c_if(c[0], True) + with self.assertWarns(DeprecationWarning): + qc.h(q[2]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.h(3).c_if(c[3], True) qc.measure(q[1], c[1]) qc.measure(q[2], c[2]) qc.measure(q[3], c[3]) @@ -608,7 +624,8 @@ def test_circuit_depth_multiqubit_or_conditional(self): circ.rz(0.1, 1) circ.cz(1, 3) circ.measure(1, 0) - circ.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + circ.x(0).c_if(0, 1) self.assertEqual( circ.depth(lambda x: x.operation.num_qubits >= 2 or x.operation.condition is not None), 4, @@ -765,7 +782,8 @@ def test_circuit_nonlocal_gates(self): qc.cry(0.1, q[2], q[4]) qc.z(q[3:]) qc.cswap(q[1], q[2], q[3]) - qc.iswap(q[0], q[4]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.iswap(q[0], q[4]).c_if(c, 2) result = qc.num_nonlocal_gates() expected = 3 self.assertEqual(expected, result) @@ -921,7 +939,8 @@ def test_circuit_connected_components_with_cond(self): qc.h(q[2]) qc.h(q[3]) qc.measure(q[0], c[0]) - qc.cx(q[0], q[3]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.cx(q[0], q[3]).c_if(c, 2) qc.measure(q[1], c[1]) qc.measure(q[2], c[2]) qc.measure(q[3], c[3]) @@ -949,8 +968,10 @@ def test_circuit_connected_components_with_cond2(self): qc.h(q[1]) qc.h(q[2]) qc.h(q[3]) - qc.h(0).c_if(c, 0) - qc.cx(1, 2).c_if(c, 4) + with self.assertWarns(DeprecationWarning): + qc.h(0).c_if(c, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(1, 2).c_if(c, 4) self.assertEqual(qc.num_connected_components(), 2) def test_circuit_connected_components_with_cond3(self): @@ -977,10 +998,13 @@ def test_circuit_connected_components_with_cond3(self): qc.h(q[2]) qc.h(q[3]) qc.measure(q[0], c[0]) - qc.h(q[0]).c_if(c, 0) - qc.cx(q[1], q[2]).c_if(c, 1) + with self.assertWarns(DeprecationWarning): + qc.h(q[0]).c_if(c, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(q[1], q[2]).c_if(c, 1) qc.measure(q[2], c[2]) - qc.x(q[3]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.x(q[3]).c_if(c, 2) self.assertEqual(qc.num_connected_components(), 1) def test_circuit_connected_components_with_bit_cond(self): @@ -1007,7 +1031,8 @@ def test_circuit_connected_components_with_bit_cond(self): qc.h(q[2]) qc.h(q[3]) qc.measure(q[0], c[0]) - qc.cx(q[0], q[3]).c_if(c[0], True) + with self.assertWarns(DeprecationWarning): + qc.cx(q[0], q[3]).c_if(c[0], True) qc.measure(q[1], c[1]) qc.measure(q[2], c[2]) qc.measure(q[3], c[3]) @@ -1035,9 +1060,12 @@ def test_circuit_connected_components_with_bit_cond2(self): qc.h(q[1]) qc.h(q[2]) qc.h(q[3]) - qc.h(0).c_if(c[1], True) - qc.cx(1, 0).c_if(c[4], False) - qc.cz(2, 3).c_if(c[0], True) + with self.assertWarns(DeprecationWarning): + qc.h(0).c_if(c[1], True) + with self.assertWarns(DeprecationWarning): + qc.cx(1, 0).c_if(c[4], False) + with self.assertWarns(DeprecationWarning): + qc.cz(2, 3).c_if(c[0], True) self.assertEqual(qc.num_connected_components(), 5) def test_circuit_connected_components_with_bit_cond3(self): @@ -1063,9 +1091,12 @@ def test_circuit_connected_components_with_bit_cond3(self): qc.h(q[1]) qc.h(q[2]) qc.h(q[3]) - qc.h(q[0]).c_if(c[0], True) - qc.cx(q[1], q[2]).c_if(c, 1) - qc.x(q[3]).c_if(c[2], True) + with self.assertWarns(DeprecationWarning): + qc.h(q[0]).c_if(c[0], True) + with self.assertWarns(DeprecationWarning): + qc.cx(q[1], q[2]).c_if(c, 1) + with self.assertWarns(DeprecationWarning): + qc.x(q[3]).c_if(c[2], True) self.assertEqual(qc.num_connected_components(), 1) def test_circuit_unitary_factors1(self): @@ -1109,7 +1140,8 @@ def test_circuit_unitary_factors3(self): qc.h(q[3]) qc.cx(q[1], q[2]) qc.cx(q[1], q[2]) - qc.cx(q[0], q[3]).c_if(c, 2) + with self.assertWarns(DeprecationWarning): + qc.cx(q[0], q[3]).c_if(c, 2) qc.cx(q[0], q[3]) qc.cx(q[0], q[3]) qc.cx(q[0], q[3]) diff --git a/test/python/circuit/test_circuit_qasm.py b/test/python/circuit/test_circuit_qasm.py index 984851e00388..bbbb494877f6 100644 --- a/test/python/circuit/test_circuit_qasm.py +++ b/test/python/circuit/test_circuit_qasm.py @@ -44,9 +44,12 @@ def test_circuit_qasm(self): qc.barrier(qr2) qc.cx(qr2[1], qr1[0]) qc.h(qr2[1]) - qc.x(qr2[1]).c_if(cr, 0) - qc.y(qr1[0]).c_if(cr, 1) - qc.z(qr1[0]).c_if(cr, 2) + with self.assertWarns(DeprecationWarning): + qc.x(qr2[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.y(qr1[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.z(qr1[0]).c_if(cr, 2) qc.barrier(qr1, qr2) qc.measure(qr1[0], cr[0]) qc.measure(qr2[0], cr[1]) @@ -639,7 +642,8 @@ def test_circuit_raises_on_single_bit_condition(self): """OpenQASM 2 can't represent single-bit conditions, so test that a suitable error is printed if this is attempted.""" qc = QuantumCircuit(1, 1) - qc.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, True) with self.assertRaisesRegex(QasmError, "OpenQASM 2 can only condition on registers"): dumps(qc) diff --git a/test/python/circuit/test_commutation_checker.py b/test/python/circuit/test_commutation_checker.py index a0aeae5ca2c3..b7cd73e03300 100644 --- a/test/python/circuit/test_commutation_checker.py +++ b/test/python/circuit/test_commutation_checker.py @@ -252,26 +252,33 @@ def test_conditional_gates(self): # Currently, in all cases commutativity checker should returns False. # This is definitely suboptimal. - self.assertFalse( - scc.commute(CXGate().c_if(cr[0], 0), [qr[0], qr[1]], [], XGate(), [qr[2]], []) - ) - self.assertFalse( - scc.commute(CXGate().c_if(cr[0], 0), [qr[0], qr[1]], [], XGate(), [qr[1]], []) - ) - self.assertFalse( - scc.commute( - CXGate().c_if(cr[0], 0), - [qr[0], qr[1]], - [], - CXGate().c_if(cr[0], 0), - [qr[0], qr[1]], - [], + with self.assertWarns(DeprecationWarning): + self.assertFalse( + scc.commute(CXGate().c_if(cr[0], 0), [qr[0], qr[1]], [], XGate(), [qr[2]], []) ) - ) - self.assertFalse( - scc.commute(XGate().c_if(cr[0], 0), [qr[0]], [], XGate().c_if(cr[0], 1), [qr[0]], []) - ) - self.assertFalse(scc.commute(XGate().c_if(cr[0], 0), [qr[0]], [], XGate(), [qr[0]], [])) + with self.assertWarns(DeprecationWarning): + self.assertFalse( + scc.commute(CXGate().c_if(cr[0], 0), [qr[0], qr[1]], [], XGate(), [qr[1]], []) + ) + with self.assertWarns(DeprecationWarning): + self.assertFalse( + scc.commute( + CXGate().c_if(cr[0], 0), + [qr[0], qr[1]], + [], + CXGate().c_if(cr[0], 0), + [qr[0], qr[1]], + [], + ) + ) + with self.assertWarns(DeprecationWarning): + self.assertFalse( + scc.commute( + XGate().c_if(cr[0], 0), [qr[0]], [], XGate().c_if(cr[0], 1), [qr[0]], [] + ) + ) + with self.assertWarns(DeprecationWarning): + self.assertFalse(scc.commute(XGate().c_if(cr[0], 0), [qr[0]], [], XGate(), [qr[0]], [])) def test_complex_gates(self): """Check commutativity involving more complex gates.""" diff --git a/test/python/circuit/test_compose.py b/test/python/circuit/test_compose.py index 582bee082d99..cc4be3c3ffa2 100644 --- a/test/python/circuit/test_compose.py +++ b/test/python/circuit/test_compose.py @@ -367,7 +367,8 @@ def __init__(self): super().__init__("mygate", 1, []) conditional = QuantumCircuit(1, 1) - conditional.append(Custom(), [0], []).c_if(conditional.clbits[0], True) + with self.assertWarns(DeprecationWarning): + conditional.append(Custom(), [0], []).c_if(conditional.clbits[0], True) test = base.compose(conditional, qubits=[0], clbits=[0], copy=False) self.assertIs(test.data[-1].operation, conditional.data[-1].operation) self.assertEqual(test.data[-1].operation.condition, (test.clbits[0], True)) @@ -463,16 +464,20 @@ def test_compose_conditional(self): creg = ClassicalRegister(2, "rcr") circuit_right = QuantumCircuit(qreg, creg) - circuit_right.x(qreg[1]).c_if(creg, 3) - circuit_right.h(qreg[0]).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + circuit_right.x(qreg[1]).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + circuit_right.h(qreg[0]).c_if(creg, 3) circuit_right.measure(qreg, creg) # permuted subset of qubits and clbits circuit_composed = self.circuit_left.compose(circuit_right, qubits=[1, 4], clbits=[0, 1]) circuit_expected = self.circuit_left.copy() - circuit_expected.x(self.left_qubit4).c_if(*self.condition) - circuit_expected.h(self.left_qubit1).c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + circuit_expected.x(self.left_qubit4).c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + circuit_expected.h(self.left_qubit1).c_if(*self.condition) circuit_expected.measure(self.left_qubit1, self.left_clbit0) circuit_expected.measure(self.left_qubit4, self.left_clbit1) @@ -489,8 +494,10 @@ def test_compose_conditional_no_match(self): right.cx(0, 1) right.h(0) right.measure([0, 1], [0, 1]) - right.z(2).c_if(right.cregs[0], 1) - right.x(2).c_if(right.cregs[1], 1) + with self.assertWarns(DeprecationWarning): + right.z(2).c_if(right.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + right.x(2).c_if(right.cregs[1], 1) test = QuantumCircuit(3, 3).compose(right, range(3), range(2)) z = next(ins.operation for ins in test.data[::-1] if ins.operation.name == "z") x = next(ins.operation for ins in test.data[::-1] if ins.operation.name == "x") @@ -724,7 +731,8 @@ def test_single_bit_condition(self): """Test that compose can correctly handle circuits that contain conditions on single bits. This is a regression test of the bug that broke qiskit-experiments in gh-7653.""" base = QuantumCircuit(1, 1) - base.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + base.x(0).c_if(0, True) test = QuantumCircuit(1, 1).compose(base) self.assertIsNot(base.clbits[0], test.clbits[0]) self.assertEqual(base, test) diff --git a/test/python/circuit/test_control_flow.py b/test/python/circuit/test_control_flow.py index 35c57839d753..cdb87ac0d342 100644 --- a/test/python/circuit/test_control_flow.py +++ b/test/python/circuit/test_control_flow.py @@ -808,15 +808,20 @@ def test_no_c_if_for_while_loop_if_else(self): body = QuantumCircuit(1) with self.assertRaisesRegex(NotImplementedError, r"cannot be classically controlled"): - qc.while_loop((qc.clbits[0], False), body, [qc.qubits[0]], []).c_if(qc.clbits[0], True) + with self.assertWarns(DeprecationWarning): + qc.while_loop((qc.clbits[0], False), body, [qc.qubits[0]], []).c_if( + qc.clbits[0], True + ) with self.assertRaisesRegex(NotImplementedError, r"cannot be classically controlled"): - qc.if_test((qc.clbits[0], False), body, [qc.qubits[0]], []).c_if(qc.clbits[0], True) + with self.assertWarns(DeprecationWarning): + qc.if_test((qc.clbits[0], False), body, [qc.qubits[0]], []).c_if(qc.clbits[0], True) with self.assertRaisesRegex(NotImplementedError, r"cannot be classically controlled"): - qc.if_else((qc.clbits[0], False), body, body, [qc.qubits[0]], []).c_if( - qc.clbits[0], True - ) + with self.assertWarns(DeprecationWarning): + qc.if_else((qc.clbits[0], False), body, body, [qc.qubits[0]], []).c_if( + qc.clbits[0], True + ) def test_nested_parameters_are_recognised(self): """Verify that parameters added inside a control-flow operator get added to the outer diff --git a/test/python/circuit/test_control_flow_builders.py b/test/python/circuit/test_control_flow_builders.py index 7a3a0873ae77..419cfb406d19 100644 --- a/test/python/circuit/test_control_flow_builders.py +++ b/test/python/circuit/test_control_flow_builders.py @@ -193,12 +193,16 @@ def test_register_condition_in_nested_block(self): with self.subTest("if/c_if"): test = QuantumCircuit(qr, clbits, cr1, cr2, cr3, cr4) with test.if_test((cr1, 0)): - test.x(0).c_if(cr2, 0) - test.z(0).c_if(cr3, 0) + with self.assertWarns(DeprecationWarning): + test.x(0).c_if(cr2, 0) + with self.assertWarns(DeprecationWarning): + test.z(0).c_if(cr3, 0) true_body = QuantumCircuit([qr[0]], clbits, cr1, cr2, cr3) - true_body.x(0).c_if(cr2, 0) - true_body.z(0).c_if(cr3, 0) + with self.assertWarns(DeprecationWarning): + true_body.x(0).c_if(cr2, 0) + with self.assertWarns(DeprecationWarning): + true_body.z(0).c_if(cr3, 0) expected = QuantumCircuit(qr, clbits, cr1, cr2, cr3, cr4) expected.if_test((cr1, 0), true_body, [qr[0]], clbits + list(cr1)) @@ -209,14 +213,18 @@ def test_register_condition_in_nested_block(self): test = QuantumCircuit(qr, clbits, cr1, cr2, cr3, cr4) with test.while_loop((cr1, 0)): with test.if_test((cr2, 0)) as else_: - test.x(0).c_if(cr3, 0) + with self.assertWarns(DeprecationWarning): + test.x(0).c_if(cr3, 0) with else_: - test.z(0).c_if(cr4, 0) + with self.assertWarns(DeprecationWarning): + test.z(0).c_if(cr4, 0) true_body = QuantumCircuit([qr[0]], cr2, cr3, cr4) - true_body.x(0).c_if(cr3, 0) + with self.assertWarns(DeprecationWarning): + true_body.x(0).c_if(cr3, 0) false_body = QuantumCircuit([qr[0]], cr2, cr3, cr4) - false_body.z(0).c_if(cr4, 0) + with self.assertWarns(DeprecationWarning): + false_body.z(0).c_if(cr4, 0) while_body = QuantumCircuit([qr[0]], clbits, cr1, cr2, cr3, cr4) while_body.if_else((cr2, 0), true_body, false_body, [qr[0]], clbits) @@ -647,17 +655,23 @@ def test_if_else_tracks_registers(self): test = QuantumCircuit(qr, *cr) with test.if_test((cr[0], 0)) as else_: - test.h(0).c_if(cr[1], 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(cr[1], 0) # Test repetition. - test.h(0).c_if(cr[1], 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(cr[1], 0) with else_: - test.h(0).c_if(cr[2], 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(cr[2], 0) true_body = QuantumCircuit([qr[0]], cr[0], cr[1], cr[2]) - true_body.h(qr[0]).c_if(cr[1], 0) - true_body.h(qr[0]).c_if(cr[1], 0) + with self.assertWarns(DeprecationWarning): + true_body.h(qr[0]).c_if(cr[1], 0) + with self.assertWarns(DeprecationWarning): + true_body.h(qr[0]).c_if(cr[1], 0) false_body = QuantumCircuit([qr[0]], cr[0], cr[1], cr[2]) - false_body.h(qr[0]).c_if(cr[2], 0) + with self.assertWarns(DeprecationWarning): + false_body.h(qr[0]).c_if(cr[2], 0) expected = QuantumCircuit(qr, *cr) expected.if_else( @@ -1036,11 +1050,13 @@ def test_break_continue_accept_c_if(self, loop_operation): test = QuantumCircuit(qubits, clbits) with test.for_loop(range(2)): test.h(0) - loop_operation(test).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + loop_operation(test).c_if(1, 0) body = QuantumCircuit([qubits[0]], [clbits[1]]) body.h(qubits[0]) - loop_operation(body).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + loop_operation(body).c_if(clbits[1], 0) expected = QuantumCircuit(qubits, clbits) expected.for_loop(range(2), None, body, [qubits[0]], [clbits[1]]) @@ -1052,11 +1068,13 @@ def test_break_continue_accept_c_if(self, loop_operation): test = QuantumCircuit(qubits, clbits) with test.while_loop(cond): test.h(0) - loop_operation(test).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + loop_operation(test).c_if(1, 0) body = QuantumCircuit([qubits[0]], clbits) body.h(qubits[0]) - loop_operation(body).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + loop_operation(body).c_if(clbits[1], 0) expected = QuantumCircuit(qubits, clbits) expected.while_loop(cond, body, [qubits[0]], clbits) @@ -1230,7 +1248,8 @@ def test_break_continue_nested_in_if(self, loop_operation): # full width of the loop do so. with test.if_test(cond_inner): pass - test.h(0).c_if(2, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(2, 0) true_body1 = QuantumCircuit([qubits[0], clbits[0], clbits[2]]) loop_operation(true_body1) @@ -1240,7 +1259,8 @@ def test_break_continue_nested_in_if(self, loop_operation): loop_body = QuantumCircuit([qubits[0], clbits[0], clbits[2]]) loop_body.if_test(cond_inner, true_body1, [qubits[0]], [clbits[0], clbits[2]]) loop_body.if_test(cond_inner, true_body2, [], [clbits[0]]) - loop_body.h(qubits[0]).c_if(clbits[2], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[0]).c_if(clbits[2], 0) expected = QuantumCircuit(qubits, clbits) expected.for_loop(range(2), None, loop_body, [qubits[0]], [clbits[0], clbits[2]]) @@ -1258,7 +1278,8 @@ def test_break_continue_nested_in_if(self, loop_operation): pass with else_: pass - test.h(0).c_if(2, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(2, 0) true_body1 = QuantumCircuit([qubits[0], qubits[1], clbits[0], clbits[2]]) true_body1.h(qubits[1]) @@ -1273,7 +1294,8 @@ def test_break_continue_nested_in_if(self, loop_operation): cond_inner, true_body1, false_body1, [qubits[0], qubits[1]], [clbits[0], clbits[2]] ) loop_body.if_else(cond_inner, true_body2, false_body2, [], [clbits[0]]) - loop_body.h(qubits[0]).c_if(clbits[2], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[0]).c_if(clbits[2], 0) expected = QuantumCircuit(qubits, clbits) expected.for_loop( @@ -1289,7 +1311,8 @@ def test_break_continue_nested_in_if(self, loop_operation): loop_operation(test) with test.if_test(cond_inner): pass - test.h(0).c_if(2, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(2, 0) true_body1 = QuantumCircuit([qubits[0], clbits[0], clbits[1], clbits[2]]) loop_operation(true_body1) @@ -1301,7 +1324,8 @@ def test_break_continue_nested_in_if(self, loop_operation): cond_inner, true_body1, [qubits[0]], [clbits[0], clbits[1], clbits[2]] ) loop_body.if_test(cond_inner, true_body2, [], [clbits[0]]) - loop_body.h(qubits[0]).c_if(clbits[2], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[0]).c_if(clbits[2], 0) expected = QuantumCircuit(qubits, clbits) expected.while_loop( @@ -1321,7 +1345,8 @@ def test_break_continue_nested_in_if(self, loop_operation): pass with else_: pass - test.h(0).c_if(2, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(2, 0) true_body1 = QuantumCircuit([qubits[0], qubits[1], clbits[0], clbits[1], clbits[2]]) true_body1.h(qubits[1]) @@ -1340,7 +1365,8 @@ def test_break_continue_nested_in_if(self, loop_operation): [clbits[0], clbits[1], clbits[2]], ) loop_body.if_else(cond_inner, true_body2, false_body2, [], [clbits[0]]) - loop_body.h(qubits[0]).c_if(clbits[2], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[0]).c_if(clbits[2], 0) expected = QuantumCircuit(qubits, clbits) expected.while_loop( @@ -1368,7 +1394,8 @@ def test_break_continue_nested_in_switch(self, loop_operation): with test.switch(clbits[0]) as case: with case(case.DEFAULT): pass - test.h(0).c_if(clbits[2], 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(clbits[2], 0) body0 = QuantumCircuit([qubits[0], clbits[0], clbits[2]]) loop_operation(body0) @@ -1379,7 +1406,8 @@ def test_break_continue_nested_in_switch(self, loop_operation): loop_body = QuantumCircuit([qubits[0], clbits[0], clbits[2]]) loop_body.switch(clbits[0], [(0, body0), (1, body1)], [qubits[0]], [clbits[0], clbits[2]]) loop_body.switch(clbits[0], [(CASE_DEFAULT, body2)], [], [clbits[0]]) - loop_body.h(qubits[0]).c_if(clbits[2], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[0]).c_if(clbits[2], 0) expected = QuantumCircuit(qubits, clbits) expected.for_loop(range(2), None, loop_body, [qubits[0]], [clbits[0], clbits[2]]) @@ -1465,18 +1493,23 @@ def test_break_continue_deeply_nested(self, loop_operation): loop_operation(test) # inner true 2 with test.if_test(cond_inner): - test.h(0).c_if(3, 0) - test.h(1).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(4, 0) # outer true 2 with test.if_test(cond_outer): - test.h(2).c_if(5, 0) - test.h(3).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(6, 0) inner_true_body1 = QuantumCircuit(qubits[:4], clbits[:2], clbits[3:7]) loop_operation(inner_true_body1) inner_true_body2 = QuantumCircuit([qubits[0], clbits[0], clbits[3]]) - inner_true_body2.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + inner_true_body2.h(qubits[0]).c_if(clbits[3], 0) outer_true_body1 = QuantumCircuit(qubits[:4], clbits[:2], clbits[3:7]) outer_true_body1.if_test( @@ -1485,15 +1518,18 @@ def test_break_continue_deeply_nested(self, loop_operation): outer_true_body1.if_test( cond_inner, inner_true_body2, [qubits[0]], [clbits[0], clbits[3]] ) - outer_true_body1.h(qubits[1]).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + outer_true_body1.h(qubits[1]).c_if(clbits[4], 0) outer_true_body2 = QuantumCircuit([qubits[2], clbits[1], clbits[5]]) - outer_true_body2.h(qubits[2]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + outer_true_body2.h(qubits[2]).c_if(clbits[5], 0) loop_body = QuantumCircuit(qubits[:4], clbits[:2] + clbits[3:7]) loop_body.if_test(cond_outer, outer_true_body1, qubits[:4], clbits[:2] + clbits[3:7]) loop_body.if_test(cond_outer, outer_true_body2, [qubits[2]], [clbits[1], clbits[5]]) - loop_body.h(qubits[3]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[3]).c_if(clbits[6], 0) expected = QuantumCircuit(qubits, clbits) expected.for_loop(range(2), None, loop_body, qubits[:4], clbits[:2] + clbits[3:7]) @@ -1507,31 +1543,43 @@ def test_break_continue_deeply_nested(self, loop_operation): with test.if_test(cond_outer): # inner 1 with test.if_test(cond_inner) as inner1_else: - test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) with inner1_else: - loop_operation(test).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + loop_operation(test).c_if(4, 0) # inner 2 with test.if_test(cond_inner) as inner2_else: - test.h(1).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(5, 0) with inner2_else: - test.h(2).c_if(6, 0) - test.h(3).c_if(7, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(7, 0) # outer 2 with test.if_test(cond_outer) as outer2_else: - test.h(4).c_if(8, 0) + with self.assertWarns(DeprecationWarning): + test.h(4).c_if(8, 0) with outer2_else: - test.h(5).c_if(9, 0) - test.h(6).c_if(10, 0) + with self.assertWarns(DeprecationWarning): + test.h(5).c_if(9, 0) + with self.assertWarns(DeprecationWarning): + test.h(6).c_if(10, 0) inner1_true = QuantumCircuit(qubits[:7], clbits[:2], clbits[3:11]) - inner1_true.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + inner1_true.h(qubits[0]).c_if(clbits[3], 0) inner1_false = QuantumCircuit(qubits[:7], clbits[:2], clbits[3:11]) - loop_operation(inner1_false).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + loop_operation(inner1_false).c_if(clbits[4], 0) inner2_true = QuantumCircuit([qubits[1], qubits[2], clbits[0], clbits[5], clbits[6]]) - inner2_true.h(qubits[1]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + inner2_true.h(qubits[1]).c_if(clbits[5], 0) inner2_false = QuantumCircuit([qubits[1], qubits[2], clbits[0], clbits[5], clbits[6]]) - inner2_false.h(qubits[2]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + inner2_false.h(qubits[2]).c_if(clbits[6], 0) outer1_true = QuantumCircuit(qubits[:7], clbits[:2], clbits[3:11]) outer1_true.if_else( @@ -1544,12 +1592,15 @@ def test_break_continue_deeply_nested(self, loop_operation): qubits[1:3], [clbits[0], clbits[5], clbits[6]], ) - outer1_true.h(qubits[3]).c_if(clbits[7], 0) + with self.assertWarns(DeprecationWarning): + outer1_true.h(qubits[3]).c_if(clbits[7], 0) outer2_true = QuantumCircuit([qubits[4], qubits[5], clbits[1], clbits[8], clbits[9]]) - outer2_true.h(qubits[4]).c_if(clbits[8], 0) + with self.assertWarns(DeprecationWarning): + outer2_true.h(qubits[4]).c_if(clbits[8], 0) outer2_false = QuantumCircuit([qubits[4], qubits[5], clbits[1], clbits[8], clbits[9]]) - outer2_false.h(qubits[5]).c_if(clbits[9], 0) + with self.assertWarns(DeprecationWarning): + outer2_false.h(qubits[5]).c_if(clbits[9], 0) loop_body = QuantumCircuit(qubits[:7], clbits[:2], clbits[3:11]) loop_body.if_test(cond_outer, outer1_true, qubits[:7], clbits[:2] + clbits[3:11]) @@ -1560,7 +1611,8 @@ def test_break_continue_deeply_nested(self, loop_operation): qubits[4:6], [clbits[1], clbits[8], clbits[9]], ) - loop_body.h(qubits[6]).c_if(clbits[10], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[6]).c_if(clbits[10], 0) expected = QuantumCircuit(qubits, clbits) expected.for_loop(range(2), None, loop_body, qubits[:7], clbits[:2] + clbits[3:11]) @@ -1574,72 +1626,90 @@ def test_break_continue_deeply_nested(self, loop_operation): test = QuantumCircuit(qubits, clbits) with test.for_loop(range(2)): - test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) # outer 1 with test.if_test(cond_outer) as outer1_else: - test.h(1).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(4, 0) with outer1_else: - test.h(2).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(5, 0) # outer 2 (nesting the inner condition in the 'if') with test.if_test(cond_outer) as outer2_else: - test.h(3).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(6, 0) # inner 21 with test.if_test(cond_inner) as inner21_else: loop_operation(test) with inner21_else: - test.h(4).c_if(7, 0) + with self.assertWarns(DeprecationWarning): + test.h(4).c_if(7, 0) # inner 22 with test.if_test(cond_inner) as inner22_else: - test.h(5).c_if(8, 0) + with self.assertWarns(DeprecationWarning): + test.h(5).c_if(8, 0) with inner22_else: loop_operation(test) # inner 23 with test.switch(cond_inner[0]) as inner23_case: with inner23_case(True): - test.h(5).c_if(8, 0) + with self.assertWarns(DeprecationWarning): + test.h(5).c_if(8, 0) with inner23_case(False): loop_operation(test) - test.h(6).c_if(9, 0) + with self.assertWarns(DeprecationWarning): + test.h(6).c_if(9, 0) with outer2_else: - test.h(7).c_if(10, 0) + with self.assertWarns(DeprecationWarning): + test.h(7).c_if(10, 0) # inner 24 with test.if_test(cond_inner) as inner24_else: - test.h(8).c_if(11, 0) + with self.assertWarns(DeprecationWarning): + test.h(8).c_if(11, 0) with inner24_else: - test.h(9).c_if(12, 0) + with self.assertWarns(DeprecationWarning): + test.h(9).c_if(12, 0) # outer 3 (nesting the inner condition in an 'else' branch) with test.if_test(cond_outer) as outer3_else: - test.h(10).c_if(13, 0) + with self.assertWarns(DeprecationWarning): + test.h(10).c_if(13, 0) with outer3_else: - test.h(11).c_if(14, 0) + with self.assertWarns(DeprecationWarning): + test.h(11).c_if(14, 0) # inner 31 with test.if_test(cond_inner) as inner31_else: loop_operation(test) with inner31_else: - test.h(12).c_if(15, 0) + with self.assertWarns(DeprecationWarning): + test.h(12).c_if(15, 0) # inner 32 with test.if_test(cond_inner) as inner32_else: - test.h(13).c_if(16, 0) + with self.assertWarns(DeprecationWarning): + test.h(13).c_if(16, 0) with inner32_else: loop_operation(test) # inner 33 with test.if_test(cond_inner) as inner33_else: - test.h(14).c_if(17, 0) + with self.assertWarns(DeprecationWarning): + test.h(14).c_if(17, 0) with inner33_else: - test.h(15).c_if(18, 0) + with self.assertWarns(DeprecationWarning): + test.h(15).c_if(18, 0) - test.h(16).c_if(19, 0) + with self.assertWarns(DeprecationWarning): + test.h(16).c_if(19, 0) # End of test "for" loop. # No `clbits[2]` here because that's only used in `cond_loop`, for while loops. @@ -1648,32 +1718,40 @@ def test_break_continue_deeply_nested(self, loop_operation): loop_bits = loop_qubits + loop_clbits outer1_true = QuantumCircuit([qubits[1], qubits[2], clbits[1], clbits[4], clbits[5]]) - outer1_true.h(qubits[1]).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + outer1_true.h(qubits[1]).c_if(clbits[4], 0) outer1_false = QuantumCircuit([qubits[1], qubits[2], clbits[1], clbits[4], clbits[5]]) - outer1_false.h(qubits[2]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + outer1_false.h(qubits[2]).c_if(clbits[5], 0) inner21_true = QuantumCircuit(loop_bits) loop_operation(inner21_true) inner21_false = QuantumCircuit(loop_bits) - inner21_false.h(qubits[4]).c_if(clbits[7], 0) + with self.assertWarns(DeprecationWarning): + inner21_false.h(qubits[4]).c_if(clbits[7], 0) inner22_true = QuantumCircuit(loop_bits) - inner22_true.h(qubits[5]).c_if(clbits[8], 0) + with self.assertWarns(DeprecationWarning): + inner22_true.h(qubits[5]).c_if(clbits[8], 0) inner22_false = QuantumCircuit(loop_bits) loop_operation(inner22_false) inner23_true = QuantumCircuit(loop_bits) - inner23_true.h(qubits[5]).c_if(clbits[8], 0) + with self.assertWarns(DeprecationWarning): + inner23_true.h(qubits[5]).c_if(clbits[8], 0) inner23_false = QuantumCircuit(loop_bits) loop_operation(inner23_false) inner24_true = QuantumCircuit(qubits[8:10], [clbits[0], clbits[11], clbits[12]]) - inner24_true.h(qubits[8]).c_if(clbits[11], 0) + with self.assertWarns(DeprecationWarning): + inner24_true.h(qubits[8]).c_if(clbits[11], 0) inner24_false = QuantumCircuit(qubits[8:10], [clbits[0], clbits[11], clbits[12]]) - inner24_false.h(qubits[9]).c_if(clbits[12], 0) + with self.assertWarns(DeprecationWarning): + inner24_false.h(qubits[9]).c_if(clbits[12], 0) outer2_true = QuantumCircuit(loop_bits) - outer2_true.h(qubits[3]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + outer2_true.h(qubits[3]).c_if(clbits[6], 0) outer2_true.if_else(cond_inner, inner21_true, inner21_false, loop_qubits, loop_clbits) outer2_true.if_else(cond_inner, inner22_true, inner22_false, loop_qubits, loop_clbits) outer2_true.switch( @@ -1682,9 +1760,11 @@ def test_break_continue_deeply_nested(self, loop_operation): loop_qubits, loop_clbits, ) - outer2_true.h(qubits[6]).c_if(clbits[9], 0) + with self.assertWarns(DeprecationWarning): + outer2_true.h(qubits[6]).c_if(clbits[9], 0) outer2_false = QuantumCircuit(loop_bits) - outer2_false.h(qubits[7]).c_if(clbits[10], 0) + with self.assertWarns(DeprecationWarning): + outer2_false.h(qubits[7]).c_if(clbits[10], 0) outer2_false.if_else( cond_inner, inner24_true, @@ -1696,22 +1776,28 @@ def test_break_continue_deeply_nested(self, loop_operation): inner31_true = QuantumCircuit(loop_bits) loop_operation(inner31_true) inner31_false = QuantumCircuit(loop_bits) - inner31_false.h(qubits[12]).c_if(clbits[15], 0) + with self.assertWarns(DeprecationWarning): + inner31_false.h(qubits[12]).c_if(clbits[15], 0) inner32_true = QuantumCircuit(loop_bits) - inner32_true.h(qubits[13]).c_if(clbits[16], 0) + with self.assertWarns(DeprecationWarning): + inner32_true.h(qubits[13]).c_if(clbits[16], 0) inner32_false = QuantumCircuit(loop_bits) loop_operation(inner32_false) inner33_true = QuantumCircuit(qubits[14:16], [clbits[0], clbits[17], clbits[18]]) - inner33_true.h(qubits[14]).c_if(clbits[17], 0) + with self.assertWarns(DeprecationWarning): + inner33_true.h(qubits[14]).c_if(clbits[17], 0) inner33_false = QuantumCircuit(qubits[14:16], [clbits[0], clbits[17], clbits[18]]) - inner33_false.h(qubits[15]).c_if(clbits[18], 0) + with self.assertWarns(DeprecationWarning): + inner33_false.h(qubits[15]).c_if(clbits[18], 0) outer3_true = QuantumCircuit(loop_bits) - outer3_true.h(qubits[10]).c_if(clbits[13], 0) + with self.assertWarns(DeprecationWarning): + outer3_true.h(qubits[10]).c_if(clbits[13], 0) outer3_false = QuantumCircuit(loop_bits) - outer3_false.h(qubits[11]).c_if(clbits[14], 0) + with self.assertWarns(DeprecationWarning): + outer3_false.h(qubits[11]).c_if(clbits[14], 0) outer3_false.if_else(cond_inner, inner31_true, inner31_false, loop_qubits, loop_clbits) outer3_false.if_else(cond_inner, inner32_true, inner32_false, loop_qubits, loop_clbits) outer3_false.if_else( @@ -1723,7 +1809,8 @@ def test_break_continue_deeply_nested(self, loop_operation): ) loop_body = QuantumCircuit(loop_bits) - loop_body.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[0]).c_if(clbits[3], 0) loop_body.if_else( cond_outer, outer1_true, @@ -1733,7 +1820,8 @@ def test_break_continue_deeply_nested(self, loop_operation): ) loop_body.if_else(cond_outer, outer2_true, outer2_false, loop_qubits, loop_clbits) loop_body.if_else(cond_outer, outer3_true, outer3_false, loop_qubits, loop_clbits) - loop_body.h(qubits[16]).c_if(clbits[19], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[16]).c_if(clbits[19], 0) expected = QuantumCircuit(qubits, clbits) expected.for_loop(range(2), None, loop_body, loop_qubits, loop_clbits) @@ -1756,33 +1844,41 @@ def test_break_continue_deeply_nested(self, loop_operation): loop_operation(test) # inner true 2 with test.if_test(cond_inner): - test.h(0).c_if(3, 0) - test.h(1).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(4, 0) # outer true 2 with test.if_test(cond_outer): - test.h(2).c_if(5, 0) - test.h(3).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(6, 0) inner_true_body1 = QuantumCircuit(qubits[:4], clbits[:7]) loop_operation(inner_true_body1) inner_true_body2 = QuantumCircuit([qubits[0], clbits[0], clbits[3]]) - inner_true_body2.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + inner_true_body2.h(qubits[0]).c_if(clbits[3], 0) outer_true_body1 = QuantumCircuit(qubits[:4], clbits[:7]) outer_true_body1.if_test(cond_inner, inner_true_body1, qubits[:4], clbits[:7]) outer_true_body1.if_test( cond_inner, inner_true_body2, [qubits[0]], [clbits[0], clbits[3]] ) - outer_true_body1.h(qubits[1]).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + outer_true_body1.h(qubits[1]).c_if(clbits[4], 0) outer_true_body2 = QuantumCircuit([qubits[2], clbits[1], clbits[5]]) - outer_true_body2.h(qubits[2]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + outer_true_body2.h(qubits[2]).c_if(clbits[5], 0) loop_body = QuantumCircuit(qubits[:4], clbits[:7]) loop_body.if_test(cond_outer, outer_true_body1, qubits[:4], clbits[:7]) loop_body.if_test(cond_outer, outer_true_body2, [qubits[2]], [clbits[1], clbits[5]]) - loop_body.h(qubits[3]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[3]).c_if(clbits[6], 0) expected = QuantumCircuit(qubits, clbits) expected.while_loop(cond_loop, loop_body, qubits[:4], clbits[:7]) @@ -1796,31 +1892,43 @@ def test_break_continue_deeply_nested(self, loop_operation): with test.if_test(cond_outer): # inner 1 with test.if_test(cond_inner) as inner1_else: - test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) with inner1_else: - loop_operation(test).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + loop_operation(test).c_if(4, 0) # inner 2 with test.if_test(cond_inner) as inner2_else: - test.h(1).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(5, 0) with inner2_else: - test.h(2).c_if(6, 0) - test.h(3).c_if(7, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(7, 0) # outer 2 with test.if_test(cond_outer) as outer2_else: - test.h(4).c_if(8, 0) + with self.assertWarns(DeprecationWarning): + test.h(4).c_if(8, 0) with outer2_else: - test.h(5).c_if(9, 0) - test.h(6).c_if(10, 0) + with self.assertWarns(DeprecationWarning): + test.h(5).c_if(9, 0) + with self.assertWarns(DeprecationWarning): + test.h(6).c_if(10, 0) inner1_true = QuantumCircuit(qubits[:7], clbits[:11]) - inner1_true.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + inner1_true.h(qubits[0]).c_if(clbits[3], 0) inner1_false = QuantumCircuit(qubits[:7], clbits[:11]) - loop_operation(inner1_false).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + loop_operation(inner1_false).c_if(clbits[4], 0) inner2_true = QuantumCircuit([qubits[1], qubits[2], clbits[0], clbits[5], clbits[6]]) - inner2_true.h(qubits[1]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + inner2_true.h(qubits[1]).c_if(clbits[5], 0) inner2_false = QuantumCircuit([qubits[1], qubits[2], clbits[0], clbits[5], clbits[6]]) - inner2_false.h(qubits[2]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + inner2_false.h(qubits[2]).c_if(clbits[6], 0) outer1_true = QuantumCircuit(qubits[:7], clbits[:11]) outer1_true.if_else(cond_inner, inner1_true, inner1_false, qubits[:7], clbits[:11]) @@ -1831,12 +1939,15 @@ def test_break_continue_deeply_nested(self, loop_operation): qubits[1:3], [clbits[0], clbits[5], clbits[6]], ) - outer1_true.h(qubits[3]).c_if(clbits[7], 0) + with self.assertWarns(DeprecationWarning): + outer1_true.h(qubits[3]).c_if(clbits[7], 0) outer2_true = QuantumCircuit([qubits[4], qubits[5], clbits[1], clbits[8], clbits[9]]) - outer2_true.h(qubits[4]).c_if(clbits[8], 0) + with self.assertWarns(DeprecationWarning): + outer2_true.h(qubits[4]).c_if(clbits[8], 0) outer2_false = QuantumCircuit([qubits[4], qubits[5], clbits[1], clbits[8], clbits[9]]) - outer2_false.h(qubits[5]).c_if(clbits[9], 0) + with self.assertWarns(DeprecationWarning): + outer2_false.h(qubits[5]).c_if(clbits[9], 0) loop_body = QuantumCircuit(qubits[:7], clbits[:11]) loop_body.if_test(cond_outer, outer1_true, qubits[:7], clbits[:11]) @@ -1847,7 +1958,8 @@ def test_break_continue_deeply_nested(self, loop_operation): qubits[4:6], [clbits[1], clbits[8], clbits[9]], ) - loop_body.h(qubits[6]).c_if(clbits[10], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[6]).c_if(clbits[10], 0) expected = QuantumCircuit(qubits, clbits) expected.while_loop(cond_loop, loop_body, qubits[:7], clbits[:11]) @@ -1857,65 +1969,81 @@ def test_break_continue_deeply_nested(self, loop_operation): with self.subTest("while/else/else"): test = QuantumCircuit(qubits, clbits) with test.while_loop(cond_loop): - test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) # outer 1 with test.if_test(cond_outer) as outer1_else: - test.h(1).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(4, 0) with outer1_else: - test.h(2).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(5, 0) # outer 2 (nesting the inner condition in the 'if') with test.if_test(cond_outer) as outer2_else: - test.h(3).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(6, 0) # inner 21 with test.if_test(cond_inner) as inner21_else: loop_operation(test) with inner21_else: - test.h(4).c_if(7, 0) + with self.assertWarns(DeprecationWarning): + test.h(4).c_if(7, 0) # inner 22 with test.if_test(cond_inner) as inner22_else: - test.h(5).c_if(8, 0) + with self.assertWarns(DeprecationWarning): + test.h(5).c_if(8, 0) with inner22_else: loop_operation(test) - test.h(6).c_if(9, 0) + with self.assertWarns(DeprecationWarning): + test.h(6).c_if(9, 0) with outer2_else: - test.h(7).c_if(10, 0) + with self.assertWarns(DeprecationWarning): + test.h(7).c_if(10, 0) # inner 23 with test.if_test(cond_inner) as inner23_else: - test.h(8).c_if(11, 0) + with self.assertWarns(DeprecationWarning): + test.h(8).c_if(11, 0) with inner23_else: - test.h(9).c_if(12, 0) + with self.assertWarns(DeprecationWarning): + test.h(9).c_if(12, 0) # outer 3 (nesting the inner condition in an 'else' branch) with test.if_test(cond_outer) as outer3_else: - test.h(10).c_if(13, 0) + with self.assertWarns(DeprecationWarning): + test.h(10).c_if(13, 0) with outer3_else: - test.h(11).c_if(14, 0) + with self.assertWarns(DeprecationWarning): + test.h(11).c_if(14, 0) # inner 31 with test.if_test(cond_inner) as inner31_else: loop_operation(test) with inner31_else: - test.h(12).c_if(15, 0) + with self.assertWarns(DeprecationWarning): + test.h(12).c_if(15, 0) # inner 32 with test.if_test(cond_inner) as inner32_else: - test.h(13).c_if(16, 0) + with self.assertWarns(DeprecationWarning): + test.h(13).c_if(16, 0) with inner32_else: loop_operation(test) # inner 33 with test.if_test(cond_inner) as inner33_else: - test.h(14).c_if(17, 0) + with self.assertWarns(DeprecationWarning): + test.h(14).c_if(17, 0) with inner33_else: - test.h(15).c_if(18, 0) - - test.h(16).c_if(19, 0) + with self.assertWarns(DeprecationWarning): + test.h(15).c_if(18, 0) + with self.assertWarns(DeprecationWarning): + test.h(16).c_if(19, 0) # End of test "for" loop. # No `clbits[2]` here because that's only used in `cond_loop`, for while loops. @@ -1924,32 +2052,41 @@ def test_break_continue_deeply_nested(self, loop_operation): loop_bits = loop_qubits + loop_clbits outer1_true = QuantumCircuit([qubits[1], qubits[2], clbits[1], clbits[4], clbits[5]]) - outer1_true.h(qubits[1]).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + outer1_true.h(qubits[1]).c_if(clbits[4], 0) outer1_false = QuantumCircuit([qubits[1], qubits[2], clbits[1], clbits[4], clbits[5]]) - outer1_false.h(qubits[2]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + outer1_false.h(qubits[2]).c_if(clbits[5], 0) inner21_true = QuantumCircuit(loop_bits) loop_operation(inner21_true) inner21_false = QuantumCircuit(loop_bits) - inner21_false.h(qubits[4]).c_if(clbits[7], 0) + with self.assertWarns(DeprecationWarning): + inner21_false.h(qubits[4]).c_if(clbits[7], 0) inner22_true = QuantumCircuit(loop_bits) - inner22_true.h(qubits[5]).c_if(clbits[8], 0) + with self.assertWarns(DeprecationWarning): + inner22_true.h(qubits[5]).c_if(clbits[8], 0) inner22_false = QuantumCircuit(loop_bits) loop_operation(inner22_false) inner23_true = QuantumCircuit(qubits[8:10], [clbits[0], clbits[11], clbits[12]]) - inner23_true.h(qubits[8]).c_if(clbits[11], 0) + with self.assertWarns(DeprecationWarning): + inner23_true.h(qubits[8]).c_if(clbits[11], 0) inner23_false = QuantumCircuit(qubits[8:10], [clbits[0], clbits[11], clbits[12]]) - inner23_false.h(qubits[9]).c_if(clbits[12], 0) + with self.assertWarns(DeprecationWarning): + inner23_false.h(qubits[9]).c_if(clbits[12], 0) outer2_true = QuantumCircuit(loop_bits) - outer2_true.h(qubits[3]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + outer2_true.h(qubits[3]).c_if(clbits[6], 0) outer2_true.if_else(cond_inner, inner21_true, inner21_false, loop_qubits, loop_clbits) outer2_true.if_else(cond_inner, inner22_true, inner22_false, loop_qubits, loop_clbits) - outer2_true.h(qubits[6]).c_if(clbits[9], 0) + with self.assertWarns(DeprecationWarning): + outer2_true.h(qubits[6]).c_if(clbits[9], 0) outer2_false = QuantumCircuit(loop_bits) - outer2_false.h(qubits[7]).c_if(clbits[10], 0) + with self.assertWarns(DeprecationWarning): + outer2_false.h(qubits[7]).c_if(clbits[10], 0) outer2_false.if_else( cond_inner, inner23_true, @@ -1961,22 +2098,28 @@ def test_break_continue_deeply_nested(self, loop_operation): inner31_true = QuantumCircuit(loop_bits) loop_operation(inner31_true) inner31_false = QuantumCircuit(loop_bits) - inner31_false.h(qubits[12]).c_if(clbits[15], 0) + with self.assertWarns(DeprecationWarning): + inner31_false.h(qubits[12]).c_if(clbits[15], 0) inner32_true = QuantumCircuit(loop_bits) - inner32_true.h(qubits[13]).c_if(clbits[16], 0) + with self.assertWarns(DeprecationWarning): + inner32_true.h(qubits[13]).c_if(clbits[16], 0) inner32_false = QuantumCircuit(loop_bits) loop_operation(inner32_false) inner33_true = QuantumCircuit(qubits[14:16], [clbits[0], clbits[17], clbits[18]]) - inner33_true.h(qubits[14]).c_if(clbits[17], 0) + with self.assertWarns(DeprecationWarning): + inner33_true.h(qubits[14]).c_if(clbits[17], 0) inner33_false = QuantumCircuit(qubits[14:16], [clbits[0], clbits[17], clbits[18]]) - inner33_false.h(qubits[15]).c_if(clbits[18], 0) + with self.assertWarns(DeprecationWarning): + inner33_false.h(qubits[15]).c_if(clbits[18], 0) outer3_true = QuantumCircuit(loop_bits) - outer3_true.h(qubits[10]).c_if(clbits[13], 0) + with self.assertWarns(DeprecationWarning): + outer3_true.h(qubits[10]).c_if(clbits[13], 0) outer3_false = QuantumCircuit(loop_bits) - outer3_false.h(qubits[11]).c_if(clbits[14], 0) + with self.assertWarns(DeprecationWarning): + outer3_false.h(qubits[11]).c_if(clbits[14], 0) outer3_false.if_else(cond_inner, inner31_true, inner31_false, loop_qubits, loop_clbits) outer3_false.if_else(cond_inner, inner32_true, inner32_false, loop_qubits, loop_clbits) outer3_false.if_else( @@ -1988,7 +2131,8 @@ def test_break_continue_deeply_nested(self, loop_operation): ) loop_body = QuantumCircuit(loop_bits) - loop_body.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[0]).c_if(clbits[3], 0) loop_body.if_else( cond_outer, outer1_true, @@ -1998,7 +2142,8 @@ def test_break_continue_deeply_nested(self, loop_operation): ) loop_body.if_else(cond_outer, outer2_true, outer2_false, loop_qubits, loop_clbits) loop_body.if_else(cond_outer, outer3_true, outer3_false, loop_qubits, loop_clbits) - loop_body.h(qubits[16]).c_if(clbits[19], 0) + with self.assertWarns(DeprecationWarning): + loop_body.h(qubits[16]).c_if(clbits[19], 0) expected = QuantumCircuit(qubits, clbits) expected.while_loop(cond_loop, loop_body, loop_qubits, loop_clbits) @@ -2008,52 +2153,68 @@ def test_break_continue_deeply_nested(self, loop_operation): with self.subTest("if/while/if/switch"): test = QuantumCircuit(qubits, clbits) with test.if_test(cond_outer): # outer_t - test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) with test.while_loop(cond_loop): # loop - test.h(1).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(4, 0) with test.if_test(cond_inner): # inner_t - test.h(2).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(5, 0) with test.switch(5) as case_: with case_(False): # case_f - test.h(3).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(6, 0) with case_(True): # case_t loop_operation(test) - test.h(4).c_if(7, 0) + with self.assertWarns(DeprecationWarning): + test.h(4).c_if(7, 0) # exit inner_t - test.h(5).c_if(8, 0) + with self.assertWarns(DeprecationWarning): + test.h(5).c_if(8, 0) # exit loop - test.h(6).c_if(9, 0) + with self.assertWarns(DeprecationWarning): + test.h(6).c_if(9, 0) # exit outer_t - test.h(7).c_if(10, 0) + with self.assertWarns(DeprecationWarning): + test.h(7).c_if(10, 0) case_f = QuantumCircuit(qubits[1:6], [clbits[0], clbits[2]] + clbits[4:9]) - case_f.h(qubits[3]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + case_f.h(qubits[3]).c_if(clbits[6], 0) case_t = QuantumCircuit(qubits[1:6], [clbits[0], clbits[2]] + clbits[4:9]) loop_operation(case_t) inner_t = QuantumCircuit(qubits[1:6], [clbits[0], clbits[2]] + clbits[4:9]) - inner_t.h(qubits[2]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + inner_t.h(qubits[2]).c_if(clbits[5], 0) inner_t.switch( clbits[5], [(False, case_f), (True, case_t)], qubits[1:6], [clbits[0], clbits[2]] + clbits[4:9], ) - inner_t.h(qubits[4]).c_if(clbits[7], 0) + with self.assertWarns(DeprecationWarning): + inner_t.h(qubits[4]).c_if(clbits[7], 0) loop = QuantumCircuit(qubits[1:6], [clbits[0], clbits[2]] + clbits[4:9]) - loop.h(qubits[1]).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + loop.h(qubits[1]).c_if(clbits[4], 0) loop.if_test(cond_inner, inner_t, qubits[1:6], [clbits[0], clbits[2]] + clbits[4:9]) - loop.h(qubits[5]).c_if(clbits[8], 0) + with self.assertWarns(DeprecationWarning): + loop.h(qubits[5]).c_if(clbits[8], 0) outer_t = QuantumCircuit(qubits[:7], clbits[:10]) - outer_t.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + outer_t.h(qubits[0]).c_if(clbits[3], 0) outer_t.while_loop(cond_loop, loop, qubits[1:6], [clbits[0], clbits[2]] + clbits[4:9]) - outer_t.h(qubits[6]).c_if(clbits[9], 0) + with self.assertWarns(DeprecationWarning): + outer_t.h(qubits[6]).c_if(clbits[9], 0) expected = QuantumCircuit(qubits, clbits) expected.if_test(cond_outer, outer_t, qubits[:7], clbits[:10]) - expected.h(qubits[7]).c_if(clbits[10], 0) + with self.assertWarns(DeprecationWarning): + expected.h(qubits[7]).c_if(clbits[10], 0) self.assertEqual(canonicalize_control_flow(test), canonicalize_control_flow(expected)) @@ -2061,64 +2222,82 @@ def test_break_continue_deeply_nested(self, loop_operation): test = QuantumCircuit(qubits, clbits) with test.switch(0) as case_outer: with case_outer(False): # outer_case_f - test.h(0).c_if(3, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(3, 0) with test.for_loop(range(2)): # loop - test.h(1).c_if(4, 0) + with self.assertWarns(DeprecationWarning): + test.h(1).c_if(4, 0) with test.switch(1) as case_inner: with case_inner(False): # inner_case_f - test.h(2).c_if(5, 0) + with self.assertWarns(DeprecationWarning): + test.h(2).c_if(5, 0) with test.if_test((2, True)) as else_: # if_t - test.h(3).c_if(6, 0) + with self.assertWarns(DeprecationWarning): + test.h(3).c_if(6, 0) with else_: # if_f loop_operation(test) - test.h(4).c_if(7, 0) + with self.assertWarns(DeprecationWarning): + test.h(4).c_if(7, 0) with case_inner(True): # inner_case_t loop_operation(test) - test.h(5).c_if(8, 0) + with self.assertWarns(DeprecationWarning): + test.h(5).c_if(8, 0) # exit loop1 - test.h(6).c_if(9, 0) + with self.assertWarns(DeprecationWarning): + test.h(6).c_if(9, 0) with case_outer(True): # outer_case_t - test.h(7).c_if(10, 0) - test.h(8).c_if(11, 0) + with self.assertWarns(DeprecationWarning): + test.h(7).c_if(10, 0) + with self.assertWarns(DeprecationWarning): + test.h(8).c_if(11, 0) if_t = QuantumCircuit(qubits[1:6], clbits[1:3] + clbits[4:9]) - if_t.h(qubits[3]).c_if(clbits[6], 0) + with self.assertWarns(DeprecationWarning): + if_t.h(qubits[3]).c_if(clbits[6], 0) if_f = QuantumCircuit(qubits[1:6], clbits[1:3] + clbits[4:9]) loop_operation(if_f) inner_case_f = QuantumCircuit(qubits[1:6], clbits[1:3] + clbits[4:9]) - inner_case_f.h(qubits[2]).c_if(clbits[5], 0) + with self.assertWarns(DeprecationWarning): + inner_case_f.h(qubits[2]).c_if(clbits[5], 0) inner_case_f.if_else( (clbits[2], True), if_t, if_f, qubits[1:6], clbits[1:3] + clbits[4:9] ) - inner_case_f.h(qubits[4]).c_if(clbits[7], 0) + with self.assertWarns(DeprecationWarning): + inner_case_f.h(qubits[4]).c_if(clbits[7], 0) inner_case_t = QuantumCircuit(qubits[1:6], clbits[1:3] + clbits[4:9]) loop_operation(inner_case_t) loop = QuantumCircuit(qubits[1:6], clbits[1:3] + clbits[4:9]) - loop.h(qubits[1]).c_if(clbits[4], 0) + with self.assertWarns(DeprecationWarning): + loop.h(qubits[1]).c_if(clbits[4], 0) loop.switch( clbits[1], [(False, inner_case_f), (True, inner_case_t)], qubits[1:6], clbits[1:3] + clbits[4:9], ) - loop.h(qubits[5]).c_if(clbits[8], 0) + with self.assertWarns(DeprecationWarning): + loop.h(qubits[5]).c_if(clbits[8], 0) outer_case_f = QuantumCircuit(qubits[:8], clbits[:11]) - outer_case_f.h(qubits[0]).c_if(clbits[3], 0) + with self.assertWarns(DeprecationWarning): + outer_case_f.h(qubits[0]).c_if(clbits[3], 0) outer_case_f.for_loop(range(2), None, loop, qubits[1:6], clbits[1:3] + clbits[4:9]) - outer_case_f.h(qubits[6]).c_if(clbits[9], 0) + with self.assertWarns(DeprecationWarning): + outer_case_f.h(qubits[6]).c_if(clbits[9], 0) outer_case_t = QuantumCircuit(qubits[:8], clbits[:11]) - outer_case_t.h(qubits[7]).c_if(clbits[10], 0) + with self.assertWarns(DeprecationWarning): + outer_case_t.h(qubits[7]).c_if(clbits[10], 0) expected = QuantumCircuit(qubits, clbits) expected.switch( clbits[0], [(False, outer_case_f), (True, outer_case_t)], qubits[:8], clbits[:11] ) - expected.h(qubits[8]).c_if(clbits[11], 0) + with self.assertWarns(DeprecationWarning): + expected.h(qubits[8]).c_if(clbits[11], 0) self.assertEqual(canonicalize_control_flow(test), canonicalize_control_flow(expected)) @@ -2351,10 +2530,12 @@ def test_access_of_clbit_from_c_if(self): with self.subTest("if"): test = QuantumCircuit(bits) with test.if_test(cond): - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) body = QuantumCircuit([qubits[0]], clbits) - body.h(qubits[0]).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(clbits[1], 0) expected = QuantumCircuit(bits) expected.if_test(cond, body, [qubits[0]], clbits) @@ -2363,41 +2544,49 @@ def test_access_of_clbit_from_c_if(self): with test.if_test(cond) as else_: pass with else_: - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) true_body = QuantumCircuit([qubits[0]], clbits) false_body = QuantumCircuit([qubits[0]], clbits) - false_body.h(qubits[0]).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + false_body.h(qubits[0]).c_if(clbits[1], 0) expected = QuantumCircuit(bits) expected.if_else(cond, true_body, false_body, [qubits[0]], clbits) with self.subTest("for"): test = QuantumCircuit(bits) with test.for_loop(range(2)): - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) body = QuantumCircuit([qubits[0]], clbits) - body.h(qubits[0]).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(clbits[1], 0) expected = QuantumCircuit(bits) expected.for_loop(range(2), None, body, [qubits[0]], clbits) with self.subTest("while"): test = QuantumCircuit(bits) with test.while_loop(cond): - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) body = QuantumCircuit([qubits[0]], clbits) - body.h(qubits[0]).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(clbits[1], 0) expected = QuantumCircuit(bits) expected.while_loop(cond, body, [qubits[0]], clbits) with self.subTest("switch"): test = QuantumCircuit(bits) with test.switch(cond[0]) as case, case(False): - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) body = QuantumCircuit([qubits[0]], clbits) - body.h(qubits[0]).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(clbits[1], 0) expected = QuantumCircuit(bits) expected.switch(cond[0], [(False, body)], [qubits[0]], clbits) @@ -2405,10 +2594,12 @@ def test_access_of_clbit_from_c_if(self): test = QuantumCircuit(bits) with test.for_loop(range(2)): with test.if_test(cond): - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) true_body = QuantumCircuit([qubits[0]], clbits) - true_body.h(qubits[0]).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + true_body.h(qubits[0]).c_if(clbits[1], 0) body = QuantumCircuit([qubits[0]], clbits) body.if_test(cond, body, [qubits[0]], clbits) expected = QuantumCircuit(bits) @@ -2417,10 +2608,12 @@ def test_access_of_clbit_from_c_if(self): with self.subTest("switch inside for"): test = QuantumCircuit(bits) with test.for_loop(range(2)), test.switch(cond[0]) as case, case(False): - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) body = QuantumCircuit([qubits[0]], clbits) - body.h(qubits[0]).c_if(clbits[1], 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(clbits[1], 0) body = QuantumCircuit([qubits[0]], clbits) body.switch(cond[0], [(False, body)], [qubits[0]], clbits) expected = QuantumCircuit(bits) @@ -2438,10 +2631,12 @@ def test_access_of_classicalregister_from_c_if(self): with self.subTest("if"): test = QuantumCircuit(qubits, clbits, creg) with test.if_test(cond): - test.h(0).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(creg, 0) body = QuantumCircuit([qubits[0]], clbits, creg) - body.h(qubits[0]).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(creg, 0) expected = QuantumCircuit(qubits, clbits, creg) expected.if_test(cond, body, [qubits[0]], all_clbits) @@ -2450,41 +2645,49 @@ def test_access_of_classicalregister_from_c_if(self): with test.if_test(cond) as else_: pass with else_: - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) true_body = QuantumCircuit([qubits[0]], clbits, creg) false_body = QuantumCircuit([qubits[0]], clbits, creg) - false_body.h(qubits[0]).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + false_body.h(qubits[0]).c_if(creg, 0) expected = QuantumCircuit(qubits, clbits, creg) expected.if_else(cond, true_body, false_body, [qubits[0]], all_clbits) with self.subTest("for"): test = QuantumCircuit(qubits, clbits, creg) with test.for_loop(range(2)): - test.h(0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(1, 0) body = QuantumCircuit([qubits[0]], clbits, creg) - body.h(qubits[0]).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(creg, 0) expected = QuantumCircuit(qubits, clbits, creg) expected.for_loop(range(2), None, body, [qubits[0]], all_clbits) with self.subTest("while"): test = QuantumCircuit(qubits, clbits, creg) with test.while_loop(cond): - test.h(0).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(creg, 0) body = QuantumCircuit([qubits[0]], clbits, creg) - body.h(qubits[0]).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(creg, 0) expected = QuantumCircuit(qubits, clbits, creg) expected.while_loop(cond, body, [qubits[0]], all_clbits) with self.subTest("switch"): test = QuantumCircuit(qubits, clbits, creg) with test.switch(cond[0]) as case, case(False): - test.h(0).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(creg, 0) body = QuantumCircuit([qubits[0]], clbits, creg) - body.h(qubits[0]).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + body.h(qubits[0]).c_if(creg, 0) expected = QuantumCircuit(qubits, clbits, creg) expected.switch(cond[0], [(False, body)], [qubits[0]], all_clbits) @@ -2492,10 +2695,12 @@ def test_access_of_classicalregister_from_c_if(self): test = QuantumCircuit(qubits, clbits, creg) with test.for_loop(range(2)): with test.if_test(cond): - test.h(0).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(creg, 0) true_body = QuantumCircuit([qubits[0]], clbits, creg) - true_body.h(qubits[0]).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + true_body.h(qubits[0]).c_if(creg, 0) body = QuantumCircuit([qubits[0]], clbits, creg) body.if_test(cond, body, [qubits[0]], all_clbits) expected = QuantumCircuit(qubits, clbits, creg) @@ -2505,10 +2710,12 @@ def test_access_of_classicalregister_from_c_if(self): test = QuantumCircuit(qubits, clbits, creg) with test.for_loop(range(2)): with test.switch(cond[0]) as case, case(False): - test.h(0).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + test.h(0).c_if(creg, 0) case = QuantumCircuit([qubits[0]], clbits, creg) - case.h(qubits[0]).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + case.h(qubits[0]).c_if(creg, 0) body = QuantumCircuit([qubits[0]], clbits, creg) body.switch(cond[0], [(False, case)], [qubits[0]], all_clbits) expected = QuantumCircuit(qubits, clbits, creg) @@ -3424,7 +3631,8 @@ def test_if_placeholder_rejects_c_if(self): NotImplementedError, r"IfElseOp cannot be classically controlled through Instruction\.c_if", ): - placeholder.c_if(bits[1], 0) + with self.assertWarns(DeprecationWarning): + placeholder.c_if(bits[1], 0) with self.subTest("else"): test = QuantumCircuit(bits) @@ -3441,7 +3649,8 @@ def test_if_placeholder_rejects_c_if(self): NotImplementedError, r"IfElseOp cannot be classically controlled through Instruction\.c_if", ): - placeholder.c_if(bits[1], 0) + with self.assertWarns(DeprecationWarning): + placeholder.c_if(bits[1], 0) def test_switch_rejects_operations_outside_cases(self): """It shouldn't be permissible to try and put instructions inside a switch but outside a @@ -3543,7 +3752,8 @@ def test_reject_c_if_from_outside_scope(self): with self.assertRaisesRegex( CircuitError, r"Cannot add resources after the scope has been built\." ): - instructions.c_if(*cond) + with self.assertWarns(DeprecationWarning): + instructions.c_if(*cond) with self.subTest("else"): test = QuantumCircuit(bits) @@ -3554,7 +3764,8 @@ def test_reject_c_if_from_outside_scope(self): with self.assertRaisesRegex( CircuitError, r"Cannot add resources after the scope has been built\." ): - instructions.c_if(*cond) + with self.assertWarns(DeprecationWarning): + instructions.c_if(*cond) with self.subTest("for"): test = QuantumCircuit(bits) @@ -3563,7 +3774,8 @@ def test_reject_c_if_from_outside_scope(self): with self.assertRaisesRegex( CircuitError, r"Cannot add resources after the scope has been built\." ): - instructions.c_if(*cond) + with self.assertWarns(DeprecationWarning): + instructions.c_if(*cond) with self.subTest("while"): test = QuantumCircuit(bits) @@ -3572,7 +3784,8 @@ def test_reject_c_if_from_outside_scope(self): with self.assertRaisesRegex( CircuitError, r"Cannot add resources after the scope has been built\." ): - instructions.c_if(*cond) + with self.assertWarns(DeprecationWarning): + instructions.c_if(*cond) with self.subTest("switch"): test = QuantumCircuit(bits) @@ -3581,7 +3794,8 @@ def test_reject_c_if_from_outside_scope(self): with self.assertRaisesRegex( CircuitError, r"Cannot add resources after the scope has been built\." ): - instructions.c_if(*cond) + with self.assertWarns(DeprecationWarning): + instructions.c_if(*cond) with self.subTest("if inside for"): # As a side-effect of how the lazy building of 'if' statements works, we actually @@ -3595,7 +3809,8 @@ def test_reject_c_if_from_outside_scope(self): with self.assertRaisesRegex( CircuitError, r"Cannot add resources after the scope has been built\." ): - instructions.c_if(*cond) + with self.assertWarns(DeprecationWarning): + instructions.c_if(*cond) with self.subTest("switch inside for"): # `switch` has the same lazy building as `if`, so is subject to the same considerations @@ -3608,7 +3823,8 @@ def test_reject_c_if_from_outside_scope(self): with self.assertRaisesRegex( CircuitError, r"Cannot add resources after the scope has been built\." ): - instructions.c_if(*cond) + with self.assertWarns(DeprecationWarning): + instructions.c_if(*cond) def test_raising_inside_context_manager_leave_circuit_usable(self): """Test that if we leave a builder by raising some sort of exception, the circuit is left in diff --git a/test/python/circuit/test_extensions_standard.py b/test/python/circuit/test_extensions_standard.py index 73e00fa84c90..042087baa6d9 100644 --- a/test/python/circuit/test_extensions_standard.py +++ b/test/python/circuit/test_extensions_standard.py @@ -76,7 +76,8 @@ def test_barrier_invalid(self): def test_conditional_barrier_invalid(self): qc = self.circuit barrier = qc.barrier(self.qr) - self.assertRaises(QiskitError, barrier.c_if, self.cr, 0) + with self.assertWarns(DeprecationWarning): + self.assertRaises(QiskitError, barrier.c_if, self.cr, 0) def test_barrier_reg(self): self.circuit.barrier(self.qr) @@ -131,13 +132,15 @@ def test_ch_invalid(self): self.assertRaises(CircuitError, qc.ch, "a", self.qr[1]) def test_cif_reg(self): - self.circuit.h(self.qr[0]).c_if(self.cr, 7) + with self.assertWarns(DeprecationWarning): + self.circuit.h(self.qr[0]).c_if(self.cr, 7) self.assertEqual(self.circuit[0].operation.name, "h") self.assertEqual(self.circuit[0].qubits, (self.qr[0],)) self.assertEqual(self.circuit[0].operation.condition, (self.cr, 7)) def test_cif_single_bit(self): - self.circuit.h(self.qr[0]).c_if(self.cr[0], True) + with self.assertWarns(DeprecationWarning): + self.circuit.h(self.qr[0]).c_if(self.cr[0], True) self.assertEqual(self.circuit[0].operation.name, "h") self.assertEqual(self.circuit[0].qubits, (self.qr[0],)) self.assertEqual(self.circuit[0].operation.condition, (self.cr[0], True)) diff --git a/test/python/circuit/test_instruction_repeat.py b/test/python/circuit/test_instruction_repeat.py index 778e6aad64c2..74142fa898e9 100644 --- a/test/python/circuit/test_instruction_repeat.py +++ b/test/python/circuit/test_instruction_repeat.py @@ -55,7 +55,8 @@ def test_standard_1Q_one(self): def test_conditional(self): """Test that repetition works with a condition.""" cr = ClassicalRegister(3, "cr") - gate = SGate().c_if(cr, 7).repeat(5) + with self.assertWarns(DeprecationWarning): + gate = SGate().c_if(cr, 7).repeat(5) self.assertEqual(gate.condition, (cr, 7)) defn = QuantumCircuit(1) @@ -98,7 +99,8 @@ def test_standard_2Q_one(self): def test_conditional(self): """Test that repetition works with a condition.""" cr = ClassicalRegister(3, "cr") - gate = CXGate().c_if(cr, 7).repeat(5) + with self.assertWarns(DeprecationWarning): + gate = CXGate().c_if(cr, 7).repeat(5) self.assertEqual(gate.condition, (cr, 7)) defn = QuantumCircuit(2) @@ -145,7 +147,8 @@ def test_measure_one(self): def test_measure_conditional(self): """Test conditional measure moves condition to the outside.""" cr = ClassicalRegister(3, "cr") - measure = Measure().c_if(cr, 7).repeat(5) + with self.assertWarns(DeprecationWarning): + measure = Measure().c_if(cr, 7).repeat(5) self.assertEqual(measure.condition, (cr, 7)) defn = QuantumCircuit(1, 1) diff --git a/test/python/circuit/test_instructions.py b/test/python/circuit/test_instructions.py index 170b47632c4d..a412d09a2302 100644 --- a/test/python/circuit/test_instructions.py +++ b/test/python/circuit/test_instructions.py @@ -176,7 +176,8 @@ def circuit_instruction_circuit_roundtrip(self): circ1.u(0.1, 0.2, -0.2, q[0]) circ1.barrier() circ1.measure(q, c) - circ1.rz(0.8, q[0]).c_if(c, 6) + with self.assertWarns(DeprecationWarning): + circ1.rz(0.8, q[0]).c_if(c, 6) inst = circ1.to_instruction() circ2 = QuantumCircuit(q, c, name="circ2") @@ -238,16 +239,20 @@ def test_reverse_instruction(self): circ.u(0.1, 0.2, -0.2, q[0]) circ.barrier() circ.measure(q[0], c[0]) - circ.rz(0.8, q[0]).c_if(c, 6) - inst = circ.to_instruction() + with self.assertWarns(DeprecationWarning): + circ.rz(0.8, q[0]).c_if(c, 6) + with self.assertWarns(DeprecationWarning): + inst = circ.to_instruction() circ = QuantumCircuit(q, c, name="circ") - circ.rz(0.8, q[0]).c_if(c, 6) + with self.assertWarns(DeprecationWarning): + circ.rz(0.8, q[0]).c_if(c, 6) circ.measure(q[0], c[0]) circ.barrier() circ.u(0.1, 0.2, -0.2, q[0]) circ.t(q[1]) - inst_reverse = circ.to_instruction() + with self.assertWarns(DeprecationWarning): + inst_reverse = circ.to_instruction() self.assertEqual(inst.reverse_ops().definition, inst_reverse.definition) @@ -336,8 +341,10 @@ def test_inverse_instruction_with_conditional(self): circ.u(0.1, 0.2, -0.2, q[0]) circ.barrier() circ.measure(q[0], c[0]) - circ.rz(0.8, q[0]).c_if(c, 6) - inst = circ.to_instruction() + with self.assertWarns(DeprecationWarning): + circ.rz(0.8, q[0]).c_if(c, 6) + with self.assertWarns(DeprecationWarning): + inst = circ.to_instruction() self.assertRaises(CircuitError, inst.inverse) def test_inverse_opaque(self): @@ -467,7 +474,8 @@ def test_instructionset_c_if_direct_resource(self): def case(resource): qc = QuantumCircuit(cr1, qubits, loose_clbits, cr2, cr3) - qc.x(0).c_if(resource, 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(resource, 0) c_if_resource = qc.data[0].operation.condition[0] self.assertIs(c_if_resource, resource) @@ -500,7 +508,8 @@ def test_instructionset_c_if_indexing(self): qc = QuantumCircuit(cr1, qubits, loose_clbits, cr2, cr3) for index, clbit in enumerate(qc.clbits): with self.subTest(index=index): - qc.x(0).c_if(index, 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(index, 0) qc.measure(0, index) from_c_if = qc.data[-2].operation.condition[0] from_measure = qc.data[-1].clbits[0] @@ -516,13 +525,16 @@ def test_instructionset_c_if_size_1_classical_register(self): qc = QuantumCircuit(qr, cr) with self.subTest("classical register"): - qc.x(0).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(cr, 0) self.assertIs(qc.data[-1].operation.condition[0], cr) with self.subTest("classical bit by value"): - qc.x(0).c_if(cr[0], 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(cr[0], 0) self.assertIs(qc.data[-1].operation.condition[0], cr[0]) with self.subTest("classical bit by index"): - qc.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 0) self.assertIs(qc.data[-1].operation.condition[0], cr[0]) def test_instructionset_c_if_no_classical_registers(self): @@ -533,10 +545,12 @@ def test_instructionset_c_if_no_classical_registers(self): bits = [Qubit(), Clbit()] qc = QuantumCircuit(bits) with self.subTest("by value"): - qc.x(0).c_if(bits[1], 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(bits[1], 0) self.assertIs(qc.data[-1].operation.condition[0], bits[1]) with self.subTest("by index"): - qc.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 0) self.assertIs(qc.data[-1].operation.condition[0], bits[1]) def test_instructionset_c_if_rejects_invalid_specifiers(self): @@ -550,7 +564,8 @@ def case(specifier, message): qc = QuantumCircuit(qreg, creg) instruction = qc.x(0) with self.assertRaisesRegex(CircuitError, message): - instruction.c_if(specifier, 0) + with self.assertWarns(DeprecationWarning): + instruction.c_if(specifier, 0) with self.subTest("absent bit"): case(Clbit(), r"Clbit .* is not present in this circuit\.") @@ -574,21 +589,24 @@ def test_instructionset_c_if_with_no_requester(self): instructions = InstructionSet() instructions.add(instruction, [Qubit()], []) register = ClassicalRegister(2) - instructions.c_if(register, 0) + with self.assertWarns(DeprecationWarning): + instructions.c_if(register, 0) self.assertIs(instructions[0].operation.condition[0], register) with self.subTest("accepts arbitrary bit"): instruction = RZGate(0) instructions = InstructionSet() instructions.add(instruction, [Qubit()], []) bit = Clbit() - instructions.c_if(bit, 0) + with self.assertWarns(DeprecationWarning): + instructions.c_if(bit, 0) self.assertIs(instructions[0].operation.condition[0], bit) with self.subTest("rejects index"): instruction = RZGate(0) instructions = InstructionSet() instructions.add(instruction, [Qubit()], []) with self.assertRaisesRegex(CircuitError, r"Cannot pass an index as a condition .*"): - instructions.c_if(0, 0) + with self.assertWarns(DeprecationWarning): + instructions.c_if(0, 0) def test_instructionset_c_if_calls_custom_requester(self): """Test that :meth:`.InstructionSet.c_if` calls a custom requester, and uses its output.""" @@ -613,7 +631,8 @@ def dummy_requester(specifier): instructions = InstructionSet(resource_requester=dummy_requester) instructions.add(instruction, [Qubit()], []) bit = Clbit() - instructions.c_if(bit, 0) + with self.assertWarns(DeprecationWarning): + instructions.c_if(bit, 0) dummy_requester.assert_called_once_with(bit) self.assertIs(instructions[0].operation.condition[0], sentinel_bit) with self.subTest("calls requester with index"): @@ -622,7 +641,8 @@ def dummy_requester(specifier): instructions = InstructionSet(resource_requester=dummy_requester) instructions.add(instruction, [Qubit()], []) index = 0 - instructions.c_if(index, 0) + with self.assertWarns(DeprecationWarning): + instructions.c_if(index, 0) dummy_requester.assert_called_once_with(index) self.assertIs(instructions[0].operation.condition[0], sentinel_bit) with self.subTest("calls requester with register"): @@ -631,7 +651,8 @@ def dummy_requester(specifier): instructions = InstructionSet(resource_requester=dummy_requester) instructions.add(instruction, [Qubit()], []) register = ClassicalRegister(2) - instructions.c_if(register, 0) + with self.assertWarns(DeprecationWarning): + instructions.c_if(register, 0) dummy_requester.assert_called_once_with(register) self.assertIs(instructions[0].operation.condition[0], sentinel_register) with self.subTest("calls requester only once when broadcast"): @@ -641,7 +662,8 @@ def dummy_requester(specifier): for instruction in instruction_list: instructions.add(instruction, [Qubit()], []) register = ClassicalRegister(2) - instructions.c_if(register, 0) + with self.assertWarns(DeprecationWarning): + instructions.c_if(register, 0) dummy_requester.assert_called_once_with(register) for instruction in instruction_list: self.assertIs(instructions[0].operation.condition[0], sentinel_register) diff --git a/test/python/circuit/test_random_circuit.py b/test/python/circuit/test_random_circuit.py index ebbdfd28d648..0d798fe8ad19 100644 --- a/test/python/circuit/test_random_circuit.py +++ b/test/python/circuit/test_random_circuit.py @@ -49,14 +49,16 @@ def test_random_circuit_conditional_reset(self): """Test generating random circuits with conditional and reset.""" num_qubits = 1 depth = 100 - circ = random_circuit(num_qubits, depth, conditional=True, reset=True, seed=5) + with self.assertWarns(DeprecationWarning): + circ = random_circuit(num_qubits, depth, conditional=True, reset=True, seed=5) self.assertEqual(circ.width(), 2 * num_qubits) self.assertIn("reset", circ.count_ops()) def test_large_conditional(self): """Test that conditions do not fail with large conditionals. Regression test of gh-6994.""" # The main test is that this call actually returns without raising an exception. - circ = random_circuit(64, 2, conditional=True, seed=0) + with self.assertWarns(DeprecationWarning): + circ = random_circuit(64, 2, conditional=True, seed=0) # Test that at least one instruction had a condition generated. It's possible that this # fails due to very bad luck with the random seed - if so, change the seed to ensure that a # condition _is_ generated, because we need to test that generation doesn't error. @@ -72,7 +74,8 @@ def test_large_conditional(self): def test_random_mid_circuit_measure_conditional(self): """Test random circuit with mid-circuit measurements for conditionals.""" num_qubits = depth = 2 - circ = random_circuit(num_qubits, depth, conditional=True, seed=16) + with self.assertWarns(DeprecationWarning): + circ = random_circuit(num_qubits, depth, conditional=True, seed=16) self.assertEqual(circ.width(), 2 * num_qubits) op_names = [instruction.operation.name for instruction in circ] # Before a condition, there needs to be measurement in all the qubits. diff --git a/test/python/circuit/test_registerless_circuit.py b/test/python/circuit/test_registerless_circuit.py index 3f77919957da..c3da073e5234 100644 --- a/test/python/circuit/test_registerless_circuit.py +++ b/test/python/circuit/test_registerless_circuit.py @@ -195,10 +195,12 @@ def test_circuit_conditional(self): qreg = QuantumRegister(2) creg = ClassicalRegister(4) circuit = QuantumCircuit(qreg, creg) - circuit.h(0).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + circuit.h(0).c_if(creg, 3) expected = QuantumCircuit(qreg, creg) - expected.h(qreg[0]).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + expected.h(qreg[0]).c_if(creg, 3) self.assertEqual(circuit, expected) @@ -333,11 +335,14 @@ def test_circuit_conditional(self): qreg1 = QuantumRegister(2) creg = ClassicalRegister(2) circuit = QuantumCircuit(qreg0, qreg1, creg) - circuit.h(range(1, 3)).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + circuit.h(range(1, 3)).c_if(creg, 3) expected = QuantumCircuit(qreg0, qreg1, creg) - expected.h(qreg0[1]).c_if(creg, 3) - expected.h(qreg1[0]).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + expected.h(qreg0[1]).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + expected.h(qreg1[0]).c_if(creg, 3) self.assertEqual(circuit, expected) @@ -466,11 +471,14 @@ def test_circuit_conditional(self): qreg1 = QuantumRegister(2) creg = ClassicalRegister(2) circuit = QuantumCircuit(qreg0, qreg1, creg) - circuit.h(slice(1, 3)).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + circuit.h(slice(1, 3)).c_if(creg, 3) expected = QuantumCircuit(qreg0, qreg1, creg) - expected.h(qreg0[1]).c_if(creg, 3) - expected.h(qreg1[0]).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + expected.h(qreg0[1]).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + expected.h(qreg1[0]).c_if(creg, 3) self.assertEqual(circuit, expected) @@ -504,10 +512,12 @@ def test_bit_conditional_single_gate(self): qreg = QuantumRegister(1) creg = ClassicalRegister(2) circuit = QuantumCircuit(qreg, creg) - circuit.h(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + circuit.h(0).c_if(0, True) expected = QuantumCircuit(qreg, creg) - expected.h(qreg[0]).c_if(creg[0], True) + with self.assertWarns(DeprecationWarning): + expected.h(qreg[0]).c_if(creg[0], True) self.assertEqual(circuit, expected) def test_bit_conditional_multiple_gates(self): @@ -516,12 +526,18 @@ def test_bit_conditional_multiple_gates(self): creg = ClassicalRegister(2) creg1 = ClassicalRegister(1) circuit = QuantumCircuit(qreg, creg, creg1) - circuit.h(0).c_if(0, True) - circuit.h(1).c_if(1, False) - circuit.cx(1, 0).c_if(2, True) + with self.assertWarns(DeprecationWarning): + circuit.h(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + circuit.h(1).c_if(1, False) + with self.assertWarns(DeprecationWarning): + circuit.cx(1, 0).c_if(2, True) expected = QuantumCircuit(qreg, creg, creg1) - expected.h(qreg[0]).c_if(creg[0], True) - expected.h(qreg[1]).c_if(creg[1], False) - expected.cx(qreg[1], qreg[0]).c_if(creg1[0], True) + with self.assertWarns(DeprecationWarning): + expected.h(qreg[0]).c_if(creg[0], True) + with self.assertWarns(DeprecationWarning): + expected.h(qreg[1]).c_if(creg[1], False) + with self.assertWarns(DeprecationWarning): + expected.cx(qreg[1], qreg[0]).c_if(creg1[0], True) self.assertEqual(circuit, expected) diff --git a/test/python/circuit/test_singleton.py b/test/python/circuit/test_singleton.py index 40549dd0ad15..8a2b57235f06 100644 --- a/test/python/circuit/test_singleton.py +++ b/test/python/circuit/test_singleton.py @@ -63,7 +63,8 @@ def test_label_not_singleton(self): def test_condition_not_singleton(self): gate = HGate() - condition_gate = HGate().c_if(Clbit(), 0) + with self.assertWarns(DeprecationWarning): + condition_gate = HGate().c_if(Clbit(), 0) self.assertIsNot(gate, condition_gate) def test_raise_on_state_mutation(self): @@ -76,7 +77,8 @@ def test_raise_on_state_mutation(self): def test_labeled_condition(self): singleton_gate = HGate() clbit = Clbit() - gate = HGate(label="conditionally special").c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + gate = HGate(label="conditionally special").c_if(clbit, 0) self.assertIsNot(singleton_gate, gate) self.assertEqual(gate.label, "conditionally special") self.assertEqual(gate.condition, (clbit, 0)) @@ -109,14 +111,16 @@ def test_label_copy_new(self): self.assertEqual(copied_label.label, "special") def test_condition_copy(self): - gate = HGate().c_if(Clbit(), 0) + with self.assertWarns(DeprecationWarning): + gate = HGate().c_if(Clbit(), 0) copied = gate.copy() self.assertIsNot(gate, copied) self.assertEqual(gate, copied) def test_condition_label_copy(self): clbit = Clbit() - gate = HGate(label="conditionally special").c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + gate = HGate(label="conditionally special").c_if(clbit, 0) copied = gate.copy() self.assertIsNot(gate, copied) self.assertEqual(gate, copied) @@ -136,14 +140,16 @@ def test_deepcopy_with_label(self): self.assertEqual(copied.label, "special") def test_deepcopy_with_condition(self): - gate = HGate().c_if(Clbit(), 0) + with self.assertWarns(DeprecationWarning): + gate = HGate().c_if(Clbit(), 0) copied = copy.deepcopy(gate) self.assertIsNot(gate, copied) self.assertEqual(gate, copied) def test_condition_label_deepcopy(self): clbit = Clbit() - gate = HGate(label="conditionally special").c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + gate = HGate(label="conditionally special").c_if(clbit, 0) copied = copy.deepcopy(gate) self.assertIsNot(gate, copied) self.assertEqual(gate, copied) @@ -193,7 +199,8 @@ def test_round_trip_dag_conversion_with_label(self): def test_round_trip_dag_conversion_with_condition(self): qc = QuantumCircuit(1, 1) - gate = HGate().c_if(qc.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + gate = HGate().c_if(qc.cregs[0], 0) qc.append(gate, [0]) dag = circuit_to_dag(qc) out = dag_to_circuit(dag) @@ -203,7 +210,8 @@ def test_round_trip_dag_conversion_with_condition(self): def test_round_trip_dag_conversion_condition_label(self): qc = QuantumCircuit(1, 1) - gate = HGate(label="conditionally special").c_if(qc.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + gate = HGate(label="conditionally special").c_if(qc.cregs[0], 0) qc.append(gate, [0]) dag = circuit_to_dag(qc) out = dag_to_circuit(dag) @@ -217,7 +225,8 @@ def test_condition_via_instructionset(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr, 1) self.assertIsNot(gate, circuit.data[0].operation) self.assertEqual(circuit.data[0].operation.condition, (cr, 1)) @@ -287,7 +296,8 @@ def test_immutable_pickle(self): def test_mutable_pickle(self): gate = SXGate() clbit = Clbit() - condition_gate = gate.c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + condition_gate = gate.c_if(clbit, 0) self.assertIsNot(gate, condition_gate) self.assertEqual(condition_gate.condition, (clbit, 0)) self.assertTrue(condition_gate.mutable) @@ -505,7 +515,8 @@ def test_label_not_singleton(self): def test_condition_not_singleton(self): gate = CZGate() - condition_gate = CZGate().c_if(Clbit(), 0) + with self.assertWarns(DeprecationWarning): + condition_gate = CZGate().c_if(Clbit(), 0) self.assertIsNot(gate, condition_gate) def test_raise_on_state_mutation(self): @@ -518,7 +529,8 @@ def test_raise_on_state_mutation(self): def test_labeled_condition(self): singleton_gate = CSwapGate() clbit = Clbit() - gate = CSwapGate(label="conditionally special").c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + gate = CSwapGate(label="conditionally special").c_if(clbit, 0) self.assertIsNot(singleton_gate, gate) self.assertEqual(gate.label, "conditionally special") self.assertEqual(gate.condition, (clbit, 0)) @@ -551,14 +563,16 @@ def test_label_copy_new(self): self.assertEqual(copied_label.label, "special") def test_condition_copy(self): - gate = CZGate().c_if(Clbit(), 0) + with self.assertWarns(DeprecationWarning): + gate = CZGate().c_if(Clbit(), 0) copied = gate.copy() self.assertIsNot(gate, copied) self.assertEqual(gate, copied) def test_condition_label_copy(self): clbit = Clbit() - gate = CZGate(label="conditionally special").c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + gate = CZGate(label="conditionally special").c_if(clbit, 0) copied = gate.copy() self.assertIsNot(gate, copied) self.assertEqual(gate, copied) @@ -583,14 +597,16 @@ def test_deepcopy_with_label(self): self.assertNotEqual(singleton_gate.label, copied.label) def test_deepcopy_with_condition(self): - gate = CCXGate().c_if(Clbit(), 0) + with self.assertWarns(DeprecationWarning): + gate = CCXGate().c_if(Clbit(), 0) copied = copy.deepcopy(gate) self.assertIsNot(gate, copied) self.assertEqual(gate, copied) def test_condition_label_deepcopy(self): clbit = Clbit() - gate = CHGate(label="conditionally special").c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + gate = CHGate(label="conditionally special").c_if(clbit, 0) copied = copy.deepcopy(gate) self.assertIsNot(gate, copied) self.assertEqual(gate, copied) @@ -640,7 +656,8 @@ def test_round_trip_dag_conversion_with_label(self): def test_round_trip_dag_conversion_with_condition(self): qc = QuantumCircuit(2, 1) - gate = CHGate().c_if(qc.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + gate = CHGate().c_if(qc.cregs[0], 0) qc.append(gate, [0, 1]) dag = circuit_to_dag(qc) out = dag_to_circuit(dag) @@ -650,7 +667,8 @@ def test_round_trip_dag_conversion_with_condition(self): def test_round_trip_dag_conversion_condition_label(self): qc = QuantumCircuit(2, 1) - gate = CHGate(label="conditionally special").c_if(qc.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + gate = CHGate(label="conditionally special").c_if(qc.cregs[0], 0) qc.append(gate, [0, 1]) dag = circuit_to_dag(qc) out = dag_to_circuit(dag) @@ -664,7 +682,8 @@ def test_condition_via_instructionset(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr, 1) self.assertIsNot(gate, circuit.data[0].operation) self.assertEqual(circuit.data[0].operation.condition, (cr, 1)) @@ -723,7 +742,8 @@ def test_inner_outer_label_with_c_if(self): inner_gate = HGate(label="my h gate") controlled_gate = inner_gate.control(label="foo") clbit = Clbit() - conditonal_controlled_gate = controlled_gate.c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + conditonal_controlled_gate = controlled_gate.c_if(clbit, 0) self.assertTrue(conditonal_controlled_gate.mutable) self.assertEqual("my h gate", conditonal_controlled_gate.base_gate.label) self.assertEqual("foo", conditonal_controlled_gate.label) @@ -733,7 +753,8 @@ def test_inner_outer_label_with_c_if_deepcopy(self): inner_gate = XGate(label="my h gate") controlled_gate = inner_gate.control(label="foo") clbit = Clbit() - conditonal_controlled_gate = controlled_gate.c_if(clbit, 0) + with self.assertWarns(DeprecationWarning): + conditonal_controlled_gate = controlled_gate.c_if(clbit, 0) self.assertTrue(conditonal_controlled_gate.mutable) self.assertEqual("my h gate", conditonal_controlled_gate.base_gate.label) self.assertEqual("foo", conditonal_controlled_gate.label) diff --git a/test/python/circuit/test_store.py b/test/python/circuit/test_store.py index 139192745d2e..ecb98681bbd2 100644 --- a/test/python/circuit/test_store.py +++ b/test/python/circuit/test_store.py @@ -73,7 +73,8 @@ def test_rejects_dangerous_cast(self): def test_rejects_c_if(self): instruction = Store(expr.Var.new("a", types.Bool()), expr.Var.new("b", types.Bool())) with self.assertRaises(NotImplementedError): - instruction.c_if(Clbit(), False) + with self.assertWarns(DeprecationWarning): + instruction.c_if(Clbit(), False) class TestStoreCircuit(QiskitTestCase): @@ -241,4 +242,5 @@ def test_rejects_c_if(self): qc = QuantumCircuit([Clbit()], inputs=[a]) instruction_set = qc.store(a, True) with self.assertRaises(NotImplementedError): - instruction_set.c_if(qc.clbits[0], False) + with self.assertWarns(DeprecationWarning): + instruction_set.c_if(qc.clbits[0], False) diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index c333ce9ace22..1ae0e327d8e7 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -284,7 +284,8 @@ def test_measure_to_registers_when_conditionals(self): qc.measure(qr[0], cr1) # Measure not required for a later conditional qc.measure(qr[1], cr2[1]) # Measure required for a later conditional - qc.h(qr[1]).c_if(cr2, 3) + with self.assertWarns(DeprecationWarning): + qc.h(qr[1]).c_if(cr2, 3) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) @@ -304,7 +305,8 @@ def test_convert_to_bfunc_plus_conditional(self): cr = ClassicalRegister(1) qc = QuantumCircuit(qr, cr) - qc.h(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.h(qr[0]).c_if(cr, 1) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) @@ -325,7 +327,8 @@ def test_convert_to_bfunc_plus_conditional_onebit(self): cr = ClassicalRegister(3) qc = QuantumCircuit(qr, cr) - qc.h(qr[0]).c_if(cr[2], 1) + with self.assertWarns(DeprecationWarning): + qc.h(qr[0]).c_if(cr[2], 1) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) @@ -351,7 +354,8 @@ def test_resize_value_to_register(self): cr3 = ClassicalRegister(1) qc = QuantumCircuit(qr, cr1, cr2, cr3) - qc.h(qr[0]).c_if(cr2, 2) + with self.assertWarns(DeprecationWarning): + qc.h(qr[0]).c_if(cr2, 2) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) diff --git a/test/python/compiler/test_disassembler.py b/test/python/compiler/test_disassembler.py index 0525b54e2107..bfeeeacf595c 100644 --- a/test/python/compiler/test_disassembler.py +++ b/test/python/compiler/test_disassembler.py @@ -191,7 +191,8 @@ def test_circuit_with_conditionals(self): qc = QuantumCircuit(qr, cr1, cr2) qc.measure(qr[0], cr1) # Measure not required for a later conditional qc.measure(qr[1], cr2[1]) # Measure required for a later conditional - qc.h(qr[1]).c_if(cr2, 3) + with self.assertWarns(DeprecationWarning): + qc.h(qr[1]).c_if(cr2, 3) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) circuits, run_config_out, header = disassemble(qobj) @@ -207,7 +208,8 @@ def test_circuit_with_simple_conditional(self): qr = QuantumRegister(1) cr = ClassicalRegister(1) qc = QuantumCircuit(qr, cr) - qc.h(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.h(qr[0]).c_if(cr, 1) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) circuits, run_config_out, header = disassemble(qobj) @@ -228,7 +230,8 @@ def test_circuit_with_single_bit_conditions(self): qr = QuantumRegister(1) cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) - qc.h(qr[0]).c_if(cr[0], 1) + with self.assertWarns(DeprecationWarning): + qc.h(qr[0]).c_if(cr[0], 1) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) @@ -267,9 +270,12 @@ def test_multiple_conditionals_multiple_registers(self): qc = QuantumCircuit(qr, cr1, cr2, cr3, cr4) qc.x(qr[1]) qc.h(qr) - qc.cx(qr[1], qr[0]).c_if(cr3, 14) - qc.ccx(qr[0], qr[2], qr[1]).c_if(cr4, 1) - qc.h(qr).c_if(cr1, 3) + with self.assertWarns(DeprecationWarning): + qc.cx(qr[1], qr[0]).c_if(cr3, 14) + with self.assertWarns(DeprecationWarning): + qc.ccx(qr[0], qr[2], qr[1]).c_if(cr4, 1) + with self.assertWarns(DeprecationWarning): + qc.h(qr).c_if(cr1, 3) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) circuits, run_config_out, header = disassemble(qobj) @@ -285,7 +291,8 @@ def test_circuit_with_bit_conditional_1(self): qr = QuantumRegister(2) cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) - qc.h(qr[0]).c_if(cr[1], True) + with self.assertWarns(DeprecationWarning): + qc.h(qr[0]).c_if(cr[1], True) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) circuits, run_config_out, header = disassemble(qobj) @@ -302,9 +309,12 @@ def test_circuit_with_bit_conditional_2(self): cr = ClassicalRegister(2) cr1 = ClassicalRegister(2) qc = QuantumCircuit(qr, cr, cr1) - qc.h(qr[0]).c_if(cr1[1], False) - qc.h(qr[1]).c_if(cr[0], True) - qc.cx(qr[0], qr[1]).c_if(cr1[0], False) + with self.assertWarns(DeprecationWarning): + qc.h(qr[0]).c_if(cr1[1], False) + with self.assertWarns(DeprecationWarning): + qc.h(qr[1]).c_if(cr[0], True) + with self.assertWarns(DeprecationWarning): + qc.cx(qr[0], qr[1]).c_if(cr1[0], False) with self.assertWarns(DeprecationWarning): qobj = assemble(qc) circuits, run_config_out, header = disassemble(qobj) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 825dfd6bdfe7..b7bf3365f1d9 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -2210,7 +2210,8 @@ def _regular_circuit(self): base.append(CustomCX(), [3, 6]) base.append(CustomCX(), [5, 4]) base.append(CustomCX(), [5, 3]) - base.append(CustomCX(), [2, 4]).c_if(base.cregs[0], 3) + with self.assertWarns(DeprecationWarning): + base.append(CustomCX(), [2, 4]).c_if(base.cregs[0], 3) base.ry(a, 4) base.measure(4, 2) return base @@ -2819,7 +2820,8 @@ def test_parallel_singleton_conditional_gate(self, opt_level): circ = QuantumCircuit(2, 1) circ.h(0) circ.measure(0, circ.clbits[0]) - circ.z(1).c_if(circ.clbits[0], 1) + with self.assertWarns(DeprecationWarning): + circ.z(1).c_if(circ.clbits[0], 1) res = transpile( [circ, circ], backend, optimization_level=opt_level, seed_transpiler=123456769 ) @@ -3267,7 +3269,8 @@ def test_shared_classical_between_components_condition(self, opt_level): for i in range(18): qc.measure(i, creg[i]) - qc.ecr(20, 21).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.ecr(20, 21).c_if(creg, 0) tqc = transpile(qc, self.backend, optimization_level=opt_level, seed_transpiler=42) def _visit_block(circuit, qubit_mapping=None): @@ -3303,9 +3306,11 @@ def test_shared_classical_between_components_condition_large_to_small(self, opt_ qc.measure(24, creg[0]) qc.measure(23, creg[1]) # Component 1 - qc.h(0).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.h(0).c_if(creg, 0) for i in range(18): - qc.ecr(0, i + 1).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.ecr(0, i + 1).c_if(creg, 0) tqc = transpile(qc, self.backend, optimization_level=opt_level, seed_transpiler=123456789) def _visit_block(circuit, qubit_mapping=None): @@ -3377,9 +3382,11 @@ def test_shared_classical_between_components_condition_large_to_small_reverse_in qc.measure(0, creg[0]) qc.measure(1, creg[1]) # Component 1 - qc.h(24).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.h(24).c_if(creg, 0) for i in range(23, 5, -1): - qc.ecr(24, i).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.ecr(24, i).c_if(creg, 0) tqc = transpile(qc, self.backend, optimization_level=opt_level, seed_transpiler=2023) def _visit_block(circuit, qubit_mapping=None): @@ -3450,15 +3457,19 @@ def test_chained_data_dependency(self, opt_level): measure_op = Measure() qc.append(measure_op, [9], [creg[0]]) # Component 1 - qc.h(10).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.h(10).c_if(creg, 0) for i in range(11, 20): - qc.ecr(10, i).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.ecr(10, i).c_if(creg, 0) measure_op = Measure() qc.append(measure_op, [19], [creg[0]]) # Component 2 - qc.h(20).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.h(20).c_if(creg, 0) for i in range(21, 30): - qc.cz(20, i).c_if(creg, 0) + with self.assertWarns(DeprecationWarning): + qc.cz(20, i).c_if(creg, 0) measure_op = Measure() qc.append(measure_op, [29], [creg[0]]) tqc = transpile(qc, self.backend, optimization_level=opt_level, seed_transpiler=2023) diff --git a/test/python/converters/test_circuit_to_dag.py b/test/python/converters/test_circuit_to_dag.py index 0bded9c0f4a2..c89d47727f0c 100644 --- a/test/python/converters/test_circuit_to_dag.py +++ b/test/python/converters/test_circuit_to_dag.py @@ -34,7 +34,8 @@ def test_circuit_and_dag(self): circuit_in.h(qr[1]) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) - circuit_in.x(qr[0]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_in.x(qr[0]).c_if(cr, 0x3) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) circuit_in.measure(qr[2], cr[2]) diff --git a/test/python/converters/test_circuit_to_dagdependency.py b/test/python/converters/test_circuit_to_dagdependency.py index 9d33192d50a1..37ad23d5c47a 100644 --- a/test/python/converters/test_circuit_to_dagdependency.py +++ b/test/python/converters/test_circuit_to_dagdependency.py @@ -33,7 +33,8 @@ def test_circuit_and_dag_canonical(self): circuit_in.h(qr[1]) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) - circuit_in.x(qr[0]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_in.x(qr[0]).c_if(cr, 0x3) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) circuit_in.measure(qr[2], cr[2]) @@ -51,7 +52,8 @@ def test_circuit_and_dag_canonical2(self): circuit_in.h(qr[1]) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) - circuit_in.x(qr[0]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_in.x(qr[0]).c_if(cr, 0x3) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) circuit_in.measure(qr[2], cr[2]) diff --git a/test/python/converters/test_circuit_to_dagdependency_v2.py b/test/python/converters/test_circuit_to_dagdependency_v2.py index edeea3a59fea..9d72d045db31 100644 --- a/test/python/converters/test_circuit_to_dagdependency_v2.py +++ b/test/python/converters/test_circuit_to_dagdependency_v2.py @@ -33,7 +33,8 @@ def test_circuit_and_dag_canonical(self): circuit_in.h(qr[1]) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) - circuit_in.x(qr[0]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_in.x(qr[0]).c_if(cr, 0x3) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) circuit_in.measure(qr[2], cr[2]) diff --git a/test/python/converters/test_circuit_to_instruction.py b/test/python/converters/test_circuit_to_instruction.py index e3239d4b5ff4..505e3d93bdb7 100644 --- a/test/python/converters/test_circuit_to_instruction.py +++ b/test/python/converters/test_circuit_to_instruction.py @@ -56,12 +56,16 @@ def test_flatten_registers_of_circuit_single_bit_cond(self): cr1 = ClassicalRegister(3, "cr1") cr2 = ClassicalRegister(3, "cr2") circ = QuantumCircuit(qr1, qr2, cr1, cr2) - circ.h(qr1[0]).c_if(cr1[1], True) - circ.h(qr2[1]).c_if(cr2[0], False) - circ.cx(qr1[1], qr2[2]).c_if(cr2[2], True) + with self.assertWarns(DeprecationWarning): + circ.h(qr1[0]).c_if(cr1[1], True) + with self.assertWarns(DeprecationWarning): + circ.h(qr2[1]).c_if(cr2[0], False) + with self.assertWarns(DeprecationWarning): + circ.cx(qr1[1], qr2[2]).c_if(cr2[2], True) circ.measure(qr2[2], cr2[0]) - inst = circuit_to_instruction(circ) + with self.assertWarns(DeprecationWarning): + inst = circuit_to_instruction(circ) q = QuantumRegister(5, "q") c = ClassicalRegister(6, "c") @@ -196,8 +200,10 @@ def test_registerless_classical_bits(self): Regression test of gh-7394.""" expected = QuantumCircuit([Qubit(), Clbit()]) - expected.h(0).c_if(expected.clbits[0], 0) - test = circuit_to_instruction(expected) + with self.assertWarns(DeprecationWarning): + expected.h(0).c_if(expected.clbits[0], 0) + with self.assertWarns(DeprecationWarning): + test = circuit_to_instruction(expected) self.assertIsInstance(test, Instruction) self.assertIsInstance(test.definition, QuantumCircuit) diff --git a/test/python/converters/test_dag_to_dagdependency.py b/test/python/converters/test_dag_to_dagdependency.py index 6b52652e6ace..b4a66659245b 100644 --- a/test/python/converters/test_dag_to_dagdependency.py +++ b/test/python/converters/test_dag_to_dagdependency.py @@ -34,7 +34,8 @@ def test_circuit_and_dag_dependency(self): circuit_in.h(qr[1]) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) - circuit_in.x(qr[0]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_in.x(qr[0]).c_if(cr, 0x3) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) circuit_in.measure(qr[2], cr[2]) @@ -55,7 +56,8 @@ def test_circuit_and_dag_dependency2(self): circuit_in.h(qr[1]) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) - circuit_in.x(qr[0]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_in.x(qr[0]).c_if(cr, 0x3) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) circuit_in.measure(qr[2], cr[2]) diff --git a/test/python/converters/test_dag_to_dagdependency_v2.py b/test/python/converters/test_dag_to_dagdependency_v2.py index 925bf442f477..951e31835fe9 100644 --- a/test/python/converters/test_dag_to_dagdependency_v2.py +++ b/test/python/converters/test_dag_to_dagdependency_v2.py @@ -34,7 +34,8 @@ def test_circuit_and_dag_dependency(self): circuit_in.h(qr[1]) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) - circuit_in.x(qr[0]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_in.x(qr[0]).c_if(cr, 0x3) circuit_in.measure(qr[0], cr[0]) circuit_in.measure(qr[1], cr[1]) circuit_in.measure(qr[2], cr[2]) diff --git a/test/python/dagcircuit/test_collect_blocks.py b/test/python/dagcircuit/test_collect_blocks.py index b2715078d7f5..4650a7203c22 100644 --- a/test/python/dagcircuit/test_collect_blocks.py +++ b/test/python/dagcircuit/test_collect_blocks.py @@ -243,7 +243,8 @@ def test_circuit_has_conditional_gates(self): qc.x(0) qc.x(1) qc.cx(1, 0) - qc.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 1) qc.x(0) qc.x(1) qc.cx(0, 1) @@ -280,7 +281,8 @@ def test_circuit_has_conditional_gates_dagdependency(self): qc.x(0) qc.x(1) qc.cx(1, 0) - qc.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 1) qc.x(0) qc.x(1) qc.cx(0, 1) @@ -544,11 +546,13 @@ def test_collect_blocks_with_clbits(self): condition.""" qc = QuantumCircuit(4, 3) - qc.cx(0, 1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(0, 1) qc.cx(2, 3) qc.cx(1, 2) qc.cx(0, 1) - qc.cx(2, 3).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(2, 3).c_if(1, 0) dag = circuit_to_dag(qc) @@ -567,7 +571,8 @@ def _collapse_fn(circuit): return op # Collapse block with measures into a single "COLLAPSED" block - dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) + with self.assertWarns(DeprecationWarning): + dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) collapsed_qc = dag_to_circuit(dag) self.assertEqual(len(collapsed_qc.data), 1) @@ -580,11 +585,13 @@ def test_collect_blocks_with_clbits_dagdependency(self): under conditions, using DAGDependency.""" qc = QuantumCircuit(4, 3) - qc.cx(0, 1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(0, 1) qc.cx(2, 3) qc.cx(1, 2) qc.cx(0, 1) - qc.cx(2, 3).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(2, 3).c_if(1, 0) dag = circuit_to_dagdependency(qc) @@ -603,7 +610,8 @@ def _collapse_fn(circuit): return op # Collapse block with measures into a single "COLLAPSED" block - dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) + with self.assertWarns(DeprecationWarning): + dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) collapsed_qc = dagdependency_to_circuit(dag) self.assertEqual(len(collapsed_qc.data), 1) @@ -620,10 +628,13 @@ def test_collect_blocks_with_clbits2(self): cbit = Clbit() qc = QuantumCircuit(qreg, creg, [cbit]) - qc.cx(0, 1).c_if(creg[1], 1) - qc.cx(2, 3).c_if(cbit, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg[1], 1) + with self.assertWarns(DeprecationWarning): + qc.cx(2, 3).c_if(cbit, 0) qc.cx(1, 2) - qc.cx(0, 1).c_if(creg[2], 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg[2], 1) dag = circuit_to_dag(qc) @@ -642,7 +653,8 @@ def _collapse_fn(circuit): return op # Collapse block with measures into a single "COLLAPSED" block - dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) + with self.assertWarns(DeprecationWarning): + dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) collapsed_qc = dag_to_circuit(dag) self.assertEqual(len(collapsed_qc.data), 1) @@ -659,10 +671,13 @@ def test_collect_blocks_with_clbits2_dagdependency(self): cbit = Clbit() qc = QuantumCircuit(qreg, creg, [cbit]) - qc.cx(0, 1).c_if(creg[1], 1) - qc.cx(2, 3).c_if(cbit, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg[1], 1) + with self.assertWarns(DeprecationWarning): + qc.cx(2, 3).c_if(cbit, 0) qc.cx(1, 2) - qc.cx(0, 1).c_if(creg[2], 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg[2], 1) dag = circuit_to_dag(qc) @@ -681,7 +696,8 @@ def _collapse_fn(circuit): return op # Collapse block with measures into a single "COLLAPSED" block - dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) + with self.assertWarns(DeprecationWarning): + dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) collapsed_qc = dag_to_circuit(dag) self.assertEqual(len(collapsed_qc.data), 1) @@ -698,9 +714,11 @@ def test_collect_blocks_with_cregs(self): creg2 = ClassicalRegister(2, "cr2") qc = QuantumCircuit(qreg, creg, creg2) - qc.cx(0, 1).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg, 3) qc.cx(1, 2) - qc.cx(0, 1).c_if(creg[2], 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg[2], 1) dag = circuit_to_dag(qc) @@ -719,7 +737,8 @@ def _collapse_fn(circuit): return op # Collapse block with measures into a single "COLLAPSED" block - dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) + with self.assertWarns(DeprecationWarning): + dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) collapsed_qc = dag_to_circuit(dag) self.assertEqual(len(collapsed_qc.data), 1) @@ -737,9 +756,11 @@ def test_collect_blocks_with_cregs_dagdependency(self): creg2 = ClassicalRegister(2, "cr2") qc = QuantumCircuit(qreg, creg, creg2) - qc.cx(0, 1).c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg, 3) qc.cx(1, 2) - qc.cx(0, 1).c_if(creg[2], 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(creg[2], 1) dag = circuit_to_dagdependency(qc) @@ -758,7 +779,8 @@ def _collapse_fn(circuit): return op # Collapse block with measures into a single "COLLAPSED" block - dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) + with self.assertWarns(DeprecationWarning): + dag = BlockCollapser(dag).collapse_to_operation(blocks, _collapse_fn) collapsed_qc = dagdependency_to_circuit(dag) self.assertEqual(len(collapsed_qc.data), 1) @@ -917,14 +939,19 @@ def test_split_layers_dagdependency(self): def test_block_collapser_register_condition(self): """Test that BlockCollapser can handle a register being used more than once.""" qc = QuantumCircuit(1, 2) - qc.x(0).c_if(qc.cregs[0], 0) - qc.y(0).c_if(qc.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(qc.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + qc.y(0).c_if(qc.cregs[0], 1) dag = circuit_to_dag(qc) blocks = BlockCollector(dag).collect_all_matching_blocks( lambda _: True, split_blocks=False, min_block_size=1 ) - dag = BlockCollapser(dag).collapse_to_operation(blocks, lambda circ: circ.to_instruction()) + with self.assertWarns(DeprecationWarning): + dag = BlockCollapser(dag).collapse_to_operation( + blocks, lambda circ: circ.to_instruction() + ) collapsed_qc = dag_to_circuit(dag) self.assertEqual(len(collapsed_qc.data), 1) diff --git a/test/python/dagcircuit/test_compose.py b/test/python/dagcircuit/test_compose.py index ff5014eacef7..82246b306f47 100644 --- a/test/python/dagcircuit/test_compose.py +++ b/test/python/dagcircuit/test_compose.py @@ -321,8 +321,10 @@ def test_compose_conditional(self): creg = ClassicalRegister(2, "rcr") circuit_right = QuantumCircuit(qreg, creg) - circuit_right.x(qreg[1]).c_if(creg, 2) - circuit_right.h(qreg[0]).c_if(creg, 1) + with self.assertWarns(DeprecationWarning): + circuit_right.x(qreg[1]).c_if(creg, 2) + with self.assertWarns(DeprecationWarning): + circuit_right.h(qreg[0]).c_if(creg, 1) circuit_right.measure(qreg, creg) # permuted subset of qubits and clbits @@ -330,16 +332,19 @@ def test_compose_conditional(self): dag_right = circuit_to_dag(circuit_right) # permuted subset of qubits and clbits - dag_left.compose( - dag_right, - qubits=[self.left_qubit1, self.left_qubit4], - clbits=[self.left_clbit1, self.left_clbit0], - ) + with self.assertWarns(DeprecationWarning): + dag_left.compose( + dag_right, + qubits=[self.left_qubit1, self.left_qubit4], + clbits=[self.left_clbit1, self.left_clbit0], + ) circuit_composed = dag_to_circuit(dag_left) circuit_expected = self.circuit_left.copy() - circuit_expected.x(self.left_qubit4).c_if(*self.condition1) - circuit_expected.h(self.left_qubit1).c_if(*self.condition2) + with self.assertWarns(DeprecationWarning): + circuit_expected.x(self.left_qubit4).c_if(*self.condition1) + with self.assertWarns(DeprecationWarning): + circuit_expected.h(self.left_qubit1).c_if(*self.condition2) circuit_expected.measure(self.left_qubit4, self.left_clbit0) circuit_expected.measure(self.left_qubit1, self.left_clbit1) @@ -423,12 +428,13 @@ def test_compose_condition_multiple_classical(self): circuit_left = QuantumCircuit(qreg, creg1, creg2) circuit_right = QuantumCircuit(qreg, creg1, creg2) - circuit_right.h(0).c_if(creg1, 1) + with self.assertWarns(DeprecationWarning): + circuit_right.h(0).c_if(creg1, 1) dag_left = circuit_to_dag(circuit_left) dag_right = circuit_to_dag(circuit_right) - - dag_composed = dag_left.compose(dag_right, qubits=[0], clbits=[0, 1], inplace=False) + with self.assertWarns(DeprecationWarning): + dag_composed = dag_left.compose(dag_right, qubits=[0], clbits=[0, 1], inplace=False) dag_expected = circuit_to_dag(circuit_right.copy()) diff --git a/test/python/dagcircuit/test_dagcircuit.py b/test/python/dagcircuit/test_dagcircuit.py index ef8050961066..10a0ebf06fd6 100644 --- a/test/python/dagcircuit/test_dagcircuit.py +++ b/test/python/dagcircuit/test_dagcircuit.py @@ -561,7 +561,8 @@ def setUp(self): def test_apply_operation_back(self): """The apply_operation_back() method.""" - x_gate = XGate().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + x_gate = XGate().c_if(*self.condition) self.dag.apply_operation_back(HGate(), [self.qubit0], []) self.dag.apply_operation_back(CXGate(), [self.qubit0, self.qubit1], []) self.dag.apply_operation_back(Measure(), [self.qubit1], [self.clbit1]) @@ -573,7 +574,8 @@ def test_apply_operation_back(self): def test_edges(self): """Test that DAGCircuit.edges() behaves as expected with ops.""" - x_gate = XGate().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + x_gate = XGate().c_if(*self.condition) self.dag.apply_operation_back(HGate(), [self.qubit0], []) self.dag.apply_operation_back(CXGate(), [self.qubit0, self.qubit1], []) self.dag.apply_operation_back(Measure(), [self.qubit1], [self.clbit1]) @@ -590,8 +592,8 @@ def test_apply_operation_back_conditional(self): """Test consistency of apply_operation_back with condition set.""" # Single qubit gate conditional: qc.h(qr[2]).c_if(cr, 3) - - h_gate = HGate().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + h_gate = HGate().c_if(*self.condition) h_node = self.dag.apply_operation_back(h_gate, [self.qubit2], []) self.assertEqual(h_node.qargs, (self.qubit2,)) @@ -630,8 +632,8 @@ def test_apply_operation_back_conditional_measure(self): new_creg = ClassicalRegister(1, "cr2") self.dag.add_creg(new_creg) - - meas_gate = Measure().c_if(new_creg, 0) + with self.assertWarns(DeprecationWarning): + meas_gate = Measure().c_if(new_creg, 0) meas_node = self.dag.apply_operation_back(meas_gate, [self.qubit0], [self.clbit0]) self.assertEqual(meas_node.qargs, (self.qubit0,)) @@ -675,8 +677,8 @@ def test_apply_operation_back_conditional_measure_to_self(self): # Measure targeting a clbit which _is_ a member of the conditional # register. qc.measure(qr[0], cr[0]).c_if(cr, 3) - - meas_gate = Measure().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + meas_gate = Measure().c_if(*self.condition) meas_node = self.dag.apply_operation_back(meas_gate, [self.qubit1], [self.clbit1]) self.assertEqual(meas_node.qargs, (self.qubit1,)) @@ -1239,7 +1241,8 @@ def test_dag_collect_runs(self): def test_dag_collect_runs_start_with_conditional(self): """Test collect runs with a conditional at the start of the run.""" - h_gate = HGate().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + h_gate = HGate().c_if(*self.condition) self.dag.apply_operation_back(h_gate, [self.qubit0]) self.dag.apply_operation_back(HGate(), [self.qubit0]) self.dag.apply_operation_back(HGate(), [self.qubit0]) @@ -1252,7 +1255,8 @@ def test_dag_collect_runs_start_with_conditional(self): def test_dag_collect_runs_conditional_in_middle(self): """Test collect_runs with a conditional in the middle of a run.""" - h_gate = HGate().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + h_gate = HGate().c_if(*self.condition) self.dag.apply_operation_back(HGate(), [self.qubit0]) self.dag.apply_operation_back(h_gate, [self.qubit0]) self.dag.apply_operation_back(HGate(), [self.qubit0]) @@ -1294,7 +1298,8 @@ def test_dag_collect_1q_runs_start_with_conditional(self): """Test collect 1q runs with a conditional at the start of the run.""" self.dag.apply_operation_back(Reset(), [self.qubit0]) self.dag.apply_operation_back(Delay(100), [self.qubit0]) - h_gate = HGate().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + h_gate = HGate().c_if(*self.condition) self.dag.apply_operation_back(h_gate, [self.qubit0]) self.dag.apply_operation_back(HGate(), [self.qubit0]) self.dag.apply_operation_back(HGate(), [self.qubit0]) @@ -1309,7 +1314,8 @@ def test_dag_collect_1q_runs_conditional_in_middle(self): """Test collect_1q_runs with a conditional in the middle of a run.""" self.dag.apply_operation_back(Reset(), [self.qubit0]) self.dag.apply_operation_back(Delay(100), [self.qubit0]) - h_gate = HGate().c_if(*self.condition) + with self.assertWarns(DeprecationWarning): + h_gate = HGate().c_if(*self.condition) self.dag.apply_operation_back(HGate(), [self.qubit0]) self.dag.apply_operation_back(h_gate, [self.qubit0]) self.dag.apply_operation_back(HGate(), [self.qubit0]) @@ -1387,7 +1393,8 @@ def test_layers_basic(self): qubit1 = qreg[1] clbit0 = creg[0] clbit1 = creg[1] - x_gate = XGate().c_if(creg, 3) + with self.assertWarns(DeprecationWarning): + x_gate = XGate().c_if(creg, 3) dag = DAGCircuit() dag.add_qreg(qreg) dag.add_creg(creg) @@ -1856,29 +1863,41 @@ def test_semantic_conditions(self): qreg = QuantumRegister(1, name="q") creg = ClassicalRegister(1, name="c") qc1 = QuantumCircuit(qreg, creg, [Clbit()]) - qc1.x(0).c_if(qc1.cregs[0], 1) - qc1.x(0).c_if(qc1.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.clbits[-1], True) qc2 = QuantumCircuit(qreg, creg, [Clbit()]) - qc2.x(0).c_if(qc2.cregs[0], 1) - qc2.x(0).c_if(qc2.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.clbits[-1], True) self.assertEqual(circuit_to_dag(qc1), circuit_to_dag(qc2)) # Order of operations transposed. qc1 = QuantumCircuit(qreg, creg, [Clbit()]) - qc1.x(0).c_if(qc1.cregs[0], 1) - qc1.x(0).c_if(qc1.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.clbits[-1], True) qc2 = QuantumCircuit(qreg, creg, [Clbit()]) - qc2.x(0).c_if(qc2.clbits[-1], True) - qc2.x(0).c_if(qc2.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.cregs[0], 1) self.assertNotEqual(circuit_to_dag(qc1), circuit_to_dag(qc2)) # Single-bit condition values not the same. qc1 = QuantumCircuit(qreg, creg, [Clbit()]) - qc1.x(0).c_if(qc1.cregs[0], 1) - qc1.x(0).c_if(qc1.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc1.x(0).c_if(qc1.clbits[-1], True) qc2 = QuantumCircuit(qreg, creg, [Clbit()]) - qc2.x(0).c_if(qc2.cregs[0], 1) - qc2.x(0).c_if(qc2.clbits[-1], False) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc2.x(0).c_if(qc2.clbits[-1], False) self.assertNotEqual(circuit_to_dag(qc1), circuit_to_dag(qc2)) def test_semantic_expr(self): @@ -2489,7 +2508,8 @@ def test_substitute_without_propagating_bit_conditional(self): sub = QuantumCircuit(2, 1) sub.h(0) - sub.cx(0, 1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + sub.cx(0, 1).c_if(0, True) sub.h(0) expected = DAGCircuit() @@ -2522,7 +2542,8 @@ def test_substitute_without_propagating_register_conditional(self): sub = QuantumCircuit(QuantumRegister(2), ClassicalRegister(2)) sub.h(0) - sub.cx(0, 1).c_if(sub.cregs[0], 3) + with self.assertWarns(DeprecationWarning): + sub.cx(0, 1).c_if(sub.cregs[0], 3) sub.h(0) expected = DAGCircuit() @@ -2559,8 +2580,10 @@ def test_substitute_with_provided_wire_map_propagate_condition(self): sub.cx(0, 1) sub.h(0) - conditioned_h = HGate().c_if(*conditioned_cz.condition) - conditioned_cx = CXGate().c_if(*conditioned_cz.condition) + with self.assertWarns(DeprecationWarning): + conditioned_h = HGate().c_if(*conditioned_cz.condition) + with self.assertWarns(DeprecationWarning): + conditioned_cx = CXGate().c_if(*conditioned_cz.condition) expected = DAGCircuit() expected.add_qubits(base_qubits) @@ -2593,7 +2616,8 @@ def test_substitute_with_provided_wire_map_no_propagate_condition(self): sub = QuantumCircuit(2, 1) sub.h(0) - sub.cx(0, 1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + sub.cx(0, 1).c_if(0, True) sub.h(0) conditioned_cx = CXGate().to_mutable() @@ -2626,7 +2650,8 @@ def test_creates_additional_alias_register(self): target = base.apply_operation_back(Instruction("dummy", 2, 2, []), base_qreg, base_creg[:2]) sub = QuantumCircuit(QuantumRegister(2), ClassicalRegister(2)) - sub.cx(0, 1).c_if(sub.cregs[0], 3) + with self.assertWarns(DeprecationWarning): + sub.cx(0, 1).c_if(sub.cregs[0], 3) base.substitute_node_with_dag(target, circuit_to_dag(sub)) @@ -2731,12 +2756,14 @@ def test_refuses_to_overwrite_condition(self, inplace): dag = DAGCircuit() dag.add_qreg(qr) dag.add_creg(cr) - node = dag.apply_operation_back(XGate().c_if(cr, 2), qr, []) + with self.assertWarns(DeprecationWarning): + node = dag.apply_operation_back(XGate().c_if(cr, 2), qr, []) with self.assertRaisesRegex(DAGCircuitError, "Cannot propagate a condition"): - dag.substitute_node( - node, XGate().c_if(cr, 1), inplace=inplace, propagate_condition=True - ) + with self.assertWarns(DeprecationWarning): + dag.substitute_node( + node, XGate().c_if(cr, 1), inplace=inplace, propagate_condition=True + ) @data(True, False) def test_replace_if_else_op_with_another(self, inplace): @@ -3194,7 +3221,8 @@ def setUp(self): def test_creg_conditional(self): """Test consistency of conditional on classical register.""" - self.circuit.h(self.qreg[0]).c_if(self.creg, 1) + with self.assertWarns(DeprecationWarning): + self.circuit.h(self.qreg[0]).c_if(self.creg, 1) self.dag = circuit_to_dag(self.circuit) gate_node = self.dag.gate_nodes()[0] self.assertEqual(gate_node.op, HGate()) @@ -3235,8 +3263,8 @@ def test_creg_conditional(self): def test_clbit_conditional(self): """Test consistency of conditional on single classical bit.""" - - self.circuit.h(self.qreg[0]).c_if(self.creg[0], 1) + with self.assertWarns(DeprecationWarning): + self.circuit.h(self.qreg[0]).c_if(self.creg[0], 1) self.dag = circuit_to_dag(self.circuit) gate_node = self.dag.gate_nodes()[0] self.assertEqual(gate_node.op, HGate()) diff --git a/test/python/primitives/test_backend_sampler_v2.py b/test/python/primitives/test_backend_sampler_v2.py index 372ae3a6715c..22c4b8d5d684 100644 --- a/test/python/primitives/test_backend_sampler_v2.py +++ b/test/python/primitives/test_backend_sampler_v2.py @@ -1215,8 +1215,10 @@ def test_circuit_with_aliased_cregs(self, backend): qc.h(0) qc.measure(0, c1) qc.measure(1, c2) - qc.z(2).c_if(c1, 1) - qc.x(2).c_if(c2, 1) + with self.assertWarns(DeprecationWarning): + qc.z(2).c_if(c1, 1) + with self.assertWarns(DeprecationWarning): + qc.x(2).c_if(c2, 1) qc2 = QuantumCircuit(5, 5) qc2.compose(qc, [0, 2, 3], [2, 4], inplace=True) cregs = [creg.name for creg in qc2.cregs] @@ -1251,8 +1253,10 @@ def test_circuit_with_aliased_cregs_v1(self, backend): qc.h(0) qc.measure(0, c1) qc.measure(1, c2) - qc.z(2).c_if(c1, 1) - qc.x(2).c_if(c2, 1) + with self.assertWarns(DeprecationWarning): + qc.z(2).c_if(c1, 1) + with self.assertWarns(DeprecationWarning): + qc.x(2).c_if(c2, 1) qc2 = QuantumCircuit(5, 5) qc2.compose(qc, [0, 2, 3], [2, 4], inplace=True) cregs = [creg.name for creg in qc2.cregs] diff --git a/test/python/primitives/test_primitive.py b/test/python/primitives/test_primitive.py index fb96081fa001..dfca63a5d4b8 100644 --- a/test/python/primitives/test_primitive.py +++ b/test/python/primitives/test_primitive.py @@ -159,7 +159,8 @@ def test_circuit_key_controlflow(self): qc.h(0) qc.cx(0, 1) qc.measure(0, 0) - qc.break_loop().c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.break_loop().c_if(0, True) self.assertIsInstance(hash(_circuit_key(qc)), int) self.assertIsInstance(json.dumps(_circuit_key(qc)), str) diff --git a/test/python/primitives/test_statevector_sampler.py b/test/python/primitives/test_statevector_sampler.py index a782aafaeaf5..3af4e8d9f688 100644 --- a/test/python/primitives/test_statevector_sampler.py +++ b/test/python/primitives/test_statevector_sampler.py @@ -283,7 +283,8 @@ def test_run_errors(self): qc4 = QuantumCircuit(2, 2) qc4.h(0) qc4.measure(1, 1) - qc4.x(0).c_if(1, 1) + with self.assertWarns(DeprecationWarning): + qc4.x(0).c_if(1, 1) qc4.measure(0, 0) sampler = StatevectorSampler() @@ -592,8 +593,10 @@ def test_circuit_with_aliased_cregs(self): c2 = ClassicalRegister(1, "c2") qc = QuantumCircuit(q, c1, c2) - qc.z(2).c_if(c1, 1) - qc.x(2).c_if(c2, 1) + with self.assertWarns(DeprecationWarning): + qc.z(2).c_if(c1, 1) + with self.assertWarns(DeprecationWarning): + qc.x(2).c_if(c2, 1) qc2 = QuantumCircuit(5, 5) qc2.compose(qc, [0, 2, 3], [2, 4], inplace=True) # Note: qc2 has aliased cregs, c0 -> c[2] and c1 -> c[4]. diff --git a/test/python/providers/basic_provider/test_basic_simulator.py b/test/python/providers/basic_provider/test_basic_simulator.py index 57dd67dfd3c3..925823b49300 100644 --- a/test/python/providers/basic_provider/test_basic_simulator.py +++ b/test/python/providers/basic_provider/test_basic_simulator.py @@ -174,7 +174,8 @@ def test_if_statement(self): circuit_if_true.x(qr[1]) circuit_if_true.measure(qr[0], cr[0]) circuit_if_true.measure(qr[1], cr[1]) - circuit_if_true.x(qr[2]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_if_true.x(qr[2]).c_if(cr, 0x3) circuit_if_true.measure(qr[0], cr[0]) circuit_if_true.measure(qr[1], cr[1]) circuit_if_true.measure(qr[2], cr[2]) @@ -193,7 +194,8 @@ def test_if_statement(self): circuit_if_false.x(qr[0]) circuit_if_false.measure(qr[0], cr[0]) circuit_if_false.measure(qr[1], cr[1]) - circuit_if_false.x(qr[2]).c_if(cr, 0x3) + with self.assertWarns(DeprecationWarning): + circuit_if_false.x(qr[2]).c_if(cr, 0x3) circuit_if_false.measure(qr[0], cr[0]) circuit_if_false.measure(qr[1], cr[1]) circuit_if_false.measure(qr[2], cr[2]) @@ -230,7 +232,8 @@ def test_bit_cif_crossaffect(self): circuit.x([qr[1], qr[2]]) circuit.measure(qr[1], cr[1]) circuit.measure(qr[2], cr[2]) - circuit.h(qr[0]).c_if(cr[0], True) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr[0], True) circuit.measure(qr[0], cr1[0]) job = self.backend.run(circuit, shots=shots, seed_simulator=self.seed) result = job.result().get_counts() @@ -269,8 +272,10 @@ def test_teleport(self): circuit.barrier(qr) circuit.measure(qr[0], cr0[0]) circuit.measure(qr[1], cr1[0]) - circuit.z(qr[2]).c_if(cr0, 1) - circuit.x(qr[2]).c_if(cr1, 1) + with self.assertWarns(DeprecationWarning): + circuit.z(qr[2]).c_if(cr0, 1) + with self.assertWarns(DeprecationWarning): + circuit.x(qr[2]).c_if(cr1, 1) circuit.measure(qr[2], cr2[0]) job = self.backend.run( transpile(circuit, self.backend), shots=shots, seed_simulator=self.seed diff --git a/test/python/qasm2/test_arxiv_examples.py b/test/python/qasm2/test_arxiv_examples.py index 197b842697e1..64df2ac2598b 100644 --- a/test/python/qasm2/test_arxiv_examples.py +++ b/test/python/qasm2/test_arxiv_examples.py @@ -72,7 +72,8 @@ def test_teleportation(self, parser): if(c1==1) x q[2]; post q[2]; measure q[2] -> c2[0];""" - parsed = parser(example) + with self.assertWarns(DeprecationWarning): + parsed = parser(example) post = gate_builder("post", [], QuantumCircuit([Qubit()])) @@ -90,8 +91,10 @@ def test_teleportation(self, parser): qc.h(q[0]) qc.measure(q[0], c0[0]) qc.measure(q[1], c1[0]) - qc.z(q[2]).c_if(c0, 1) - qc.x(q[2]).c_if(c1, 1) + with self.assertWarns(DeprecationWarning): + qc.z(q[2]).c_if(c0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(q[2]).c_if(c1, 1) qc.append(post(), [q[2]], []) qc.measure(q[2], c2[0]) @@ -119,7 +122,8 @@ def test_qft(self, parser): cu1(pi/2) q[3],q[2]; h q[3]; measure q -> c;""" - parsed = parser(example) + with self.assertWarns(DeprecationWarning): + parsed = parser(example) qc = QuantumCircuit(QuantumRegister(4, "q"), ClassicalRegister(4, "c")) qc.x(0) @@ -168,7 +172,8 @@ def test_inverse_qft_1(self, parser): if(c==7) u1(pi/2+pi/4+pi/8) q[3]; h q[3]; measure q[3] -> c[3];""" - parsed = parser(example) + with self.assertWarns(DeprecationWarning): + parsed = parser(example) q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") @@ -177,21 +182,32 @@ def test_inverse_qft_1(self, parser): qc.barrier(q) qc.h(q[0]) qc.measure(q[0], c[0]) - qc.append(U1Gate(math.pi / 2).c_if(c, 1), [q[1]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 2).c_if(c, 1), [q[1]]) qc.h(q[1]) qc.measure(q[1], c[1]) - qc.append(U1Gate(math.pi / 4).c_if(c, 1), [q[2]]) - qc.append(U1Gate(math.pi / 2).c_if(c, 2), [q[2]]) - qc.append(U1Gate(math.pi / 4 + math.pi / 2).c_if(c, 3), [q[2]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 4).c_if(c, 1), [q[2]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 2).c_if(c, 2), [q[2]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 4 + math.pi / 2).c_if(c, 3), [q[2]]) qc.h(q[2]) qc.measure(q[2], c[2]) - qc.append(U1Gate(math.pi / 8).c_if(c, 1), [q[3]]) - qc.append(U1Gate(math.pi / 4).c_if(c, 2), [q[3]]) - qc.append(U1Gate(math.pi / 8 + math.pi / 4).c_if(c, 3), [q[3]]) - qc.append(U1Gate(math.pi / 2).c_if(c, 4), [q[3]]) - qc.append(U1Gate(math.pi / 8 + math.pi / 2).c_if(c, 5), [q[3]]) - qc.append(U1Gate(math.pi / 4 + math.pi / 2).c_if(c, 6), [q[3]]) - qc.append(U1Gate(math.pi / 8 + math.pi / 4 + math.pi / 2).c_if(c, 7), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 8).c_if(c, 1), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 4).c_if(c, 2), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 8 + math.pi / 4).c_if(c, 3), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 2).c_if(c, 4), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 8 + math.pi / 2).c_if(c, 5), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 4 + math.pi / 2).c_if(c, 6), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 8 + math.pi / 4 + math.pi / 2).c_if(c, 7), [q[3]]) qc.h(q[3]) qc.measure(q[3], c[3]) @@ -224,7 +240,8 @@ def test_inverse_qft_2(self, parser): if(c2==1) u1(pi/2) q[3]; h q[3]; measure q[3] -> c3[0];""" - parsed = parser(example) + with self.assertWarns(DeprecationWarning): + parsed = parser(example) q = QuantumRegister(4, "q") c0 = ClassicalRegister(1, "c0") @@ -236,16 +253,22 @@ def test_inverse_qft_2(self, parser): qc.barrier(q) qc.h(q[0]) qc.measure(q[0], c0[0]) - qc.append(U1Gate(math.pi / 2).c_if(c0, 1), [q[1]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 2).c_if(c0, 1), [q[1]]) qc.h(q[1]) qc.measure(q[1], c1[0]) - qc.append(U1Gate(math.pi / 4).c_if(c0, 1), [q[2]]) - qc.append(U1Gate(math.pi / 2).c_if(c1, 1), [q[2]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 4).c_if(c0, 1), [q[2]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 2).c_if(c1, 1), [q[2]]) qc.h(q[2]) qc.measure(q[2], c2[0]) - qc.append(U1Gate(math.pi / 8).c_if(c0, 1), [q[3]]) - qc.append(U1Gate(math.pi / 4).c_if(c1, 1), [q[3]]) - qc.append(U1Gate(math.pi / 2).c_if(c2, 1), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 8).c_if(c0, 1), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 4).c_if(c1, 1), [q[3]]) + with self.assertWarns(DeprecationWarning): + qc.append(U1Gate(math.pi / 2).c_if(c2, 1), [q[3]]) qc.h(q[3]) qc.measure(q[3], c3[0]) @@ -292,7 +315,8 @@ def test_ripple_carry_adder(self, parser): measure b[2] -> ans[2]; measure b[3] -> ans[3]; measure cout[0] -> ans[4];""" - parsed = parser(example) + with self.assertWarns(DeprecationWarning): + parsed = parser(example) majority_definition = QuantumCircuit([Qubit(), Qubit(), Qubit()]) majority_definition.cx(2, 1) @@ -423,7 +447,8 @@ def test_error_correction(self, parser): if(syn==2) x q[2]; if(syn==3) x q[1]; measure q -> c;""" - parsed = parser(example) + with self.assertWarns(DeprecationWarning): + parsed = parser(example) syndrome_definition = QuantumCircuit([Qubit() for _ in [None] * 5]) syndrome_definition.cx(0, 3) @@ -442,9 +467,12 @@ def test_error_correction(self, parser): qc.barrier(q) qc.append(syndrome(), [q[0], q[1], q[2], a[0], a[1]]) qc.measure(a, syn) - qc.x(q[0]).c_if(syn, 1) - qc.x(q[2]).c_if(syn, 2) - qc.x(q[1]).c_if(syn, 3) + with self.assertWarns(DeprecationWarning): + qc.x(q[0]).c_if(syn, 1) + with self.assertWarns(DeprecationWarning): + qc.x(q[2]).c_if(syn, 2) + with self.assertWarns(DeprecationWarning): + qc.x(q[1]).c_if(syn, 3) qc.measure(q, c) self.assertEqual(parsed, qc) diff --git a/test/python/qasm2/test_circuit_methods.py b/test/python/qasm2/test_circuit_methods.py index 1ba9689ab3ef..d5fa814f7c52 100644 --- a/test/python/qasm2/test_circuit_methods.py +++ b/test/python/qasm2/test_circuit_methods.py @@ -180,14 +180,16 @@ def test_qasm_text_conditional(self): ) + "\n" ) - q_circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + q_circuit = QuantumCircuit.from_qasm_str(qasm_string) qr = QuantumRegister(1, "q") cr0 = ClassicalRegister(4, "c0") cr1 = ClassicalRegister(4, "c1") ref = QuantumCircuit(qr, cr0, cr1) ref.x(qr[0]) - ref.x(qr[0]).c_if(cr1, 4) + with self.assertWarns(DeprecationWarning): + ref.x(qr[0]).c_if(cr1, 4) self.assertEqual(len(q_circuit.cregs), 2) self.assertEqual(len(q_circuit.qregs), 1) diff --git a/test/python/qasm2/test_export.py b/test/python/qasm2/test_export.py index 8de4bb8eb34f..ef6ab8076ef6 100644 --- a/test/python/qasm2/test_export.py +++ b/test/python/qasm2/test_export.py @@ -44,9 +44,12 @@ def test_basic_output(self): qc.barrier(qr2) qc.cx(qr2[1], qr1[0]) qc.h(qr2[1]) - qc.x(qr2[1]).c_if(cr, 0) - qc.y(qr1[0]).c_if(cr, 1) - qc.z(qr1[0]).c_if(cr, 2) + with self.assertWarns(DeprecationWarning): + qc.x(qr2[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.y(qr1[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.z(qr1[0]).c_if(cr, 2) qc.barrier(qr1, qr2) qc.measure(qr1[0], cr[0]) qc.measure(qr2[0], cr[1]) @@ -616,7 +619,8 @@ def test_rotation_angles_close_to_pi(self): def test_raises_on_single_bit_condition(self): qc = QuantumCircuit(1, 1) - qc.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, True) with self.assertRaisesRegex( qasm2.QASM2ExportError, "OpenQASM 2 can only condition on registers" diff --git a/test/python/qasm2/test_structure.py b/test/python/qasm2/test_structure.py index d963eea7e255..ffdfa907659c 100644 --- a/test/python/qasm2/test_structure.py +++ b/test/python/qasm2/test_structure.py @@ -256,11 +256,14 @@ def test_conditioned(self): if (cond == 0) U(0, 0, 0) q[0]; if (cond == 1) CX q[1], q[0]; """ - parsed = qiskit.qasm2.loads(program) + with self.assertWarns(DeprecationWarning): + parsed = qiskit.qasm2.loads(program) cond = ClassicalRegister(1, "cond") qc = QuantumCircuit(QuantumRegister(2, "q"), cond) - qc.u(0, 0, 0, 0).c_if(cond, 0) - qc.cx(1, 0).c_if(cond, 1) + with self.assertWarns(DeprecationWarning): + qc.u(0, 0, 0, 0).c_if(cond, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(1, 0).c_if(cond, 1) self.assertEqual(parsed, qc) def test_conditioned_broadcast(self): @@ -271,15 +274,20 @@ def test_conditioned_broadcast(self): if (cond == 0) U(0, 0, 0) q1; if (cond == 1) CX q1[0], q2; """ - parsed = qiskit.qasm2.loads(program) + with self.assertWarns(DeprecationWarning): + parsed = qiskit.qasm2.loads(program) cond = ClassicalRegister(1, "cond") q1 = QuantumRegister(2, "q1") q2 = QuantumRegister(2, "q2") qc = QuantumCircuit(q1, q2, cond) - qc.u(0, 0, 0, q1[0]).c_if(cond, 0) - qc.u(0, 0, 0, q1[1]).c_if(cond, 0) - qc.cx(q1[0], q2[0]).c_if(cond, 1) - qc.cx(q1[0], q2[1]).c_if(cond, 1) + with self.assertWarns(DeprecationWarning): + qc.u(0, 0, 0, q1[0]).c_if(cond, 0) + with self.assertWarns(DeprecationWarning): + qc.u(0, 0, 0, q1[1]).c_if(cond, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(q1[0], q2[0]).c_if(cond, 1) + with self.assertWarns(DeprecationWarning): + qc.cx(q1[0], q2[1]).c_if(cond, 1) self.assertEqual(parsed, qc) def test_constant_folding(self): @@ -338,19 +346,29 @@ def test_huge_conditions(self): if (cond=={bigint}) measure qr[0] -> cr[0]; if (cond=={bigint}) measure qr -> cr; """ - parsed = qiskit.qasm2.loads(program) + with self.assertWarns(DeprecationWarning): + parsed = qiskit.qasm2.loads(program) qr, cr = QuantumRegister(2, "qr"), ClassicalRegister(2, "cr") cond = ClassicalRegister(500, "cond") qc = QuantumCircuit(qr, cr, cond) - qc.u(0, 0, 0, qr[0]).c_if(cond, bigint) - qc.u(0, 0, 0, qr[0]).c_if(cond, bigint) - qc.u(0, 0, 0, qr[1]).c_if(cond, bigint) - qc.reset(qr[0]).c_if(cond, bigint) - qc.reset(qr[0]).c_if(cond, bigint) - qc.reset(qr[1]).c_if(cond, bigint) - qc.measure(qr[0], cr[0]).c_if(cond, bigint) - qc.measure(qr[0], cr[0]).c_if(cond, bigint) - qc.measure(qr[1], cr[1]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.u(0, 0, 0, qr[0]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.u(0, 0, 0, qr[0]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.u(0, 0, 0, qr[1]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.reset(qr[0]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.reset(qr[0]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.reset(qr[1]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.measure(qr[0], cr[0]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.measure(qr[0], cr[0]).c_if(cond, bigint) + with self.assertWarns(DeprecationWarning): + qc.measure(qr[1], cr[1]).c_if(cond, bigint) self.assertEqual(parsed, qc) @@ -383,14 +401,16 @@ def test_conditioned(self): creg cond[1]; if (cond == 0) not_bell q[0], q[1]; """ - parsed = qiskit.qasm2.loads(program) + with self.assertWarns(DeprecationWarning): + parsed = qiskit.qasm2.loads(program) not_bell_def = QuantumCircuit([Qubit(), Qubit()]) not_bell_def.u(0, 0, 0, 0) not_bell_def.cx(0, 1) not_bell = gate_builder("not_bell", [], not_bell_def) cond = ClassicalRegister(1, "cond") qc = QuantumCircuit(QuantumRegister(2, "q"), cond) - qc.append(not_bell().c_if(cond, 0), [0, 1]) + with self.assertWarns(DeprecationWarning): + qc.append(not_bell().c_if(cond, 0), [0, 1]) self.assertEqual(parsed, qc) def test_constant_folding_in_definition(self): @@ -735,7 +755,8 @@ def test_deepcopy_conditioned_defined_gate(self): creg c[1]; if (c == 1) my_gate q[0]; """ - parsed = qiskit.qasm2.loads(program) + with self.assertWarns(DeprecationWarning): + parsed = qiskit.qasm2.loads(program) my_gate = parsed.data[0].operation self.assertEqual(my_gate.name, "my_gate") @@ -904,12 +925,16 @@ def test_conditioned(self): if (cond == 0) measure q[0] -> c[0]; if (cond == 1) measure q -> c; """ - parsed = qiskit.qasm2.loads(program) + with self.assertWarns(DeprecationWarning): + parsed = qiskit.qasm2.loads(program) cond = ClassicalRegister(1, "cond") qc = QuantumCircuit(QuantumRegister(2, "q"), ClassicalRegister(2, "c"), cond) - qc.measure(0, 0).c_if(cond, 0) - qc.measure(0, 0).c_if(cond, 1) - qc.measure(1, 1).c_if(cond, 1) + with self.assertWarns(DeprecationWarning): + qc.measure(0, 0).c_if(cond, 0) + with self.assertWarns(DeprecationWarning): + qc.measure(0, 0).c_if(cond, 1) + with self.assertWarns(DeprecationWarning): + qc.measure(1, 1).c_if(cond, 1) self.assertEqual(parsed, qc) def test_broadcast_against_empty_register(self): @@ -991,12 +1016,16 @@ def test_conditioned(self): if (cond == 0) reset q[0]; if (cond == 1) reset q; """ - parsed = qiskit.qasm2.loads(program) + with self.assertWarns(DeprecationWarning): + parsed = qiskit.qasm2.loads(program) cond = ClassicalRegister(1, "cond") qc = QuantumCircuit(QuantumRegister(2, "q"), cond) - qc.reset(0).c_if(cond, 0) - qc.reset(0).c_if(cond, 1) - qc.reset(1).c_if(cond, 1) + with self.assertWarns(DeprecationWarning): + qc.reset(0).c_if(cond, 0) + with self.assertWarns(DeprecationWarning): + qc.reset(0).c_if(cond, 1) + with self.assertWarns(DeprecationWarning): + qc.reset(1).c_if(cond, 1) self.assertEqual(parsed, qc) def test_broadcast_against_empty_register(self): diff --git a/test/python/qasm3/test_export.py b/test/python/qasm3/test_export.py index eefc0a2cc53c..acae1d7d3cd7 100644 --- a/test/python/qasm3/test_export.py +++ b/test/python/qasm3/test_export.py @@ -104,9 +104,12 @@ def test_regs_conds_qasm(self): qc.measure(qr1[0], cr[0]) qc.measure(qr2[0], cr[1]) qc.measure(qr2[1], cr[2]) - qc.x(qr2[1]).c_if(cr, 0) - qc.y(qr1[0]).c_if(cr, 1) - qc.z(qr1[0]).c_if(cr, 2) + with self.assertWarns(DeprecationWarning): + qc.x(qr2[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.y(qr1[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.z(qr1[0]).c_if(cr, 2) expected_qasm = "\n".join( [ "OPENQASM 3.0;", @@ -723,8 +726,10 @@ def test_teleportation(self): qc.barrier() qc.measure([0, 1], [0, 1]) qc.barrier() - qc.x(2).c_if(qc.clbits[1], 1) - qc.z(2).c_if(qc.clbits[0], 1) + with self.assertWarns(DeprecationWarning): + qc.x(2).c_if(qc.clbits[1], 1) + with self.assertWarns(DeprecationWarning): + qc.z(2).c_if(qc.clbits[0], 1) transpiled = transpile(qc, initial_layout=[0, 1, 2]) expected_qasm = """\ @@ -780,8 +785,10 @@ def test_basis_gates(self): qc.barrier() qc.measure([0, 1], [0, 1]) qc.barrier() - qc.x(2).c_if(qc.clbits[1], 1) - qc.z(2).c_if(qc.clbits[0], 1) + with self.assertWarns(DeprecationWarning): + qc.x(2).c_if(qc.clbits[1], 1) + with self.assertWarns(DeprecationWarning): + qc.z(2).c_if(qc.clbits[0], 1) transpiled = transpile(qc, initial_layout=[0, 1, 2]) expected_qasm = """\ @@ -2046,11 +2053,15 @@ def test_unusual_conditions(self): qc = QuantumCircuit(3, 2) qc.h(0) qc.measure(0, 0) - qc.measure(1, 1).c_if(0, True) - qc.reset([0, 1]).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.measure(1, 1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.reset([0, 1]).c_if(0, True) with qc.while_loop((qc.clbits[0], True)): - qc.break_loop().c_if(0, True) - qc.continue_loop().c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.break_loop().c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.continue_loop().c_if(0, True) # Terra forbids delay and barrier from being conditioned through `c_if`, but in theory they # should work fine in a dynamic-circuits sense (although what a conditional barrier _means_ # is a whole other kettle of fish). diff --git a/test/python/quantum_info/operators/symplectic/test_clifford.py b/test/python/quantum_info/operators/symplectic/test_clifford.py index e78feaf3b78f..253bc15852b6 100644 --- a/test/python/quantum_info/operators/symplectic/test_clifford.py +++ b/test/python/quantum_info/operators/symplectic/test_clifford.py @@ -387,7 +387,8 @@ def test_barrier_delay_sim(self): def test_from_circuit_with_conditional_gate(self): """Test initialization from circuit with conditional gate.""" qc = QuantumCircuit(2, 1) - qc.h(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.h(0).c_if(0, 0) qc.cx(0, 1) with self.assertRaises(QiskitError): diff --git a/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py b/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py index c95d65422d4b..38b52913160e 100644 --- a/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py +++ b/test/python/transpiler/legacy_scheduling/test_instruction_alignments.py @@ -304,7 +304,8 @@ def test_circuit_using_clbit(self): circuit.x(0) circuit.delay(100, 0, unit="dt") circuit.measure(0, 0) - circuit.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + circuit.x(1).c_if(0, 1) circuit.measure(2, 0) timed_circuit = self.time_conversion_pass(circuit) @@ -320,7 +321,8 @@ def test_circuit_using_clbit(self): ref_circuit.delay(1872, 1, unit="dt") # 2032 - 160 ref_circuit.delay(432, 2, unit="dt") # 2032 - 1600 ref_circuit.measure(0, 0) - ref_circuit.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.x(1).c_if(0, 1) ref_circuit.delay(160, 0, unit="dt") ref_circuit.measure(2, 0) diff --git a/test/python/transpiler/legacy_scheduling/test_scheduling_pass.py b/test/python/transpiler/legacy_scheduling/test_scheduling_pass.py index 417ff9b42212..a13ca2e12de1 100644 --- a/test/python/transpiler/legacy_scheduling/test_scheduling_pass.py +++ b/test/python/transpiler/legacy_scheduling/test_scheduling_pass.py @@ -82,7 +82,8 @@ def test_classically_controlled_gate_after_measure(self, schedule_pass): """ qc = QuantumCircuit(2, 1) qc.measure(0, 0) - qc.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, True) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) with self.assertWarns(DeprecationWarning): @@ -92,7 +93,8 @@ def test_classically_controlled_gate_after_measure(self, schedule_pass): expected = QuantumCircuit(2, 1) expected.measure(0, 0) expected.delay(1000, 1) # x.c_if starts after measure - expected.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, True) expected.delay(200, 0) self.assertEqual(expected, scheduled) @@ -170,8 +172,10 @@ def test_c_if_on_different_qubits(self, schedule_pass): """ qc = QuantumCircuit(3, 1) qc.measure(0, 0) - qc.x(1).c_if(0, True) - qc.x(2).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(2).c_if(0, True) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) with self.assertWarns(DeprecationWarning): @@ -182,8 +186,10 @@ def test_c_if_on_different_qubits(self, schedule_pass): expected.measure(0, 0) expected.delay(1000, 1) expected.delay(1000, 2) - expected.x(1).c_if(0, True) - expected.x(2).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(2).c_if(0, True) expected.delay(200, 0) self.assertEqual(expected, scheduled) @@ -255,7 +261,8 @@ def test_measure_after_c_if(self, schedule_pass): """ qc = QuantumCircuit(3, 1) qc.measure(0, 0) - qc.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 1) qc.measure(2, 0) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) @@ -267,7 +274,8 @@ def test_measure_after_c_if(self, schedule_pass): expected.delay(1000, 1) expected.delay(1000, 2) expected.measure(0, 0) - expected.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, 1) expected.measure(2, 0) expected.delay(1000, 0) expected.delay(800, 1) @@ -451,7 +459,8 @@ def test_measure_after_c_if_on_edge_locking(self): """ qc = QuantumCircuit(3, 1) qc.measure(0, 0) - qc.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 1) qc.measure(2, 0) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) @@ -465,7 +474,8 @@ def test_measure_after_c_if_on_edge_locking(self): expected_asap = QuantumCircuit(3, 1) expected_asap.measure(0, 0) expected_asap.delay(1000, 1) - expected_asap.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_asap.x(1).c_if(0, 1) expected_asap.measure(2, 0) expected_asap.delay(200, 0) expected_asap.delay(200, 2) @@ -474,7 +484,8 @@ def test_measure_after_c_if_on_edge_locking(self): expected_alap = QuantumCircuit(3, 1) expected_alap.measure(0, 0) expected_alap.delay(1000, 1) - expected_alap.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_alap.x(1).c_if(0, 1) expected_alap.delay(200, 2) expected_alap.measure(2, 0) expected_alap.delay(200, 0) @@ -500,11 +511,14 @@ def test_active_reset_circuit(self, write_lat, cond_lat): """ qc = QuantumCircuit(1, 1) qc.measure(0, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) qc.measure(0, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) qc.measure(0, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) durations = InstructionDurations([("x", None, 100), ("measure", None, 1000)]) with self.assertWarns(DeprecationWarning): @@ -519,15 +533,18 @@ def test_active_reset_circuit(self, write_lat, cond_lat): expected.measure(0, 0) if cond_lat > 0: expected.delay(cond_lat, 0) - expected.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, 1) expected.measure(0, 0) if cond_lat > 0: expected.delay(cond_lat, 0) - expected.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, 1) expected.measure(0, 0) if cond_lat > 0: expected.delay(cond_lat, 0) - expected.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, 1) self.assertEqual(expected, actual_asap) self.assertEqual(expected, actual_alap) @@ -616,15 +633,19 @@ def test_random_complicated_circuit(self): """ qc = QuantumCircuit(3, 1) qc.delay(100, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) qc.barrier() qc.measure(2, 0) - qc.x(1).c_if(0, 0) - qc.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 0) qc.delay(300, 0) qc.cx(1, 2) qc.x(0) - qc.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(0, 0) qc.measure(2, 0) durations = InstructionDurations( @@ -644,19 +665,23 @@ def test_random_complicated_circuit(self): expected_asap.delay(100, 0) # due to conditional latency of 200dt expected_asap.delay(300, 1) expected_asap.delay(300, 2) - expected_asap.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_asap.x(0).c_if(0, 1) expected_asap.barrier() expected_asap.delay(1400, 0) expected_asap.delay(1200, 1) expected_asap.measure(2, 0) - expected_asap.x(1).c_if(0, 0) - expected_asap.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_asap.x(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_asap.x(0).c_if(0, 0) expected_asap.delay(300, 0) expected_asap.x(0) expected_asap.delay(300, 2) expected_asap.cx(1, 2) expected_asap.delay(400, 1) - expected_asap.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_asap.cx(0, 1).c_if(0, 0) expected_asap.delay(700, 0) # creg is released at t0 of cx(0,1).c_if(0,0) expected_asap.delay( 700, 1 @@ -671,20 +696,24 @@ def test_random_complicated_circuit(self): expected_alap.delay(100, 0) # due to conditional latency of 200dt expected_alap.delay(300, 1) expected_alap.delay(300, 2) - expected_alap.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_alap.x(0).c_if(0, 1) expected_alap.barrier() expected_alap.delay(1400, 0) expected_alap.delay(1200, 1) expected_alap.measure(2, 0) - expected_alap.x(1).c_if(0, 0) - expected_alap.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_alap.x(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_alap.x(0).c_if(0, 0) expected_alap.delay(300, 0) expected_alap.x(0) expected_alap.delay(300, 1) expected_alap.delay(600, 2) expected_alap.cx(1, 2) expected_alap.delay(100, 1) - expected_alap.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_alap.cx(0, 1).c_if(0, 0) expected_alap.measure(2, 0) expected_alap.delay(700, 0) expected_alap.delay(700, 1) @@ -722,8 +751,10 @@ def test_dag_introduces_extra_dependency_between_conditionals(self): """ qc = QuantumCircuit(2, 1) qc.delay(100, 0) - qc.x(0).c_if(0, True) - qc.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, True) durations = InstructionDurations([("x", None, 160)]) with self.assertWarns(DeprecationWarning): @@ -733,8 +764,10 @@ def test_dag_introduces_extra_dependency_between_conditionals(self): expected = QuantumCircuit(2, 1) expected.delay(100, 0) expected.delay(100, 1) # due to extra dependency on clbits - expected.x(0).c_if(0, True) - expected.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, True) self.assertEqual(expected, scheduled) diff --git a/test/python/transpiler/test_barrier_before_final_measurements.py b/test/python/transpiler/test_barrier_before_final_measurements.py index eb4f509e5301..3aaa5c7895cd 100644 --- a/test/python/transpiler/test_barrier_before_final_measurements.py +++ b/test/python/transpiler/test_barrier_before_final_measurements.py @@ -175,13 +175,15 @@ def test_preserve_measure_for_conditional(self): circuit.h(qr0) circuit.measure(qr0, cr0) - circuit.z(qr1).c_if(cr0, 1) + with self.assertWarns(DeprecationWarning): + circuit.z(qr1).c_if(cr0, 1) circuit.measure(qr1, cr1) expected = QuantumCircuit(qr0, qr1, cr0, cr1) expected.h(qr0) expected.measure(qr0, cr0) - expected.z(qr1).c_if(cr0, 1) + with self.assertWarns(DeprecationWarning): + expected.z(qr1).c_if(cr0, 1) expected.barrier(qr0, qr1) expected.measure(qr1, cr1) @@ -377,17 +379,23 @@ def test_conditioned_on_single_bit(self): circuit = QuantumCircuit(QuantumRegister(3), ClassicalRegister(2), [Clbit()]) circuit.h(range(3)) circuit.measure(range(3), range(3)) - circuit.h(0).c_if(circuit.cregs[0], 3) - circuit.h(1).c_if(circuit.clbits[-1], True) - circuit.h(2).c_if(circuit.clbits[-1], False) + with self.assertWarns(DeprecationWarning): + circuit.h(0).c_if(circuit.cregs[0], 3) + with self.assertWarns(DeprecationWarning): + circuit.h(1).c_if(circuit.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + circuit.h(2).c_if(circuit.clbits[-1], False) circuit.measure(range(3), range(3)) expected = circuit.copy_empty_like() expected.h(range(3)) expected.measure(range(3), range(3)) - expected.h(0).c_if(expected.cregs[0], 3) - expected.h(1).c_if(expected.clbits[-1], True) - expected.h(2).c_if(expected.clbits[-1], False) + with self.assertWarns(DeprecationWarning): + expected.h(0).c_if(expected.cregs[0], 3) + with self.assertWarns(DeprecationWarning): + expected.h(1).c_if(expected.clbits[-1], True) + with self.assertWarns(DeprecationWarning): + expected.h(2).c_if(expected.clbits[-1], False) expected.barrier(range(3)) expected.measure(range(3), range(3)) diff --git a/test/python/transpiler/test_basis_translator.py b/test/python/transpiler/test_basis_translator.py index 9dae6c3f283a..820c4f241a1e 100644 --- a/test/python/transpiler/test_basis_translator.py +++ b/test/python/transpiler/test_basis_translator.py @@ -576,9 +576,12 @@ def test_unroll_1q_chain_conditional(self): circuit.rz(0.3, qr) circuit.rx(0.1, qr) circuit.measure(qr, cr) - circuit.x(qr).c_if(cr, 1) - circuit.y(qr).c_if(cr, 1) - circuit.z(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.x(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.y(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.z(qr).c_if(cr, 1) dag = circuit_to_dag(circuit) pass_ = UnrollCustomDefinitions(std_eqlib, ["u1", "u2", "u3"]) dag = pass_.run(dag) @@ -609,9 +612,12 @@ def test_unroll_1q_chain_conditional(self): ref_circuit.append(U1Gate(0.3), [qr[0]]) ref_circuit.append(U3Gate(0.1, -pi / 2, pi / 2), [qr[0]]) ref_circuit.measure(qr[0], cr[0]) - ref_circuit.append(U3Gate(pi, 0, pi), [qr[0]]).c_if(cr, 1) - ref_circuit.append(U3Gate(pi, pi / 2, pi / 2), [qr[0]]).c_if(cr, 1) - ref_circuit.append(U1Gate(pi), [qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.append(U3Gate(pi, 0, pi), [qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.append(U3Gate(pi, pi / 2, pi / 2), [qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.append(U1Gate(pi), [qr[0]]).c_if(cr, 1) ref_dag = circuit_to_dag(ref_circuit) self.assertEqual(unrolled_dag, ref_dag) @@ -1073,7 +1079,8 @@ def test_condition_set_substitute_node(self): circ.h(0) circ.cx(0, 1) circ.measure(1, 1) - circ.h(0).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circ.h(0).c_if(cr, 1) circ_transpiled = transpile(circ, optimization_level=3, basis_gates=["cx", "id", "u"]) # ┌────────────┐ ┌────────────┐ @@ -1089,7 +1096,8 @@ def test_condition_set_substitute_node(self): expected.u(pi / 2, 0, pi, 0) expected.cx(0, 1) expected.measure(1, 1) - expected.u(pi / 2, 0, pi, 0).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + expected.u(pi / 2, 0, pi, 0).c_if(cr, 1) self.assertEqual(circ_transpiled, expected) diff --git a/test/python/transpiler/test_check_map.py b/test/python/transpiler/test_check_map.py index 2a88b272c74d..866eb9f4dfae 100644 --- a/test/python/transpiler/test_check_map.py +++ b/test/python/transpiler/test_check_map.py @@ -268,7 +268,8 @@ def test_nested_conditional_unusual_bit_order(self): # should all be fine. This kind of thing is a staple of the control-flow builders. inner_order = [cr2[0], cr1[0], cr2[1], cr1[1]] inner = QuantumCircuit(qr, inner_order, cr1, cr2) - inner.cx(0, 1).c_if(cr2, 3) + with self.assertWarns(DeprecationWarning): + inner.cx(0, 1).c_if(cr2, 3) outer = QuantumCircuit(qr, cr1, cr2) outer.if_test((cr1, 3), inner, outer.qubits, inner_order) diff --git a/test/python/transpiler/test_clifford_passes.py b/test/python/transpiler/test_clifford_passes.py index ff8be63ffbcd..08bbbf4cb884 100644 --- a/test/python/transpiler/test_clifford_passes.py +++ b/test/python/transpiler/test_clifford_passes.py @@ -620,7 +620,8 @@ def test_do_not_merge_conditional_gates(self): qc.cx(1, 0) qc.x(0) qc.x(1) - qc.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 1) qc.x(0) qc.x(1) qc.cx(0, 1) diff --git a/test/python/transpiler/test_collect_2q_blocks.py b/test/python/transpiler/test_collect_2q_blocks.py index 69efc210a9f6..362765101f08 100644 --- a/test/python/transpiler/test_collect_2q_blocks.py +++ b/test/python/transpiler/test_collect_2q_blocks.py @@ -129,11 +129,15 @@ def test_do_not_merge_conditioned_gates(self): qc = QuantumCircuit(qr, cr) qc.p(0.1, 0) - qc.p(0.2, 0).c_if(cr, 0) - qc.p(0.3, 0).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.p(0.2, 0).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.p(0.3, 0).c_if(cr, 0) qc.cx(0, 1) - qc.cx(1, 0).c_if(cr, 0) - qc.cx(0, 1).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.cx(1, 0).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(cr, 1) pass_manager = PassManager() pass_manager.append(Collect2qBlocks()) diff --git a/test/python/transpiler/test_collect_multiq_blocks.py b/test/python/transpiler/test_collect_multiq_blocks.py index e2446d03da2a..2d4bc8783764 100644 --- a/test/python/transpiler/test_collect_multiq_blocks.py +++ b/test/python/transpiler/test_collect_multiq_blocks.py @@ -127,7 +127,8 @@ def test_block_with_classical_register(self): if(c0==0) u1(0.25*pi) q[1]; if(c0==0) u2(0.25*pi, 0.25*pi) q[0]; """ - qc = QuantumCircuit.from_qasm_str(qasmstr) + with self.assertWarns(DeprecationWarning): + qc = QuantumCircuit.from_qasm_str(qasmstr) pass_manager = PassManager() pass_manager.append(CollectMultiQBlocks()) @@ -166,11 +167,15 @@ def test_do_not_merge_conditioned_gates(self): qc = QuantumCircuit(qr, cr) qc.p(0.1, 0) - qc.p(0.2, 0).c_if(cr, 0) - qc.p(0.3, 0).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.p(0.2, 0).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.p(0.3, 0).c_if(cr, 0) qc.cx(0, 1) - qc.cx(1, 0).c_if(cr, 0) - qc.cx(0, 1).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.cx(1, 0).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(cr, 1) pass_manager = PassManager() pass_manager.append(CollectMultiQBlocks()) diff --git a/test/python/transpiler/test_commutative_cancellation.py b/test/python/transpiler/test_commutative_cancellation.py index 88f1d99bef31..15b7f6705787 100644 --- a/test/python/transpiler/test_commutative_cancellation.py +++ b/test/python/transpiler/test_commutative_cancellation.py @@ -564,7 +564,8 @@ def test_conditional_gates_dont_commute(self): circuit.h(0) circuit.measure(0, 0) circuit.cx(1, 2) - circuit.cx(1, 2).c_if(circuit.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + circuit.cx(1, 2).c_if(circuit.cregs[0], 0) circuit.measure([1, 2], [0, 1]) new_pm = PassManager(CommutativeCancellation()) @@ -677,8 +678,10 @@ def test_basic_classical_wires(self): """Test that transpile runs without internal errors when dealing with commutable operations with classical controls. Regression test for gh-8553.""" original = QuantumCircuit(2, 1) - original.x(0).c_if(original.cregs[0], 0) - original.x(1).c_if(original.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + original.x(0).c_if(original.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + original.x(1).c_if(original.cregs[0], 0) # This transpilation shouldn't change anything, but it should succeed. At one point it was # triggering an internal logic error and crashing. transpiled = PassManager([CommutativeCancellation()]).run(original) diff --git a/test/python/transpiler/test_commutative_inverse_cancellation.py b/test/python/transpiler/test_commutative_inverse_cancellation.py index cd800a3bb46f..03492b8a8c2a 100644 --- a/test/python/transpiler/test_commutative_inverse_cancellation.py +++ b/test/python/transpiler/test_commutative_inverse_cancellation.py @@ -414,7 +414,8 @@ def test_conditional_gates_dont_commute(self, matrix_based): circuit.h(0) circuit.measure(0, 0) circuit.cx(1, 2) - circuit.cx(1, 2).c_if(circuit.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + circuit.cx(1, 2).c_if(circuit.cregs[0], 0) circuit.measure([1, 2], [0, 1]) passmanager = PassManager(CommutativeInverseCancellation(matrix_based=matrix_based)) diff --git a/test/python/transpiler/test_consolidate_blocks.py b/test/python/transpiler/test_consolidate_blocks.py index 1984ad1a3dc4..3b3aff1db228 100644 --- a/test/python/transpiler/test_consolidate_blocks.py +++ b/test/python/transpiler/test_consolidate_blocks.py @@ -328,7 +328,8 @@ def test_classical_conditions_maintained(self): This issue was raised in #2752 """ qc = QuantumCircuit(1, 1) - qc.h(0).c_if(qc.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc.h(0).c_if(qc.cregs[0], 1) qc.measure(0, 0) pass_manager = PassManager() diff --git a/test/python/transpiler/test_convert_conditions_to_if_ops.py b/test/python/transpiler/test_convert_conditions_to_if_ops.py index 799a71163590..d1eadda0d92d 100644 --- a/test/python/transpiler/test_convert_conditions_to_if_ops.py +++ b/test/python/transpiler/test_convert_conditions_to_if_ops.py @@ -26,13 +26,17 @@ def test_simple_loose_bits(self): base = QuantumCircuit(bits) base.h(0) - base.x(0).c_if(0, 1) - base.z(1).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + base.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + base.z(1).c_if(1, 0) base.measure(0, 0) base.measure(1, 1) base.h(0) - base.x(0).c_if(0, 1) - base.cx(0, 1).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + base.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + base.cx(0, 1).c_if(1, 0) expected = QuantumCircuit(bits) expected.h(0) @@ -48,8 +52,8 @@ def test_simple_loose_bits(self): with expected.if_test((expected.clbits[1], False)): expected.cx(0, 1) expected = canonicalize_control_flow(expected) - - output = PassManager([ConvertConditionsToIfOps()]).run(base) + with self.assertWarns(DeprecationWarning): + output = PassManager([ConvertConditionsToIfOps()]).run(base) self.assertEqual(output, expected) def test_simple_registers(self): @@ -58,13 +62,17 @@ def test_simple_registers(self): base = QuantumCircuit(*registers) base.h(0) - base.x(0).c_if(base.cregs[0], 1) - base.z(1).c_if(base.cregs[1], 0) + with self.assertWarns(DeprecationWarning): + base.x(0).c_if(base.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + base.z(1).c_if(base.cregs[1], 0) base.measure(0, 0) base.measure(1, 2) base.h(0) - base.x(0).c_if(base.cregs[0], 1) - base.cx(0, 1).c_if(base.cregs[1], 0) + with self.assertWarns(DeprecationWarning): + base.x(0).c_if(base.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + base.cx(0, 1).c_if(base.cregs[1], 0) expected = QuantumCircuit(*registers) expected.h(0) @@ -81,7 +89,8 @@ def test_simple_registers(self): expected.cx(0, 1) expected = canonicalize_control_flow(expected) - output = PassManager([ConvertConditionsToIfOps()]).run(base) + with self.assertWarns(DeprecationWarning): + output = PassManager([ConvertConditionsToIfOps()]).run(base) self.assertEqual(output, expected) def test_nested_control_flow(self): @@ -91,14 +100,18 @@ def test_nested_control_flow(self): registers = [QuantumRegister(3), ClassicalRegister(2)] base = QuantumCircuit(*registers, bits) - base.x(0).c_if(bits[0], False) + with self.assertWarns(DeprecationWarning): + base.x(0).c_if(bits[0], False) with base.if_test((base.cregs[0], 0)) as else_: - base.z(1).c_if(bits[0], False) + with self.assertWarns(DeprecationWarning): + base.z(1).c_if(bits[0], False) with else_: - base.z(1).c_if(base.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + base.z(1).c_if(base.cregs[0], 1) with base.for_loop(range(2)): with base.while_loop((base.cregs[0], 1)): - base.cx(1, 2).c_if(base.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + base.cx(1, 2).c_if(base.cregs[0], 1) base = canonicalize_control_flow(base) expected = QuantumCircuit(*registers, bits) @@ -115,8 +128,8 @@ def test_nested_control_flow(self): with expected.if_test((expected.cregs[0], 1)): expected.cx(1, 2) expected = canonicalize_control_flow(expected) - - output = PassManager([ConvertConditionsToIfOps()]).run(base) + with self.assertWarns(DeprecationWarning): + output = PassManager([ConvertConditionsToIfOps()]).run(base) self.assertEqual(output, expected) def test_no_op(self): @@ -135,5 +148,6 @@ def test_no_op(self): with base.while_loop((base.cregs[0], 1)): base.cx(1, 2) base = canonicalize_control_flow(base) - output = PassManager([ConvertConditionsToIfOps()]).run(base) + with self.assertWarns(DeprecationWarning): + output = PassManager([ConvertConditionsToIfOps()]).run(base) self.assertEqual(output, base) diff --git a/test/python/transpiler/test_decompose.py b/test/python/transpiler/test_decompose.py index 1223b37ca3ff..d77e63303f40 100644 --- a/test/python/transpiler/test_decompose.py +++ b/test/python/transpiler/test_decompose.py @@ -117,15 +117,19 @@ def test_decompose_conditional(self): qr = QuantumRegister(1, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr).c_if(cr, 1) - circuit.x(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.x(qr).c_if(cr, 1) dag = circuit_to_dag(circuit) pass_ = Decompose(HGate) after_dag = pass_.run(dag) ref_circuit = QuantumCircuit(qr, cr) - ref_circuit.append(U2Gate(0, pi), [qr[0]]).c_if(cr, 1) - ref_circuit.x(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.append(U2Gate(0, pi), [qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.x(qr).c_if(cr, 1) ref_dag = circuit_to_dag(ref_circuit) self.assertEqual(after_dag, ref_dag) diff --git a/test/python/transpiler/test_elide_permutations.py b/test/python/transpiler/test_elide_permutations.py index 6f3051cec0d6..edef139af2ee 100644 --- a/test/python/transpiler/test_elide_permutations.py +++ b/test/python/transpiler/test_elide_permutations.py @@ -180,7 +180,8 @@ def test_swap_condition(self): """Test swap elision doesn't touch conditioned swap.""" qc = QuantumCircuit(3, 3) qc.h(0) - qc.swap(0, 1).c_if(qc.clbits[0], 0) + with self.assertWarns(DeprecationWarning): + qc.swap(0, 1).c_if(qc.clbits[0], 0) qc.cx(0, 1) res = self.swap_pass(qc) self.assertEqual(res, qc) diff --git a/test/python/transpiler/test_gate_direction.py b/test/python/transpiler/test_gate_direction.py index 569a210f8a9d..9bdc085a5b5e 100644 --- a/test/python/transpiler/test_gate_direction.py +++ b/test/python/transpiler/test_gate_direction.py @@ -243,8 +243,10 @@ def test_preserves_conditions(self): cr = ClassicalRegister(1, "c") circuit = QuantumCircuit(qr, cr) - circuit.cx(qr[0], qr[1]).c_if(cr, 0) - circuit.cx(qr[1], qr[0]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + circuit.cx(qr[0], qr[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + circuit.cx(qr[1], qr[0]).c_if(cr, 0) circuit.cx(qr[0], qr[1]) circuit.cx(qr[1], qr[0]) @@ -261,16 +263,22 @@ def test_preserves_conditions(self): # c: 1/╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞════════════════════ # └─────┘└─────┘└─────┘└─────┘└─────┘└─────┘ expected = QuantumCircuit(qr, cr) - expected.cx(qr[0], qr[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + expected.cx(qr[0], qr[1]).c_if(cr, 0) # Order of H gates is important because DAG comparison will consider # different conditional order on a creg to be a different circuit. # See https://github.com/Qiskit/qiskit-terra/issues/3164 - expected.h(qr[1]).c_if(cr, 0) - expected.h(qr[0]).c_if(cr, 0) - expected.cx(qr[0], qr[1]).c_if(cr, 0) - expected.h(qr[1]).c_if(cr, 0) - expected.h(qr[0]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + expected.h(qr[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + expected.h(qr[0]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + expected.cx(qr[0], qr[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + expected.h(qr[1]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + expected.h(qr[0]).c_if(cr, 0) expected.cx(qr[0], qr[1]) expected.h(qr[1]) diff --git a/test/python/transpiler/test_high_level_synthesis.py b/test/python/transpiler/test_high_level_synthesis.py index a7dd806e63e9..973035a399c9 100644 --- a/test/python/transpiler/test_high_level_synthesis.py +++ b/test/python/transpiler/test_high_level_synthesis.py @@ -1588,9 +1588,12 @@ def test_unroll_1q_chain_conditional(self): circuit.rz(0.3, qr) circuit.rx(0.1, qr) circuit.measure(qr, cr) - circuit.x(qr).c_if(cr, 1) - circuit.y(qr).c_if(cr, 1) - circuit.z(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.x(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.y(qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.z(qr).c_if(cr, 1) dag = circuit_to_dag(circuit) pass_ = HighLevelSynthesis(equivalence_library=std_eqlib, basis_gates=["u1", "u2", "u3"]) dag = pass_.run(dag) @@ -1621,9 +1624,12 @@ def test_unroll_1q_chain_conditional(self): ref_circuit.append(U1Gate(0.3), [qr[0]]) ref_circuit.append(U3Gate(0.1, -np.pi / 2, np.pi / 2), [qr[0]]) ref_circuit.measure(qr[0], cr[0]) - ref_circuit.append(U3Gate(np.pi, 0, np.pi), [qr[0]]).c_if(cr, 1) - ref_circuit.append(U3Gate(np.pi, np.pi / 2, np.pi / 2), [qr[0]]).c_if(cr, 1) - ref_circuit.append(U1Gate(np.pi), [qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.append(U3Gate(np.pi, 0, np.pi), [qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.append(U3Gate(np.pi, np.pi / 2, np.pi / 2), [qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + ref_circuit.append(U1Gate(np.pi), [qr[0]]).c_if(cr, 1) ref_dag = circuit_to_dag(ref_circuit) self.assertEqual(unrolled_dag, ref_dag) diff --git a/test/python/transpiler/test_linear_functions_passes.py b/test/python/transpiler/test_linear_functions_passes.py index 1d157c437155..85dccbfa53fa 100644 --- a/test/python/transpiler/test_linear_functions_passes.py +++ b/test/python/transpiler/test_linear_functions_passes.py @@ -615,7 +615,8 @@ def test_do_not_merge_conditional_gates(self): qc = QuantumCircuit(2, 1) qc.cx(1, 0) qc.swap(1, 0) - qc.cx(0, 1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(0, 1) qc.cx(0, 1) qc.cx(1, 0) diff --git a/test/python/transpiler/test_optimize_1q_decomposition.py b/test/python/transpiler/test_optimize_1q_decomposition.py index 06aab474d611..fb043ff9d950 100644 --- a/test/python/transpiler/test_optimize_1q_decomposition.py +++ b/test/python/transpiler/test_optimize_1q_decomposition.py @@ -212,16 +212,18 @@ def test_ignores_conditional_rotations(self, basis): qr = QuantumRegister(1, "qr") cr = ClassicalRegister(2, "cr") circuit = QuantumCircuit(qr, cr) - circuit.p(0.1, qr).c_if(cr, 1) - circuit.p(0.2, qr).c_if(cr, 3) + with self.assertWarns(DeprecationWarning): + circuit.p(0.1, qr).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.p(0.2, qr).c_if(cr, 3) circuit.p(0.3, qr) circuit.p(0.4, qr) passmanager = PassManager() passmanager.append(Optimize1qGatesDecomposition(basis)) result = passmanager.run(circuit) - - self.assertTrue(Operator(circuit).equiv(Operator(result))) + with self.assertWarns(DeprecationWarning): + self.assertTrue(Operator(circuit).equiv(Operator(result))) @ddt.data( ["cx", "u3"], diff --git a/test/python/transpiler/test_optimize_1q_gates.py b/test/python/transpiler/test_optimize_1q_gates.py index e5483dd47499..bfa578826510 100644 --- a/test/python/transpiler/test_optimize_1q_gates.py +++ b/test/python/transpiler/test_optimize_1q_gates.py @@ -162,15 +162,19 @@ def test_ignores_conditional_rotations(self): qr = QuantumRegister(1, "qr") cr = ClassicalRegister(2, "cr") circuit = QuantumCircuit(qr, cr) - circuit.append(U1Gate(0.1), [qr]).c_if(cr, 1) - circuit.append(U1Gate(0.2), [qr]).c_if(cr, 3) + with self.assertWarns(DeprecationWarning): + circuit.append(U1Gate(0.1), [qr]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.append(U1Gate(0.2), [qr]).c_if(cr, 3) circuit.append(U1Gate(0.3), [qr]) circuit.append(U1Gate(0.4), [qr]) dag = circuit_to_dag(circuit) expected = QuantumCircuit(qr, cr) - expected.append(U1Gate(0.1), [qr]).c_if(cr, 1) - expected.append(U1Gate(0.2), [qr]).c_if(cr, 3) + with self.assertWarns(DeprecationWarning): + expected.append(U1Gate(0.1), [qr]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + expected.append(U1Gate(0.2), [qr]).c_if(cr, 3) expected.append(U1Gate(0.7), [qr]) pass_ = Optimize1qGates() @@ -190,15 +194,19 @@ def test_ignores_conditional_rotations_phase_gates(self): qr = QuantumRegister(1, "qr") cr = ClassicalRegister(2, "cr") circuit = QuantumCircuit(qr, cr) - circuit.append(PhaseGate(0.1), [qr]).c_if(cr, 1) - circuit.append(PhaseGate(0.2), [qr]).c_if(cr, 3) + with self.assertWarns(DeprecationWarning): + circuit.append(PhaseGate(0.1), [qr]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.append(PhaseGate(0.2), [qr]).c_if(cr, 3) circuit.append(PhaseGate(0.3), [qr]) circuit.append(PhaseGate(0.4), [qr]) dag = circuit_to_dag(circuit) expected = QuantumCircuit(qr, cr) - expected.append(PhaseGate(0.1), [qr]).c_if(cr, 1) - expected.append(PhaseGate(0.2), [qr]).c_if(cr, 3) + with self.assertWarns(DeprecationWarning): + expected.append(PhaseGate(0.1), [qr]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + expected.append(PhaseGate(0.2), [qr]).c_if(cr, 3) expected.append(PhaseGate(0.7), [qr]) pass_ = Optimize1qGates(["p", "u2", "u", "cx", "id"]) diff --git a/test/python/transpiler/test_optimize_swap_before_measure.py b/test/python/transpiler/test_optimize_swap_before_measure.py index 6d7c06f410a7..10455318bd09 100644 --- a/test/python/transpiler/test_optimize_swap_before_measure.py +++ b/test/python/transpiler/test_optimize_swap_before_measure.py @@ -363,12 +363,14 @@ def test_no_optimize_swap_with_condition(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.swap(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.swap(qr[0], qr[1]).c_if(cr, 1) circuit.measure(qr[0], cr[0]) dag = circuit_to_dag(circuit) expected = QuantumCircuit(qr, cr) - expected.swap(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + expected.swap(qr[0], qr[1]).c_if(cr, 1) expected.measure(qr[0], cr[0]) pass_ = OptimizeSwapBeforeMeasure() diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index b762d84032bb..52c2cb06d90c 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -1214,7 +1214,8 @@ def test_optimization_condition(self, level): qr = QuantumRegister(2) cr = ClassicalRegister(1) qc = QuantumCircuit(qr, cr) - qc.cx(0, 1).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(cr, 1) backend = GenericBackendV2( num_qubits=20, coupling_map=TOKYO_CMAP, @@ -1227,7 +1228,8 @@ def test_optimization_condition(self, level): def test_input_dag_copy(self): """Test substitute_node_with_dag input_dag copy on condition""" qc = QuantumCircuit(2, 1) - qc.cx(0, 1).c_if(qc.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(qc.cregs[0], 1) qc.cx(1, 0) circ = transpile(qc, basis_gates=["u3", "cz"]) self.assertIsInstance(circ, QuantumCircuit) diff --git a/test/python/transpiler/test_remove_diagonal_gates_before_measure.py b/test/python/transpiler/test_remove_diagonal_gates_before_measure.py index 474a586448b8..f560aa2c4855 100644 --- a/test/python/transpiler/test_remove_diagonal_gates_before_measure.py +++ b/test/python/transpiler/test_remove_diagonal_gates_before_measure.py @@ -550,7 +550,8 @@ def test_do_not_optimize_with_conditional(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.rz(0.1, qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.rz(0.1, qr[1]).c_if(cr, 1) circuit.barrier() circuit.h(qr[0]) circuit.measure(qr[0], cr[0]) diff --git a/test/python/transpiler/test_remove_final_measurements.py b/test/python/transpiler/test_remove_final_measurements.py index 4bc0e107109b..a91687bd8f3e 100644 --- a/test/python/transpiler/test_remove_final_measurements.py +++ b/test/python/transpiler/test_remove_final_measurements.py @@ -57,7 +57,8 @@ def expected_dag(): q0 = QuantumRegister(1, "q0") c0 = ClassicalRegister(1, "c0") qc = QuantumCircuit(q0, c0) - qc.x(0).c_if(c0[0], 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(c0[0], 0) return circuit_to_dag(qc) q0 = QuantumRegister(1, "q0") @@ -65,7 +66,8 @@ def expected_dag(): qc = QuantumCircuit(q0, c0) # make c0 busy - qc.x(0).c_if(c0[0], 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(c0[0], 0) # measure into c0 qc.measure(0, c0[0]) @@ -87,7 +89,8 @@ def expected_dag(): q0 = QuantumRegister(1, "q0") c0 = ClassicalRegister(2, "c0") qc = QuantumCircuit(q0, c0) - qc.x(q0[0]).c_if(c0[0], 0) + with self.assertWarns(DeprecationWarning): + qc.x(q0[0]).c_if(c0[0], 0) return circuit_to_dag(qc) q0 = QuantumRegister(1, "q0") @@ -95,7 +98,8 @@ def expected_dag(): qc = QuantumCircuit(q0, c0) # make c0[0] busy - qc.x(q0[0]).c_if(c0[0], 0) + with self.assertWarns(DeprecationWarning): + qc.x(q0[0]).c_if(c0[0], 0) # measure into not busy c0[1] qc.measure(0, c0[1]) diff --git a/test/python/transpiler/test_reset_after_measure_simplification.py b/test/python/transpiler/test_reset_after_measure_simplification.py index 38f602443c06..976801e71353 100644 --- a/test/python/transpiler/test_reset_after_measure_simplification.py +++ b/test/python/transpiler/test_reset_after_measure_simplification.py @@ -26,12 +26,13 @@ def test_simple(self): qc = QuantumCircuit(1, 1) qc.measure(0, 0) qc.reset(0) - - new_qc = ResetAfterMeasureSimplification()(qc) + with self.assertWarns(DeprecationWarning): + new_qc = ResetAfterMeasureSimplification()(qc) ans_qc = QuantumCircuit(1, 1) ans_qc.measure(0, 0) - ans_qc.x(0).c_if(ans_qc.clbits[0], 1) + with self.assertWarns(DeprecationWarning): + ans_qc.x(0).c_if(ans_qc.clbits[0], 1) self.assertEqual(new_qc, ans_qc) def test_simple_null(self): @@ -52,12 +53,13 @@ def test_simple_multi_reg(self): qc = QuantumCircuit(qr, cr1, cr2) qc.measure(0, 1) qc.reset(0) - - new_qc = ResetAfterMeasureSimplification()(qc) + with self.assertWarns(DeprecationWarning): + new_qc = ResetAfterMeasureSimplification()(qc) ans_qc = QuantumCircuit(qr, cr1, cr2) ans_qc.measure(0, 1) - ans_qc.x(0).c_if(cr2[0], 1) + with self.assertWarns(DeprecationWarning): + ans_qc.x(0).c_if(cr2[0], 1) self.assertEqual(new_qc, ans_qc) @@ -69,7 +71,6 @@ def test_simple_multi_reg_null(self): qc = QuantumCircuit(qr, cr1, cr2) qc.measure(0, 1) qc.reset(1) # reset not on same qubit as meas - new_qc = ResetAfterMeasureSimplification()(qc) self.assertEqual(new_qc, qc) @@ -79,12 +80,13 @@ def test_simple_multi_resets(self): qc.measure(0, 0) qc.reset(0) qc.reset(0) - - new_qc = ResetAfterMeasureSimplification()(qc) + with self.assertWarns(DeprecationWarning): + new_qc = ResetAfterMeasureSimplification()(qc) ans_qc = QuantumCircuit(1, 2) ans_qc.measure(0, 0) - ans_qc.x(0).c_if(ans_qc.clbits[0], 1) + with self.assertWarns(DeprecationWarning): + ans_qc.x(0).c_if(ans_qc.clbits[0], 1) ans_qc.reset(0) self.assertEqual(new_qc, ans_qc) @@ -96,11 +98,13 @@ def test_simple_multi_resets_with_resets_before_measure(self): qc.reset(1) qc.measure(1, 1) - new_qc = ResetAfterMeasureSimplification()(qc) + with self.assertWarns(DeprecationWarning): + new_qc = ResetAfterMeasureSimplification()(qc) ans_qc = QuantumCircuit(2, 2) ans_qc.measure(0, 0) - ans_qc.x(0).c_if(Clbit(ClassicalRegister(2, "c"), 0), 1) + with self.assertWarns(DeprecationWarning): + ans_qc.x(0).c_if(Clbit(ClassicalRegister(2, "c"), 0), 1) ans_qc.reset(1) ans_qc.measure(1, 1) @@ -134,7 +138,8 @@ def test_bv_circuit(self): qc.reset(1) qc.x(1) qc.h(1) - new_qc = ResetAfterMeasureSimplification()(qc) + with self.assertWarns(DeprecationWarning): + new_qc = ResetAfterMeasureSimplification()(qc) for op in new_qc.data: if op.operation.name == "reset": self.assertEqual(op.qubits[0], new_qc.qubits[1]) @@ -149,7 +154,8 @@ def test_simple_if_else(self): base_expected = QuantumCircuit(1, 1) base_expected.measure(0, 0) - base_expected.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + base_expected.x(0).c_if(0, True) test = QuantumCircuit(1, 1) test.if_else( @@ -165,7 +171,8 @@ def test_simple_if_else(self): expected.clbits, ) - self.assertEqual(pass_(test), expected) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pass_(test), expected) def test_nested_control_flow(self): """Test that the pass recurses into nested control flow.""" @@ -177,7 +184,8 @@ def test_nested_control_flow(self): base_expected = QuantumCircuit(1, 1) base_expected.measure(0, 0) - base_expected.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + base_expected.x(0).c_if(0, True) body_test = QuantumCircuit(1, 1) body_test.for_loop((0,), None, base_expected.copy(), body_test.qubits, body_test.clbits) @@ -194,5 +202,5 @@ def test_nested_control_flow(self): expected.while_loop( (expected.clbits[0], True), body_expected, expected.qubits, expected.clbits ) - - self.assertEqual(pass_(test), expected) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pass_(test), expected) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index 856b5ff09f5b..e66f56c7cd34 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -293,7 +293,8 @@ def test_classical_condition(self): with self.subTest("1 bit in register"): qc = QuantumCircuit(2, 1) qc.z(0) - qc.z(0).c_if(qc.cregs[0], 0) + with self.assertWarns(DeprecationWarning): + qc.z(0).c_if(qc.cregs[0], 0) cm = CouplingMap([(0, 1), (1, 0)]) expected = PassManager([TrivialLayout(cm)]).run(qc) actual = PassManager([TrivialLayout(cm), SabreSwap(cm)]).run(qc) @@ -302,8 +303,10 @@ def test_classical_condition(self): cregs = [ClassicalRegister(3), ClassicalRegister(4)] qc = QuantumCircuit(QuantumRegister(2, name="q"), *cregs) qc.z(0) - qc.z(0).c_if(cregs[0], 0) - qc.z(0).c_if(cregs[1], 0) + with self.assertWarns(DeprecationWarning): + qc.z(0).c_if(cregs[0], 0) + with self.assertWarns(DeprecationWarning): + qc.z(0).c_if(cregs[1], 0) cm = CouplingMap([(0, 1), (1, 0)]) expected = PassManager([TrivialLayout(cm)]).run(qc) actual = PassManager([TrivialLayout(cm), SabreSwap(cm)]).run(qc) @@ -316,40 +319,54 @@ def test_classical_condition_cargs(self): """ with self.subTest("missing measurement"): qc = QuantumCircuit(3, 1) - qc.cx(0, 2).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 2).c_if(0, 0) qc.measure(1, 0) - qc.h(2).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.h(2).c_if(0, 0) expected = QuantumCircuit(3, 1) expected.swap(1, 2) - expected.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected.cx(0, 1).c_if(0, 0) expected.measure(2, 0) - expected.h(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected.h(1).c_if(0, 0) result = SabreSwap(CouplingMap.from_line(3), seed=12345)(qc) self.assertEqual(result, expected) with self.subTest("reordered measurement"): qc = QuantumCircuit(3, 1) - qc.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(0, 0) qc.measure(1, 0) - qc.h(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.h(0).c_if(0, 0) expected = QuantumCircuit(3, 1) - expected.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected.cx(0, 1).c_if(0, 0) expected.measure(1, 0) - expected.h(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected.h(0).c_if(0, 0) result = SabreSwap(CouplingMap.from_line(3), seed=12345)(qc) self.assertEqual(result, expected) def test_conditional_measurement(self): """Test that instructions with cargs and conditions are handled correctly.""" qc = QuantumCircuit(3, 2) - qc.cx(0, 2).c_if(0, 0) - qc.measure(2, 0).c_if(1, 0) - qc.h(2).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 2).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.measure(2, 0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + qc.h(2).c_if(0, 0) qc.measure(1, 1) expected = QuantumCircuit(3, 2) expected.swap(1, 2) - expected.cx(0, 1).c_if(0, 0) - expected.measure(1, 0).c_if(1, 0) - expected.h(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected.measure(1, 0).c_if(1, 0) + with self.assertWarns(DeprecationWarning): + expected.h(1).c_if(0, 0) expected.measure(2, 1) result = SabreSwap(CouplingMap.from_line(3), seed=12345)(qc) self.assertEqual(result, expected) diff --git a/test/python/transpiler/test_scheduling_padding_pass.py b/test/python/transpiler/test_scheduling_padding_pass.py index f2f4f6a24bc6..32431ba6b2a2 100644 --- a/test/python/transpiler/test_scheduling_padding_pass.py +++ b/test/python/transpiler/test_scheduling_padding_pass.py @@ -114,7 +114,8 @@ def test_classically_controlled_gate_after_measure(self, schedule_pass): """ qc = QuantumCircuit(2, 1) qc.measure(0, 0) - qc.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, True) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) pm = PassManager([schedule_pass(durations), PadDelay()]) @@ -123,7 +124,8 @@ def test_classically_controlled_gate_after_measure(self, schedule_pass): expected = QuantumCircuit(2, 1) expected.measure(0, 0) expected.delay(1000, 1) # x.c_if starts after measure - expected.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, True) expected.delay(200, 0) self.assertEqual(expected, scheduled) @@ -200,8 +202,10 @@ def test_c_if_on_different_qubits(self, schedule_pass): """ qc = QuantumCircuit(3, 1) qc.measure(0, 0) - qc.x(1).c_if(0, True) - qc.x(2).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(2).c_if(0, True) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) pm = PassManager([schedule_pass(durations), PadDelay()]) @@ -211,8 +215,10 @@ def test_c_if_on_different_qubits(self, schedule_pass): expected.measure(0, 0) expected.delay(1000, 1) expected.delay(1000, 2) - expected.x(1).c_if(0, True) - expected.x(2).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(2).c_if(0, True) expected.delay(200, 0) self.assertEqual(expected, scheduled) @@ -283,7 +289,8 @@ def test_measure_after_c_if(self, schedule_pass): """ qc = QuantumCircuit(3, 1) qc.measure(0, 0) - qc.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 1) qc.measure(2, 0) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) @@ -294,7 +301,8 @@ def test_measure_after_c_if(self, schedule_pass): expected.delay(1000, 1) expected.delay(1000, 2) expected.measure(0, 0) - expected.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, 1) expected.measure(2, 0) expected.delay(1000, 0) expected.delay(800, 1) @@ -474,7 +482,8 @@ def test_measure_after_c_if_on_edge_locking(self): """ qc = QuantumCircuit(3, 1) qc.measure(0, 0) - qc.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 1) qc.measure(2, 0) durations = InstructionDurations([("x", None, 200), ("measure", None, 1000)]) @@ -499,7 +508,8 @@ def test_measure_after_c_if_on_edge_locking(self): expected_asap = QuantumCircuit(3, 1) expected_asap.measure(0, 0) expected_asap.delay(1000, 1) - expected_asap.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_asap.x(1).c_if(0, 1) expected_asap.measure(2, 0) expected_asap.delay(200, 0) expected_asap.delay(200, 2) @@ -508,7 +518,8 @@ def test_measure_after_c_if_on_edge_locking(self): expected_alap = QuantumCircuit(3, 1) expected_alap.measure(0, 0) expected_alap.delay(1000, 1) - expected_alap.x(1).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_alap.x(1).c_if(0, 1) expected_alap.delay(200, 2) expected_alap.measure(2, 0) expected_alap.delay(200, 0) @@ -534,11 +545,14 @@ def test_active_reset_circuit(self, write_lat, cond_lat): """ qc = QuantumCircuit(1, 1) qc.measure(0, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) qc.measure(0, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) qc.measure(0, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) durations = InstructionDurations([("x", None, 100), ("measure", None, 1000)]) @@ -562,15 +576,18 @@ def test_active_reset_circuit(self, write_lat, cond_lat): expected.measure(0, 0) if cond_lat > 0: expected.delay(cond_lat, 0) - expected.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, 1) expected.measure(0, 0) if cond_lat > 0: expected.delay(cond_lat, 0) - expected.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, 1) expected.measure(0, 0) if cond_lat > 0: expected.delay(cond_lat, 0) - expected.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, 1) self.assertEqual(expected, actual_asap) self.assertEqual(expected, actual_alap) @@ -659,15 +676,19 @@ def test_random_complicated_circuit(self): """ qc = QuantumCircuit(3, 1) qc.delay(100, 0) - qc.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 1) qc.barrier() qc.measure(2, 0) - qc.x(1).c_if(0, 0) - qc.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, 0) qc.delay(300, 0) qc.cx(1, 2) qc.x(0) - qc.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + qc.cx(0, 1).c_if(0, 0) qc.measure(2, 0) durations = InstructionDurations( @@ -694,19 +715,23 @@ def test_random_complicated_circuit(self): expected_asap.delay(200, 0) # due to conditional latency of 200dt expected_asap.delay(300, 1) expected_asap.delay(300, 2) - expected_asap.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_asap.x(0).c_if(0, 1) expected_asap.barrier() expected_asap.delay(1400, 0) expected_asap.delay(1200, 1) expected_asap.measure(2, 0) - expected_asap.x(1).c_if(0, 0) - expected_asap.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_asap.x(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_asap.x(0).c_if(0, 0) expected_asap.delay(300, 0) expected_asap.x(0) expected_asap.delay(300, 2) expected_asap.cx(1, 2) expected_asap.delay(400, 1) - expected_asap.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_asap.cx(0, 1).c_if(0, 0) expected_asap.delay(700, 0) # creg is released at t0 of cx(0,1).c_if(0,0) expected_asap.delay( 700, 1 @@ -720,20 +745,24 @@ def test_random_complicated_circuit(self): expected_alap.delay(200, 0) # due to conditional latency of 200dt expected_alap.delay(300, 1) expected_alap.delay(300, 2) - expected_alap.x(0).c_if(0, 1) + with self.assertWarns(DeprecationWarning): + expected_alap.x(0).c_if(0, 1) expected_alap.barrier() expected_alap.delay(1400, 0) expected_alap.delay(1200, 1) expected_alap.measure(2, 0) - expected_alap.x(1).c_if(0, 0) - expected_alap.x(0).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_alap.x(1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_alap.x(0).c_if(0, 0) expected_alap.delay(300, 0) expected_alap.x(0) expected_alap.delay(300, 1) expected_alap.delay(600, 2) expected_alap.cx(1, 2) expected_alap.delay(100, 1) - expected_alap.cx(0, 1).c_if(0, 0) + with self.assertWarns(DeprecationWarning): + expected_alap.cx(0, 1).c_if(0, 0) expected_alap.measure(2, 0) expected_alap.delay(700, 0) expected_alap.delay(700, 1) @@ -771,8 +800,10 @@ def test_dag_introduces_extra_dependency_between_conditionals(self): """ qc = QuantumCircuit(2, 1) qc.delay(100, 0) - qc.x(0).c_if(0, True) - qc.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + qc.x(1).c_if(0, True) durations = InstructionDurations([("x", None, 160)]) pm = PassManager([ASAPScheduleAnalysis(durations), PadDelay()]) @@ -781,8 +812,10 @@ def test_dag_introduces_extra_dependency_between_conditionals(self): expected = QuantumCircuit(2, 1) expected.delay(100, 0) expected.delay(100, 1) # due to extra dependency on clbits - expected.x(0).c_if(0, True) - expected.x(1).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(0).c_if(0, True) + with self.assertWarns(DeprecationWarning): + expected.x(1).c_if(0, True) self.assertEqual(expected, scheduled) diff --git a/test/python/transpiler/test_unroll_3q_or_more.py b/test/python/transpiler/test_unroll_3q_or_more.py index 27927bbbd4ad..d0388e4fe531 100644 --- a/test/python/transpiler/test_unroll_3q_or_more.py +++ b/test/python/transpiler/test_unroll_3q_or_more.py @@ -62,7 +62,8 @@ def test_decompose_conditional(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 0) + with self.assertWarns(DeprecationWarning): + circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 0) dag = circuit_to_dag(circuit) pass_ = Unroll3qOrMore() after_dag = pass_.run(dag) diff --git a/test/python/transpiler/test_unroll_forloops.py b/test/python/transpiler/test_unroll_forloops.py index cbf8f70ef767..a44655903370 100644 --- a/test/python/transpiler/test_unroll_forloops.py +++ b/test/python/transpiler/test_unroll_forloops.py @@ -135,7 +135,8 @@ def test_skip_continue_c_if(self): circuit.h(0) circuit.cx(0, 1) circuit.measure(0, 0) - circuit.break_loop().c_if(0, True) + with self.assertWarns(DeprecationWarning): + circuit.break_loop().c_if(0, True) passmanager = PassManager() passmanager.append(UnrollForLoops()) diff --git a/test/python/visualization/test_circuit_drawer.py b/test/python/visualization/test_circuit_drawer.py index dd69faac02cb..9eb4e3ad2c88 100644 --- a/test/python/visualization/test_circuit_drawer.py +++ b/test/python/visualization/test_circuit_drawer.py @@ -151,7 +151,8 @@ def test_wire_order(self): circuit.h(0) circuit.h(3) circuit.x(1) - circuit.x(3).c_if(cr, 10) + with self.assertWarns(DeprecationWarning): + circuit.x(3).c_if(cr, 10) expected = "\n".join( [ @@ -183,7 +184,8 @@ def test_wire_order_cregbundle(self): circuit.h(0) circuit.h(3) circuit.x(1) - circuit.x(3).c_if(cr, 10) + with self.assertWarns(DeprecationWarning): + circuit.x(3).c_if(cr, 10) expected = "\n".join( [ diff --git a/test/python/visualization/test_circuit_text_drawer.py b/test/python/visualization/test_circuit_text_drawer.py index e7d28aac8a9e..666255c44f23 100644 --- a/test/python/visualization/test_circuit_text_drawer.py +++ b/test/python/visualization/test_circuit_text_drawer.py @@ -388,7 +388,8 @@ def test_wire_order(self): circuit.h(0) circuit.h(3) circuit.x(1) - circuit.x(3).c_if(cr, 10) + with self.assertWarns(DeprecationWarning): + circuit.x(3).c_if(cr, 10) self.assertEqual( str( circuit_drawer( @@ -845,7 +846,8 @@ def test_text_cu1_condition(self): qr = QuantumRegister(3, "q") cr = ClassicalRegister(3, "c") circuit = QuantumCircuit(qr, cr) - circuit.append(CU1Gate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) + with self.assertWarns(DeprecationWarning): + circuit.append(CU1Gate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) self.assertEqual(str(circuit_drawer(circuit, output="text", initial_state=False)), expected) def test_text_rzz_condition(self): @@ -866,7 +868,8 @@ def test_text_rzz_condition(self): qr = QuantumRegister(3, "q") cr = ClassicalRegister(3, "c") circuit = QuantumCircuit(qr, cr) - circuit.append(RZZGate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) + with self.assertWarns(DeprecationWarning): + circuit.append(RZZGate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) self.assertEqual(str(circuit_drawer(circuit, output="text", initial_state=False)), expected) def test_text_cp_condition(self): @@ -887,7 +890,8 @@ def test_text_cp_condition(self): qr = QuantumRegister(3, "q") cr = ClassicalRegister(3, "c") circuit = QuantumCircuit(qr, cr) - circuit.append(CPhaseGate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) + with self.assertWarns(DeprecationWarning): + circuit.append(CPhaseGate(pi / 2), [qr[0], qr[1]]).c_if(cr[1], 1) self.assertEqual(str(circuit_drawer(circuit, output="text", initial_state=False)), expected) def test_text_cu1_reverse_bits(self): @@ -1758,7 +1762,8 @@ def test_control_gate_label_with_cond_1_low(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [0, 1]) self.assertEqual( @@ -1789,7 +1794,8 @@ def test_control_gate_label_with_cond_1_low_cregbundle(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [0, 1]) self.assertEqual( @@ -1824,7 +1830,8 @@ def test_control_gate_label_with_cond_1_med(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [0, 1]) self.assertEqual( @@ -1860,7 +1867,8 @@ def test_control_gate_label_with_cond_1_med_cregbundle(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [0, 1]) self.assertEqual( @@ -1895,7 +1903,8 @@ def test_control_gate_label_with_cond_1_high(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [0, 1]) self.assertEqual( @@ -1930,7 +1939,8 @@ def test_control_gate_label_with_cond_1_high_cregbundle(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [0, 1]) self.assertEqual( @@ -1966,7 +1976,8 @@ def test_control_gate_label_with_cond_2_med_space(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [1, 0]) self.assertEqual( @@ -1998,7 +2009,8 @@ def test_control_gate_label_with_cond_2_med(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ctrl-h").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ctrl-h").c_if(cr, 1) circ.append(controlh, [1, 0]) self.assertEqual( @@ -2034,7 +2046,8 @@ def test_control_gate_label_with_cond_2_med_cregbundle(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [1, 0]) self.assertEqual( @@ -2071,7 +2084,8 @@ def test_control_gate_label_with_cond_2_low(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [1, 0]) self.assertEqual( @@ -2108,7 +2122,8 @@ def test_control_gate_label_with_cond_2_low_cregbundle(self): cr = ClassicalRegister(1, "c") circ = QuantumCircuit(qr, cr) hgate = HGate(label="my h") - controlh = hgate.control(label="my ch").c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + controlh = hgate.control(label="my ch").c_if(cr, 1) circ.append(controlh, [1, 0]) self.assertEqual( @@ -2269,8 +2284,8 @@ def test_text_conditional_1(self): " 0x1 ", ] ) - - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2309,7 +2324,8 @@ def test_text_conditional_1_bundle(self): ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2335,7 +2351,8 @@ def test_text_conditional_reverse_bits_true(self): circuit.x(0) circuit.x(0) circuit.measure(2, 1) - circuit.x(2).c_if(cr, 2) + with self.assertWarns(DeprecationWarning): + circuit.x(2).c_if(cr, 2) expected = "\n".join( [ @@ -2386,7 +2403,8 @@ def test_text_conditional_reverse_bits_false(self): circuit.x(0) circuit.x(0) circuit.measure(2, 1) - circuit.x(2).c_if(cr, 2) + with self.assertWarns(DeprecationWarning): + circuit.x(2).c_if(cr, 2) expected = "\n".join( [ @@ -2486,7 +2504,8 @@ def test_text_conditional_1(self): " 0x1 ", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2523,8 +2542,8 @@ def test_text_conditional_1_bundle(self): " └─────┘", ] ) - - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2565,7 +2584,8 @@ def test_text_measure_with_spaces(self): " 0x1 ", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2603,7 +2623,8 @@ def test_text_measure_with_spaces_bundle(self): " 1 └─────┘", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2694,8 +2715,10 @@ def test_text_barrier_med_compress_3(self): qc1 = ClassicalRegister(3, "cr") qc2 = ClassicalRegister(1, "cr2") circuit = QuantumCircuit(qr, qc1, qc2) - circuit.x(0).c_if(qc1, 3) - circuit.x(0).c_if(qc2[0], 1) + with self.assertWarns(DeprecationWarning): + circuit.x(0).c_if(qc1, 3) + with self.assertWarns(DeprecationWarning): + circuit.x(0).c_if(qc2[0], 1) expected = "\n".join( [ @@ -2753,8 +2776,8 @@ def test_text_conditional_1_cregbundle(self): " └─────┘", ] ) - - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2790,8 +2813,8 @@ def test_text_conditional_1(self): " 0x1 ", ] ) - - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str(circuit_drawer(circuit, output="text", initial_state=True, cregbundle=False)), expected, @@ -2819,7 +2842,8 @@ def test_text_conditional_2_cregbundle(self): " └─────┘", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2859,7 +2883,8 @@ def test_text_conditional_2(self): " 0x2 ", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str(circuit_drawer(circuit, output="text", initial_state=True, cregbundle=False)), expected, @@ -2887,7 +2912,8 @@ def test_text_conditional_3_cregbundle(self): " └─────┘", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -2931,7 +2957,8 @@ def test_text_conditional_3(self): " 0x3 ", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str(circuit_drawer(circuit, output="text", initial_state=True, cregbundle=False)), expected, @@ -2959,7 +2986,8 @@ def test_text_conditional_4(self): " └─────┘", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str( circuit_drawer( @@ -3007,7 +3035,8 @@ def test_text_conditional_5(self): " 0x5 ", ] ) - circuit = QuantumCircuit.from_qasm_str(qasm_string) + with self.assertWarns(DeprecationWarning): + circuit = QuantumCircuit.from_qasm_str(qasm_string) self.assertEqual( str(circuit_drawer(circuit, output="text", initial_state=True, cregbundle=False)), expected, @@ -3018,7 +3047,8 @@ def test_text_conditional_cz_no_space_cregbundle(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cz(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cz(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3042,7 +3072,8 @@ def test_text_conditional_cz_no_space(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cz(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cz(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3066,7 +3097,8 @@ def test_text_conditional_cz_cregbundle(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cz(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cz(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3092,7 +3124,8 @@ def test_text_conditional_cz(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cz(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cz(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3118,7 +3151,8 @@ def test_text_conditional_cx_ct_cregbundle(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cx(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cx(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3144,7 +3178,8 @@ def test_text_conditional_cx_ct(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cx(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cx(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3170,7 +3205,8 @@ def test_text_conditional_cx_tc_cregbundle(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cx(qr[1], qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cx(qr[1], qr[0]).c_if(cr, 1) expected = "\n".join( [ @@ -3196,7 +3232,8 @@ def test_text_conditional_cx_tc(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cx(qr[1], qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cx(qr[1], qr[0]).c_if(cr, 1) expected = "\n".join( [ @@ -3222,7 +3259,8 @@ def test_text_conditional_cu3_ct_cregbundle(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[0], qr[1]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[0], qr[1]]).c_if(cr, 1) expected = "\n".join( [ @@ -3248,7 +3286,8 @@ def test_text_conditional_cu3_ct(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[0], qr[1]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[0], qr[1]]).c_if(cr, 1) expected = "\n".join( [ @@ -3274,7 +3313,8 @@ def test_text_conditional_cu3_tc_cregbundle(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[1], qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[1], qr[0]]).c_if(cr, 1) expected = "\n".join( [ @@ -3300,7 +3340,8 @@ def test_text_conditional_cu3_tc(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[1], qr[0]]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.append(CU3Gate(pi / 2, pi / 2, pi / 2), [qr[1], qr[0]]).c_if(cr, 1) expected = "\n".join( [ @@ -3326,7 +3367,8 @@ def test_text_conditional_ccx_cregbundle(self): qr = QuantumRegister(4, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) expected = "\n".join( [ @@ -3354,7 +3396,8 @@ def test_text_conditional_ccx(self): qr = QuantumRegister(4, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) expected = "\n".join( [ @@ -3382,7 +3425,8 @@ def test_text_conditional_ccx_no_space_cregbundle(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) expected = "\n".join( [ @@ -3416,7 +3460,8 @@ def test_text_conditional_ccx_no_space(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1) expected = "\n".join( [ @@ -3442,7 +3487,8 @@ def test_text_conditional_h_cregbundle(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr, 1) expected = "\n".join( [ @@ -3466,7 +3512,8 @@ def test_text_conditional_h(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr, 1) expected = "\n".join( [ @@ -3490,7 +3537,8 @@ def test_text_conditional_swap_cregbundle(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.swap(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.swap(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3516,7 +3564,8 @@ def test_text_conditional_swap(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.swap(qr[0], qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.swap(qr[0], qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3542,7 +3591,8 @@ def test_text_conditional_cswap_cregbundle(self): qr = QuantumRegister(4, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cswap(qr[0], qr[1], qr[2]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cswap(qr[0], qr[1], qr[2]).c_if(cr, 1) expected = "\n".join( [ @@ -3570,7 +3620,8 @@ def test_text_conditional_cswap(self): qr = QuantumRegister(4, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.cswap(qr[0], qr[1], qr[2]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.cswap(qr[0], qr[1], qr[2]).c_if(cr, 1) expected = "\n".join( [ @@ -3599,7 +3650,8 @@ def test_conditional_reset_cregbundle(self): cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.reset(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.reset(qr[0]).c_if(cr, 1) expected = "\n".join( [ @@ -3624,7 +3676,8 @@ def test_conditional_reset(self): cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) - circuit.reset(qr[0]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.reset(qr[0]).c_if(cr, 1) expected = "\n".join( [ @@ -3649,7 +3702,8 @@ def test_conditional_multiplexer_cregbundle(self): qr = QuantumRegister(3, name="qr") cr = ClassicalRegister(1, "cr") qc = QuantumCircuit(qr, cr) - qc.append(cx_multiplexer.c_if(cr, 1), [qr[0], qr[1]]) + with self.assertWarns(DeprecationWarning): + qc.append(cx_multiplexer.c_if(cr, 1), [qr[0], qr[1]]) expected = "\n".join( [ @@ -3675,7 +3729,8 @@ def test_conditional_multiplexer(self): qr = QuantumRegister(3, name="qr") cr = ClassicalRegister(1, "cr") qc = QuantumCircuit(qr, cr) - qc.append(cx_multiplexer.c_if(cr, 1), [qr[0], qr[1]]) + with self.assertWarns(DeprecationWarning): + qc.append(cx_multiplexer.c_if(cr, 1), [qr[0], qr[1]]) expected = "\n".join( [ @@ -3702,7 +3757,8 @@ def test_text_conditional_measure_cregbundle(self): circuit = QuantumCircuit(qr, cr) circuit.h(qr[0]) circuit.measure(qr[0], cr[0]) - circuit.h(qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3736,7 +3792,8 @@ def test_text_conditional_measure(self): circuit = QuantumCircuit(qr, cr) circuit.h(qr[0]) circuit.measure(qr[0], cr[0]) - circuit.h(qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3762,8 +3819,10 @@ def test_text_bit_conditional(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(2, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr[0]).c_if(cr[0], 1) - circuit.h(qr[1]).c_if(cr[1], 0) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr[0], 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[1]).c_if(cr[1], 0) expected = "\n".join( [ @@ -3790,8 +3849,10 @@ def test_text_bit_conditional_cregbundle(self): qr = QuantumRegister(2, "qr") cr = ClassicalRegister(2, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr[0]).c_if(cr[0], 1) - circuit.h(qr[1]).c_if(cr[1], 0) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr[0], 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[1]).c_if(cr[1], 0) expected = "\n".join( [ @@ -3826,7 +3887,8 @@ def test_text_condition_measure_bits_true(self): cr = ClassicalRegister(2, "cr") crx = ClassicalRegister(3, "cs") circuit = QuantumCircuit(bits, cr, [Clbit()], crx) - circuit.x(0).c_if(crx[1], 0) + with self.assertWarns(DeprecationWarning): + circuit.x(0).c_if(crx[1], 0) circuit.measure(0, bits[3]) expected = "\n".join( @@ -3860,7 +3922,8 @@ def test_text_condition_measure_bits_false(self): cr = ClassicalRegister(2, "cr") crx = ClassicalRegister(3, "cs") circuit = QuantumCircuit(bits, cr, [Clbit()], crx) - circuit.x(0).c_if(crx[1], 0) + with self.assertWarns(DeprecationWarning): + circuit.x(0).c_if(crx[1], 0) circuit.measure(0, bits[3]) expected = "\n".join( @@ -3900,7 +3963,8 @@ def test_text_conditional_reverse_bits_1(self): circuit = QuantumCircuit(qr, cr) circuit.h(qr[0]) circuit.measure(qr[0], cr[0]) - circuit.h(qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[1]).c_if(cr, 1) expected = "\n".join( [ @@ -3930,10 +3994,14 @@ def test_text_conditional_reverse_bits_2(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(3, "cr") circuit = QuantumCircuit(qr, cr) - circuit.h(qr[0]).c_if(cr, 6) - circuit.h(qr[1]).c_if(cr, 1) - circuit.h(qr[2]).c_if(cr, 2) - circuit.cx(0, 1).c_if(cr, 3) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[0]).c_if(cr, 6) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[1]).c_if(cr, 1) + with self.assertWarns(DeprecationWarning): + circuit.h(qr[2]).c_if(cr, 2) + with self.assertWarns(DeprecationWarning): + circuit.cx(0, 1).c_if(cr, 3) expected = "\n".join( [ @@ -3969,7 +4037,8 @@ def test_text_condition_bits_reverse(self): cr = ClassicalRegister(2, "cr") crx = ClassicalRegister(3, "cs") circuit = QuantumCircuit(bits, cr, [Clbit()], crx) - circuit.x(0).c_if(bits[3], 0) + with self.assertWarns(DeprecationWarning): + circuit.x(0).c_if(bits[3], 0) expected = "\n".join( [ @@ -4847,9 +4916,10 @@ def test_cccz_conditional(self): qr = QuantumRegister(4, "q") cr = ClassicalRegister(1, "c") circuit = QuantumCircuit(qr, cr) - circuit.append( - ZGate().control(3, ctrl_state="101").c_if(cr, 1), [qr[0], qr[1], qr[2], qr[3]] - ) + with self.assertWarns(DeprecationWarning): + circuit.append( + ZGate().control(3, ctrl_state="101").c_if(cr, 1), [qr[0], qr[1], qr[2], qr[3]] + ) self.assertEqual(str(circuit_drawer(circuit, output="text", initial_state=True)), expected) def test_cch_bot(self): @@ -5908,14 +5978,16 @@ def test_if_else_with_body_specified(self): circuit.measure(0, 1) circuit.measure(1, 2) circuit.x(2) - circuit.x(2, label="XLabel").c_if(cr, 2) + with self.assertWarns(DeprecationWarning): + circuit.x(2, label="XLabel").c_if(cr, 2) qr2 = QuantumRegister(3, "qr2") circuit2 = QuantumCircuit(qr2, cr) circuit2.x(1) circuit2.y(1) circuit2.z(0) - circuit2.x(0, label="X1i").c_if(cr, 4) + with self.assertWarns(DeprecationWarning): + circuit2.x(0, label="X1i").c_if(cr, 4) circuit.if_else((cr[1], 1), circuit2, None, [0, 1, 2], [0, 1, 2]) circuit.x(0, label="X1i") @@ -5981,7 +6053,8 @@ def test_if_op_nested_wire_order(self): circuit.h(0) with circuit.if_test((cr[1], 1)) as _else: - circuit.x(0, label="X c_if").c_if(cr, 4) + with self.assertWarns(DeprecationWarning): + circuit.x(0, label="X c_if").c_if(cr, 4) with circuit.if_test((cr[2], 1)): circuit.z(0) circuit.y(1) @@ -6227,12 +6300,15 @@ def test_if_else_op_from_circuit_with_conditions(self): cr = ClassicalRegister(3, "cr") circuit = QuantumCircuit(qr, cr) circuit.h(0) - circuit.x(2).c_if(cr[1], 2) + with self.assertWarns(DeprecationWarning): + circuit.x(2).c_if(cr[1], 2) qr2 = QuantumRegister(3, "qr2") qc2 = QuantumCircuit(qr2, cr) - qc2.x(0, label="X1").c_if(cr, 4) - qc2.x(1, label="X2").c_if(cr[1], 1) + with self.assertWarns(DeprecationWarning): + qc2.x(0, label="X1").c_if(cr, 4) + with self.assertWarns(DeprecationWarning): + qc2.x(1, label="X2").c_if(cr[1], 1) circuit.if_else((cr[1], 1), qc2, None, [0, 1, 2], [0, 1, 2]) self.assertEqual( diff --git a/test/python/visualization/test_dag_drawer.py b/test/python/visualization/test_dag_drawer.py index 56138c12cf00..9c9b11e42a68 100644 --- a/test/python/visualization/test_dag_drawer.py +++ b/test/python/visualization/test_dag_drawer.py @@ -98,7 +98,8 @@ def test_dag_drawer_with_dag_dep(self): qc.cx(0, 1) qc.cx(0, 2) qc.cx(0, 3) - qc.x(3).c_if(cr[1], 1) + with self.assertWarns(DeprecationWarning): + qc.x(3).c_if(cr[1], 1) qc.h(3) qc.x(4) qc.barrier(0, 1) diff --git a/test/python/visualization/test_utils.py b/test/python/visualization/test_utils.py index 1ef87994d001..7e0f91f3f993 100644 --- a/test/python/visualization/test_utils.py +++ b/test/python/visualization/test_utils.py @@ -328,9 +328,13 @@ def test_get_layered_instructions_op_with_cargs(self): qc.h(0) qc.measure(0, 0) qc_2 = QuantumCircuit(1, 1, name="add_circ") - qc_2.h(0).c_if(qc_2.cregs[0], 1) + with self.assertWarns(DeprecationWarning): + qc_2.h(0).c_if(qc_2.cregs[0], 1) qc_2.measure(0, 0) - qc.append(qc_2, [1], [0]) + # This append calls ends up calling .to_instruction() which calls + # .c_if() internally + with self.assertWarns(DeprecationWarning): + qc.append(qc_2, [1], [0]) (_, _, layered_ops) = _utils._get_layered_instructions(qc) diff --git a/test/utils/base.py b/test/utils/base.py index 0038f7772ebf..cbfae18ac95e 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -164,6 +164,13 @@ def setUpClass(cls): module="qiskit.providers.fake_provider.fake_backend", ) + # Remove with the condition attribute in 2.0: + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=r".*The property.*Instruction\.condition.*is deprecated.*", + ) + allow_DeprecationWarning_message = [ r"The property ``qiskit\.circuit\.bit\.Bit\.(register|index)`` is deprecated.*", ]