Skip to content

Deprecate NormalizeRXAngle and rzx_templates #13883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions qiskit/transpiler/passes/calibration/rzx_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@

from enum import Enum
from typing import List, Dict
from qiskit.utils import deprecate_func

from qiskit.circuit.library.templates import rzx


@deprecate_func(
since="1.4",
removal_timeline="in Qiskit 2.0",
additional_msg="Use the functions in "
"qiskit.circuit.library.templates.rzx instead to generate rzx templates",
)
def rzx_templates(template_list: List[str] = None) -> Dict:
"""Convenience function to get the cost_dict and templates for template matching.

Expand Down
8 changes: 8 additions & 0 deletions qiskit/transpiler/passes/optimization/normalize_rx_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import numpy as np

from qiskit.utils import deprecate_func

from qiskit.transpiler.basepasses import TransformationPass
from qiskit.dagcircuit import DAGCircuit
from qiskit.circuit.library.standard_gates import RXGate, RZGate, SXGate, XGate
Expand Down Expand Up @@ -48,6 +50,12 @@ class NormalizeRXAngle(TransformationPass):
Note that pulse calibration might be attached per each rotation angle.
"""

@deprecate_func(
since="1.4",
removal_timeline="in Qiskit 2.0",
additional_msg="This pass was used as pre-processing step of ``RXCalibrationBuilder``."
" With the removal of Pulse in Qiskit 2.0, this pass is no longer needed.",
)
def __init__(self, target=None, resolution_in_radian=0):
"""NormalizeRXAngle initializer.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
deprecations_transpiler:
- |
As part of Pulse deprecation in version 1.3, the calibration builder passes
were also deprecated and in particular :class:`.RXCalibrationBuilder`. The
:class:`.NormalizeRXAngle` pass is a requirement of :class:`.RXCalibrationBuilder`
hence it should also be deprecated. In addition, the :func:`.rzx_templates`
function in the calibration module is being deprecated as it is not used.
15 changes: 10 additions & 5 deletions test/python/transpiler/test_normalize_rx_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def test_not_convert_to_x_if_no_calib_in_target(self):
"""Check that RX(pi) is NOT converted to X,
if X calibration is not present in the target"""
empty_target = Target()
tp = NormalizeRXAngle(target=empty_target)
with self.assertWarns(DeprecationWarning):
tp = NormalizeRXAngle(target=empty_target)

qc = QuantumCircuit(1)
qc.rx(90, 0)
Expand All @@ -47,7 +48,8 @@ def test_sx_conversion_works(self):
if SX calibration is present in the target"""
target = Target()
target.add_instruction(SXGate(), properties={(0,): None})
tp = NormalizeRXAngle(target=target)
with self.assertWarns(DeprecationWarning):
tp = NormalizeRXAngle(target=target)

qc = QuantumCircuit(1)
qc.rx(np.pi / 2, 0)
Expand All @@ -60,7 +62,8 @@ def test_rz_added_for_negative_rotation_angles(self):
if RX rotation angle is negative"""

backend = GenericBackendV2(num_qubits=5)
tp = NormalizeRXAngle(target=backend.target)
with self.assertWarns(DeprecationWarning):
tp = NormalizeRXAngle(target=backend.target)

# circuit to transpile and test
qc = QuantumCircuit(1)
Expand All @@ -83,7 +86,8 @@ def test_rz_added_for_negative_rotation_angles(self):
def test_angle_wrapping_works(self, raw_theta, correct_wrapped_theta):
"""Check that RX rotation angles are correctly wrapped to [0, pi]"""
backend = GenericBackendV2(num_qubits=5)
tp = NormalizeRXAngle(target=backend.target)
with self.assertWarns(DeprecationWarning):
tp = NormalizeRXAngle(target=backend.target)

# circuit to transpile and test
qc = QuantumCircuit(1)
Expand Down Expand Up @@ -118,7 +122,8 @@ def test_quantize_angles(self, resolution, rx_angles, correct_num_of_cals):
the requested angle is not in the vicinity of the already generated angles.
"""
backend = GenericBackendV2(num_qubits=5)
tp = NormalizeRXAngle(backend.target, resolution_in_radian=resolution)
with self.assertWarns(DeprecationWarning):
tp = NormalizeRXAngle(backend.target, resolution_in_radian=resolution)

qc = QuantumCircuit(1)
for rx_angle in rx_angles:
Expand Down
3 changes: 2 additions & 1 deletion test/python/transpiler/test_template_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ def test_unbound_parameters_in_rzx_template(self):
circuit_in.p(2 * theta, 1)
circuit_in.cx(0, 1)

pass_ = TemplateOptimization(**rzx_templates(["zz2"]))
with self.assertWarns(DeprecationWarning):
pass_ = TemplateOptimization(**rzx_templates(["zz2"]))
circuit_out = PassManager(pass_).run(circuit_in)

# these are NOT equal if template optimization works
Expand Down