Skip to content

Commit c04dd6e

Browse files
authored
Add _act_on_ for StabilizerStateChForm to GlobalPhaseOp (#3448)
#2948 #2423
1 parent e4c191d commit c04dd6e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cirq/ops/global_phase_op.py

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ def _apply_unitary_(self, args) -> np.ndarray:
5959
args.target_tensor *= self.coefficient
6060
return args.target_tensor
6161

62+
def _act_on_(self, args: Any):
63+
from cirq.sim import clifford
64+
if isinstance(args, clifford.ActOnStabilizerCHFormArgs):
65+
args.state.omega *= self.coefficient # type: ignore
66+
return True
67+
68+
return NotImplemented
69+
6270
def __str__(self) -> str:
6371
return str(self.coefficient)
6472

cirq/ops/global_phase_op_test.py

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def test_protocols():
4040
atol=1e-8)
4141

4242

43+
@pytest.mark.parametrize('phase', [1, 1j, -1])
44+
def test_act_on(phase):
45+
state = cirq.StabilizerStateChForm(0)
46+
args = cirq.ActOnStabilizerCHFormArgs(state, [])
47+
cirq.act_on(cirq.GlobalPhaseOperation(phase), args, allow_decompose=False)
48+
assert state.state_vector() == [[phase]]
49+
50+
4351
def test_str():
4452
assert str(cirq.GlobalPhaseOperation(1j)) == '1j'
4553

0 commit comments

Comments
 (0)