Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix deprecated Numpy logic in NormalizeRXAngles #11023

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Changes from 1 commit
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
29 changes: 10 additions & 19 deletions qiskit/transpiler/passes/optimization/normalize_rx_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,16 @@ def quantize_angles(self, qubit, original_angle):
float: Quantized angle.
"""

# check if there is already a calibration for a simliar angle
try:
angles = self.already_generated[qubit] # 1d ndarray of already generated angles
similar_angle = angles[
np.isclose(angles, original_angle, atol=self.resolution_in_radian / 2)
]
quantized_angle = (
float(similar_angle[0]) if len(similar_angle) > 1 else float(similar_angle)
)
except KeyError:
quantized_angle = original_angle
self.already_generated[qubit] = np.array([quantized_angle])
except TypeError:
quantized_angle = original_angle
self.already_generated[qubit] = np.append(
self.already_generated[qubit], quantized_angle
)

return quantized_angle
if (angles := self.already_generated.get(qubit)) is None:
self.already_generated[qubit] = np.array([original_angle])
return original_angle
similar_angles = angles[
np.isclose(angles, original_angle, atol=self.resolution_in_radian / 2)
]
if similar_angles.size == 0:
self.already_generated[qubit] = np.append(angles, original_angle)
return original_angle
return float(angles[0])

def run(self, dag):
"""Run the NormalizeRXAngle pass on ``dag``.
Expand Down