From 7f5d10bdd45fbb5634a35f54935d93f95f2bcff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 5 Nov 2024 11:14:39 +0100 Subject: [PATCH 1/7] Deprecate loose custom basis gates --- .../generate_preset_pass_manager.py | 42 ++++++++++++++++--- ...asis-gates-transpile-e4b5893377f23acb.yaml | 17 ++++++++ .../transpiler/test_preset_passmanagers.py | 37 ++++++++++++++++ 3 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index 04516f4b0c6a..a267a3002377 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -17,7 +17,13 @@ import copy import warnings -from qiskit.circuit.controlflow import CONTROL_FLOW_OP_NAMES +from qiskit.circuit.controlflow import ( + CONTROL_FLOW_OP_NAMES, + IfElseOp, + WhileLoopOp, + ForLoopOp, + SwitchCaseOp, +) from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping from qiskit.circuit.quantumregister import Qubit from qiskit.providers.backend import Backend @@ -312,6 +318,7 @@ def generate_preset_pass_manager( _skip_target = ( target is None and backend is None + # Note: instruction_durations is deprecated and will be removed in 2.0 (no need for alternative) and (basis_gates is None or coupling_map is None or instruction_durations is not None) ) @@ -336,6 +343,7 @@ def generate_preset_pass_manager( # Only parse backend properties when the target isn't skipped to # preserve the former behavior of transpile. backend_properties = _parse_backend_properties(backend_properties, backend) + # Build target from constraints. target = Target.from_configuration( basis_gates=basis_gates, @@ -433,9 +441,14 @@ def generate_preset_pass_manager( def _parse_basis_gates(basis_gates, backend, inst_map, skip_target): name_mapping = {} standard_gates = get_standard_gate_name_mapping() - # Add control flow gates by default to basis set + # Add control flow gates by default to basis set and name mapping default_gates = {"measure", "delay", "reset"}.union(CONTROL_FLOW_OP_NAMES) - + name_mapping = { + "if_else": IfElseOp, + "while_loop": WhileLoopOp, + "for_loop": ForLoopOp, + "switch_case": SwitchCaseOp, + } try: instructions = set(basis_gates) for name in default_gates: @@ -450,7 +463,15 @@ def _parse_basis_gates(basis_gates, backend, inst_map, skip_target): return None, name_mapping, skip_target for inst in instructions: - if inst not in standard_gates or inst not in default_gates: + if inst not in standard_gates and inst not in default_gates: + warnings.warn( + category=DeprecationWarning, + message="Providing custom gates through the ``basis_gates`` argument is deprecated " + "for both ``transpile`` and ``generate_preset_pass_manager`` as of Qiskit 1.3.0. " + "It will be removed in Qiskit 2.0. The ``target`` parameter should be used instead. " + "You can build a target instance using ``Target.from_configuration()`` and provide" + "custom gate definitions with the ``custom_name_mapping`` argument.", + ) skip_target = True break @@ -463,7 +484,18 @@ def _parse_basis_gates(basis_gates, backend, inst_map, skip_target): # Check for custom instructions before removing calibrations for inst in instructions: - if inst not in standard_gates or inst not in default_gates: + if inst not in standard_gates and inst not in default_gates: + if inst not in backend.operation_names: + # do not raise warning when the custom instruction comes from the backend + # (common case with BasicSimulator) + warnings.warn( + category=DeprecationWarning, + message="Providing custom gates through the ``basis_gates`` argument is deprecated " + "for both ``transpile`` and ``generate_preset_pass_manager`` as of Qiskit 1.3.0. " + "It will be removed in Qiskit 2.0. The ``target`` parameter should be used instead. " + "You can build a target instance using ``Target.from_configuration()`` and provide" + "custom gate definitions with the ``custom_name_mapping`` argument.", + ) skip_target = True break diff --git a/releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml b/releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml new file mode 100644 index 000000000000..6b092fba6dfa --- /dev/null +++ b/releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml @@ -0,0 +1,17 @@ +--- +deprecations_transpiler: + - | + Providing custom gates through the ``basis_gates`` argument is deprecated + for both :func:`.transpile` and :func:`generate_preset_pass_manager`, this functionality + will be removed in Qiskit 2.0. Custom gates are still supported in the :class:`.Target` model, + and can be provided through the ``target`` argument. One can build a :class:`.Target` instance + from scratch or use the :meth:`.Target.from_configuration` method with the ``custom_name_mapping`` + argument. For example:: + from qiskit.circuit.library import XGate + from qiskit.transpiler.target import Target + + basis_gates = ["my_x", "cx"] + custom_name_mapping = {"my_x": XGate()} + target = Target.from_configuration( + basis_gates=basis_gates, num_qubits=2, custom_name_mapping=custom_name_mapping + ) \ No newline at end of file diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index 7bc23b01e841..04d127449fe2 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -1735,3 +1735,40 @@ def test_unsupported_targets_raise(self, optimization_level): pass with self.assertRaisesRegex(TranspilerError, "The control-flow construct.*not supported"): transpile(qc, target=target, optimization_level=optimization_level) + + @data(0, 1, 2, 3) + def test_custom_basis_gates_raise(self, optimization_level): + """Test that trying to provide a list of custom basis gates to generate_preset_pass_manager + raises a deprecation warning.""" + + with self.subTest(msg="no warning"): + # check that the warning isn't raised if the basis gates aren't custom + basis_gates = ["x", "cx"] + _ = generate_preset_pass_manager( + optimization_level=optimization_level, basis_gates=basis_gates + ) + + with self.subTest(msg="warning only basis gates"): + # check that the warning is raised if they are custom + basis_gates = ["my_gate"] + with self.assertWarnsRegex( + DeprecationWarning, + "Providing custom gates through the ``basis_gates`` argument is deprecated", + ): + _ = generate_preset_pass_manager( + optimization_level=optimization_level, basis_gates=basis_gates + ) + + with self.subTest(msg="no warning custom basis gates in backend"): + # check that the warning is not raised if a loose custom gate is found in the backend + backend = GenericBackendV2(num_qubits=2) + gate = Gate(name="my_gate", num_qubits=1, params=[]) + backend.target.add_instruction(gate) + self.assertEqual( + backend.operation_names, + ["cx", "id", "rz", "sx", "x", "reset", "delay", "measure", "my_gate"], + ) + basis_gates = ["my_gate"] + _ = generate_preset_pass_manager( + optimization_level=optimization_level, basis_gates=basis_gates, backend=backend + ) From 02c529554c13990455362ea6fd558e414ebdbe0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 5 Nov 2024 11:39:35 +0100 Subject: [PATCH 2/7] Filter from_configuration warning inside generate_preset_pm --- .../generate_preset_pass_manager.py | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index a267a3002377..a91b9de18e4c 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -343,24 +343,31 @@ def generate_preset_pass_manager( # Only parse backend properties when the target isn't skipped to # preserve the former behavior of transpile. backend_properties = _parse_backend_properties(backend_properties, backend) - - # Build target from constraints. - target = Target.from_configuration( - basis_gates=basis_gates, - num_qubits=backend.num_qubits if backend is not None else None, - coupling_map=coupling_map, - # If the instruction map has custom gates, do not give as config, the information - # will be added to the target with update_from_instruction_schedule_map - inst_map=inst_map if inst_map and not inst_map.has_custom_gate() else None, - backend_properties=backend_properties, - instruction_durations=instruction_durations, - concurrent_measurements=( - backend.target.concurrent_measurements if backend is not None else None - ), - dt=dt, - timing_constraints=timing_constraints, - custom_name_mapping=name_mapping, - ) + with warnings.catch_warnings(): + # TODO: inst_map will be removed in 2.0 + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``inst_map`` is deprecated as of Qiskit 1.3.*", + module="qiskit", + ) + # Build target from constraints. + target = Target.from_configuration( + basis_gates=basis_gates, + num_qubits=backend.num_qubits if backend is not None else None, + coupling_map=coupling_map, + # If the instruction map has custom gates, do not give as config, the information + # will be added to the target with update_from_instruction_schedule_map + inst_map=inst_map if inst_map and not inst_map.has_custom_gate() else None, + backend_properties=backend_properties, + instruction_durations=instruction_durations, + concurrent_measurements=( + backend.target.concurrent_measurements if backend is not None else None + ), + dt=dt, + timing_constraints=timing_constraints, + custom_name_mapping=name_mapping, + ) # Update target with custom gate information. Note that this is an exception to the priority # order (target > loose constraints), added to handle custom gates for scheduling passes. From c4fffc34db6db8701fc4b3d67f588561ea196bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 5 Nov 2024 13:10:42 +0100 Subject: [PATCH 3/7] Fix reno --- .../deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml b/releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml index 6b092fba6dfa..e2e794e96708 100644 --- a/releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml +++ b/releasenotes/notes/deprecate-custom-basis-gates-transpile-e4b5893377f23acb.yaml @@ -7,6 +7,7 @@ deprecations_transpiler: and can be provided through the ``target`` argument. One can build a :class:`.Target` instance from scratch or use the :meth:`.Target.from_configuration` method with the ``custom_name_mapping`` argument. For example:: + from qiskit.circuit.library import XGate from qiskit.transpiler.target import Target From 8b46de7f0622eddc4075541cac48a1ec0760aec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 5 Nov 2024 18:22:44 +0100 Subject: [PATCH 4/7] Apply comments from Eli's code review. Refactor qsd code not to use transpile internally --- qiskit/compiler/transpiler.py | 33 +++++++++++++++++-- qiskit/synthesis/unitary/qsd.py | 7 ++-- .../generate_preset_pass_manager.py | 1 - .../transpiler/test_preset_passmanagers.py | 22 +++++++++---- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index bda22cbbc4b8..d4f87d2da1bb 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -394,9 +394,38 @@ def callback_func(**kwargs): # Edge cases require using the old model (loose constraints) instead of building a target, # but we don't populate the passmanager config with loose constraints unless it's one of # the known edge cases to control the execution path. + # Filter instruction_durations, timing_constraints, backend_properties and inst_map deprecation with warnings.catch_warnings(): - warnings.simplefilter(action="ignore", category=DeprecationWarning) - # Filter instruction_durations, timing_constraints and backend_properties deprecation + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``inst_map`` is deprecated as of Qiskit 1.3.*", + module="qiskit", + ) + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``timing_constraints`` is deprecated as of Qiskit 1.3.*", + module="qiskit", + ) + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``instruction_durations`` is deprecated as of Qiskit 1.3.*", + module="qiskit", + ) + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``backend_properties`` is deprecated as of Qiskit 1.3.*", + module="qiskit", + ) + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``qiskit.transpiler.target.target_to_backend_properties()`` is deprecated as of qiskit 1.2.*", + module="qiskit", + ) pm = generate_preset_pass_manager( optimization_level, target=target, diff --git a/qiskit/synthesis/unitary/qsd.py b/qiskit/synthesis/unitary/qsd.py index 12e8fc0f9f7a..ab0f84ac72a4 100644 --- a/qiskit/synthesis/unitary/qsd.py +++ b/qiskit/synthesis/unitary/qsd.py @@ -251,14 +251,13 @@ def _get_ucry_cz(nqubits, angles): def _apply_a2(circ): - from qiskit.compiler import transpile from qiskit.quantum_info import Operator from qiskit.circuit.library.generalized_gates.unitary import UnitaryGate + from qiskit.transpiler.passes.synthesis import HighLevelSynthesis decomposer = two_qubit_decompose_up_to_diagonal - ccirc = transpile( - circ, basis_gates=["u", "cx", "qsd2q"], optimization_level=0, qubits_initially_zero=False - ) + hls = HighLevelSynthesis(basis_gates=["u", "cx", "qsd2q"], qubits_initially_zero=False) + ccirc = hls(circ) ind2q = [] # collect 2q instrs for i, instruction in enumerate(ccirc.data): diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index a91b9de18e4c..526ca4e02cc0 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -446,7 +446,6 @@ def generate_preset_pass_manager( def _parse_basis_gates(basis_gates, backend, inst_map, skip_target): - name_mapping = {} standard_gates = get_standard_gate_name_mapping() # Add control flow gates by default to basis set and name mapping default_gates = {"measure", "delay", "reset"}.union(CONTROL_FLOW_OP_NAMES) diff --git a/test/python/transpiler/test_preset_passmanagers.py b/test/python/transpiler/test_preset_passmanagers.py index 04d127449fe2..ce88f49560ed 100644 --- a/test/python/transpiler/test_preset_passmanagers.py +++ b/test/python/transpiler/test_preset_passmanagers.py @@ -161,7 +161,11 @@ def test_unitary_is_preserved_if_in_basis(self, level): qc = QuantumCircuit(2) qc.unitary(random_unitary(4, seed=42), [0, 1]) qc.measure_all() - result = transpile(qc, basis_gates=["cx", "u", "unitary"], optimization_level=level) + with self.assertWarnsRegex( + DeprecationWarning, + "Providing custom gates through the ``basis_gates`` argument is deprecated", + ): + result = transpile(qc, basis_gates=["cx", "u", "unitary"], optimization_level=level) self.assertEqual(result, qc) @combine(level=[0, 1, 2, 3], name="level{level}") @@ -179,12 +183,16 @@ def test_unitary_is_preserved_if_in_basis_synthesis_translation(self, level): qc = QuantumCircuit(2) qc.unitary(random_unitary(4, seed=424242), [0, 1]) qc.measure_all() - result = transpile( - qc, - basis_gates=["cx", "u", "unitary"], - optimization_level=level, - translation_method="synthesis", - ) + with self.assertWarnsRegex( + DeprecationWarning, + "Providing custom gates through the ``basis_gates`` argument is deprecated", + ): + result = transpile( + qc, + basis_gates=["cx", "u", "unitary"], + optimization_level=level, + translation_method="synthesis", + ) self.assertEqual(result, qc) @combine(level=[0, 1, 2, 3], name="level{level}") From 1cf5a8511789ec8d3337bfbb5a544bb0ca63d154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 5 Nov 2024 19:32:36 +0100 Subject: [PATCH 5/7] Add filter for target to backend props --- qiskit/compiler/transpiler.py | 6 ------ .../generate_preset_pass_manager.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/qiskit/compiler/transpiler.py b/qiskit/compiler/transpiler.py index d4f87d2da1bb..27de0a7e1811 100644 --- a/qiskit/compiler/transpiler.py +++ b/qiskit/compiler/transpiler.py @@ -420,12 +420,6 @@ def callback_func(**kwargs): message=".*``backend_properties`` is deprecated as of Qiskit 1.3.*", module="qiskit", ) - warnings.filterwarnings( - "ignore", - category=DeprecationWarning, - message=".*``qiskit.transpiler.target.target_to_backend_properties()`` is deprecated as of qiskit 1.2.*", - module="qiskit", - ) pm = generate_preset_pass_manager( optimization_level, target=target, diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index 526ca4e02cc0..0baae82fd8ef 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -526,8 +526,15 @@ def _parse_inst_map(inst_map, backend): def _parse_backend_properties(backend_properties, backend): # try getting backend_props from user, else backend if backend_properties is None and backend is not None: - backend_properties = target_to_backend_properties(backend.target) - return backend_properties + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``qiskit.transpiler.target.target_to_backend_properties()`` is deprecated as of qiskit 1.2.*", + module="qiskit", + ) + backend_properties = target_to_backend_properties(backend.target) + return backend_properties def _parse_dt(dt, backend): From 8058f344ddff58c38b910edf2cee6dbd464ea9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Wed, 6 Nov 2024 11:09:14 +0100 Subject: [PATCH 6/7] Handle additional warnings triggered in tests --- qiskit/pulse/instruction_schedule_map.py | 20 ++++++++++++++----- .../generate_preset_pass_manager.py | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/qiskit/pulse/instruction_schedule_map.py b/qiskit/pulse/instruction_schedule_map.py index 2815a9897db0..75ce3b8ef755 100644 --- a/qiskit/pulse/instruction_schedule_map.py +++ b/qiskit/pulse/instruction_schedule_map.py @@ -169,12 +169,22 @@ def assert_has( """ instruction = _get_instruction_string(instruction) if not self.has(instruction, _to_tuple(qubits)): - if instruction in self._map: - raise PulseError( - f"Operation '{instruction}' exists, but is only defined for qubits " - f"{self.qubits_with_instruction(instruction)}." + # TODO: PulseError is deprecated, this code will be removed in 2.0. + # In the meantime, we catch the deprecation + # warning not to overload users with non-actionable messages + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*The entire Qiskit Pulse package*", + module="qiskit", ) - raise PulseError(f"Operation '{instruction}' is not defined for this system.") + if instruction in self._map: + raise PulseError( + f"Operation '{instruction}' exists, but is only defined for qubits " + f"{self.qubits_with_instruction(instruction)}." + ) + raise PulseError(f"Operation '{instruction}' is not defined for this system.") def get( self, diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index 0baae82fd8ef..310397ad958f 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -527,10 +527,11 @@ def _parse_backend_properties(backend_properties, backend): # try getting backend_props from user, else backend if backend_properties is None and backend is not None: with warnings.catch_warnings(): + # filter target_to_backend_properties warning warnings.filterwarnings( "ignore", category=DeprecationWarning, - message=".*``qiskit.transpiler.target.target_to_backend_properties()`` is deprecated as of qiskit 1.2.*", + message=".*``qiskit.transpiler.target.target_to_backend_properties\\(\\)`` is deprecated as of qiskit 1.2.*", module="qiskit", ) backend_properties = target_to_backend_properties(backend.target) From 3863549910b561bdfc5048268173a2fe28ef7672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Wed, 6 Nov 2024 12:12:27 +0100 Subject: [PATCH 7/7] Handle sneaky warnings. Not sure why they weren't triggered before. --- .../generate_preset_pass_manager.py | 4 +- qiskit/transpiler/target.py | 26 ++++++--- test/python/compiler/test_transpiler.py | 54 ++++++++++++++----- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py index 310397ad958f..2874b186666e 100644 --- a/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +++ b/qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py @@ -531,11 +531,11 @@ def _parse_backend_properties(backend_properties, backend): warnings.filterwarnings( "ignore", category=DeprecationWarning, - message=".*``qiskit.transpiler.target.target_to_backend_properties\\(\\)`` is deprecated as of qiskit 1.2.*", + message=".*``qiskit.transpiler.target.target_to_backend_properties\\(\\)``.*", module="qiskit", ) backend_properties = target_to_backend_properties(backend.target) - return backend_properties + return backend_properties def _parse_dt(dt, backend): diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 1edc89013572..fb15a8039d3c 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -1156,9 +1156,16 @@ def from_configuration( if error is None and duration is None and calibration is None: gate_properties[(qubit,)] = None else: - gate_properties[(qubit,)] = InstructionProperties( - duration=duration, error=error, calibration=calibration - ) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``calibration`` is deprecated as of Qiskit 1.3.*", + module="qiskit", + ) + gate_properties[(qubit,)] = InstructionProperties( + duration=duration, error=error, calibration=calibration + ) target.add_instruction(name_mapping[gate], properties=gate_properties, name=gate) edges = list(coupling_map.get_edges()) for gate in two_qubit_gates: @@ -1198,9 +1205,16 @@ def from_configuration( if error is None and duration is None and calibration is None: gate_properties[edge] = None else: - gate_properties[edge] = InstructionProperties( - duration=duration, error=error, calibration=calibration - ) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + message=".*``calibration`` is deprecated as of Qiskit 1.3.*", + module="qiskit", + ) + gate_properties[edge] = InstructionProperties( + duration=duration, error=error, calibration=calibration + ) target.add_instruction(name_mapping[gate], properties=gate_properties, name=gate) for gate in global_ideal_variable_width_gates: target.add_instruction(name_mapping[gate], name=gate) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 5241304a0db4..851117671ef3 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -3797,13 +3797,26 @@ def test_triple_circuit_invalid_layout(self, routing_method): DeprecationWarning, expected_regex="The `target` parameter should be used instead", ): - transpile( - qc, - self.backend, - layout_method="trivial", - routing_method=routing_method, - seed_transpiler=42, - ) + if routing_method == "stochastic": + with self.assertWarnsRegex( + DeprecationWarning, + expected_regex="The StochasticSwap transpilation pass is a suboptimal", + ): + transpile( + qc, + self.backend, + layout_method="trivial", + routing_method=routing_method, + seed_transpiler=42, + ) + else: + transpile( + qc, + self.backend, + layout_method="trivial", + routing_method=routing_method, + seed_transpiler=42, + ) @data("stochastic") def test_triple_circuit_invalid_layout_stochastic(self, routing_method): @@ -3842,13 +3855,26 @@ def test_triple_circuit_invalid_layout_stochastic(self, routing_method): qc.cy(20, 29) qc.measure_all() with self.assertRaises(TranspilerError): - transpile( - qc, - self.backend, - layout_method="trivial", - routing_method=routing_method, - seed_transpiler=42, - ) + if routing_method == "stochastic": + with self.assertWarnsRegex( + DeprecationWarning, + expected_regex="The StochasticSwap transpilation pass is a suboptimal", + ): + transpile( + qc, + self.backend, + layout_method="trivial", + routing_method=routing_method, + seed_transpiler=42, + ) + else: + transpile( + qc, + self.backend, + layout_method="trivial", + routing_method=routing_method, + seed_transpiler=42, + ) # Lookahead swap skipped for performance reasons, stochastic moved to new test due to deprecation @data("sabre", "basic")