Skip to content

Commit

Permalink
add _phase_by_ method to ZZPowGate (#6062)
Browse files Browse the repository at this point in the history
  • Loading branch information
richrines1 committed Apr 14, 2023
1 parent 8ac690d commit ee2d32a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/parity_gates.py
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions cirq-core/cirq/ops/parity_gates_test.py
Expand Up @@ -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'
Expand Down

0 comments on commit ee2d32a

Please sign in to comment.