Skip to content

Commit

Permalink
Fix EjectPhasedPaulis incorrectly treating X**0 as X**1 (#4219)
Browse files Browse the repository at this point in the history
Fixes #4218 and adds a test for the previously failing case.

The code treated the half-turns (exponent) value as whole-turns so both X**1 and X**0 were treated as whole X gates.
  • Loading branch information
cduck committed Jun 17, 2021
1 parent 87f2961 commit 59d8018
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cirq-core/cirq/optimizers/eject_phased_paulis.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def optimize_circuit(self, circuit: circuits.Circuit):
# Collect, phase, and merge Ws.
w = _try_get_known_phased_pauli(op, no_symbolic=not self.eject_parameterized)
if w is not None:
if decompositions.is_negligible_turn(w[0] - 1, self.tolerance):
if decompositions.is_negligible_turn((w[0] - 1) / 2, self.tolerance):
_potential_cross_whole_w(moment_index, op, self.tolerance, state)
else:
_potential_cross_partial_w(moment_index, op, state)
Expand Down
13 changes: 13 additions & 0 deletions cirq-core/cirq/optimizers/eject_phased_paulis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,16 @@ def test_blocked_by_unknown_and_symbols(sym):
),
compare_unitaries=False,
)


def test_zero_x_rotation():
a = cirq.NamedQubit('a')

assert_optimizes(
before=quick_circuit(
[cirq.rx(0)(a)],
),
expected=quick_circuit(
[cirq.rx(0)(a)],
),
)

0 comments on commit 59d8018

Please sign in to comment.