Skip to content

Commit

Permalink
fix precision problems in _try_no_fuse
Browse files Browse the repository at this point in the history
  • Loading branch information
dwierichs committed Jul 24, 2024
1 parent 91b2f78 commit cf3e621
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pennylane/transforms/optimization/optimization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
arccos,
arctan2,
asarray,
cast_like,
cos,
is_abstract,
moveaxis,
Expand Down Expand Up @@ -57,9 +58,10 @@ def find_next_gate(wires, op_list):
def _try_no_fuse(angles1, angles2):
"""Try to combine rotation angles without trigonometric identities
if some angles in the input angles vanish."""
dummy_sum = angles1 + angles2
# moveaxis required for batched inputs
phi1, theta1, omega1 = moveaxis(asarray(angles1), -1, 0)
phi2, theta2, omega2 = moveaxis(asarray(angles2), -1, 0)
phi1, theta1, omega1 = moveaxis(cast_like(asarray(angles1), dummy_sum), -1, 0)
phi2, theta2, omega2 = moveaxis(cast_like(asarray(angles2), dummy_sum), -1, 0)

if allclose(omega1 + phi2, 0.0):
return stack([phi1, theta1 + theta2, omega2])
Expand Down

0 comments on commit cf3e621

Please sign in to comment.