diff --git a/cirq-core/cirq/ops/parity_gates.py b/cirq-core/cirq/ops/parity_gates.py index 1839260d035..5d25e1b3dcd 100644 --- a/cirq-core/cirq/ops/parity_gates.py +++ b/cirq-core/cirq/ops/parity_gates.py @@ -296,6 +296,9 @@ def _apply_unitary_(self, args: 'protocols.ApplyUnitaryArgs') -> Optional[np.nda return args.target_tensor + def _phase_by_(self, phase_turns: float, qubit_index: int) -> "ZZPowGate": + return self + def __str__(self) -> str: if self._exponent == 1: return 'ZZ' diff --git a/cirq-core/cirq/ops/parity_gates_test.py b/cirq-core/cirq/ops/parity_gates_test.py index b8c60e116f7..02ed17083e7 100644 --- a/cirq-core/cirq/ops/parity_gates_test.py +++ b/cirq-core/cirq/ops/parity_gates_test.py @@ -195,6 +195,12 @@ def test_zz_pow(): assert (cirq.ZZ**-1) ** 0.5 == cirq.ZZ**-0.5 +def test_zz_phase_by(): + assert cirq.phase_by(cirq.ZZ, 0.25, 0) == cirq.phase_by(cirq.ZZ, 0.25, 1) == cirq.ZZ + assert cirq.phase_by(cirq.ZZ**0.5, 0.25, 0) == cirq.ZZ**0.5 + assert cirq.phase_by(cirq.ZZ**-0.5, 0.25, 1) == cirq.ZZ**-0.5 + + def test_zz_str(): assert str(cirq.ZZ) == 'ZZ' assert str(cirq.ZZ**0.5) == 'ZZ**0.5'