diff --git a/cirq/ops/global_phase_op.py b/cirq/ops/global_phase_op.py index 576300a1350..9a2802d2224 100644 --- a/cirq/ops/global_phase_op.py +++ b/cirq/ops/global_phase_op.py @@ -59,6 +59,14 @@ def _apply_unitary_(self, args) -> np.ndarray: args.target_tensor *= self.coefficient return args.target_tensor + def _act_on_(self, args: Any): + from cirq.sim import clifford + if isinstance(args, clifford.ActOnStabilizerCHFormArgs): + args.state.omega *= self.coefficient # type: ignore + return True + + return NotImplemented + def __str__(self) -> str: return str(self.coefficient) diff --git a/cirq/ops/global_phase_op_test.py b/cirq/ops/global_phase_op_test.py index 12bbef97cd2..f2ae9049951 100644 --- a/cirq/ops/global_phase_op_test.py +++ b/cirq/ops/global_phase_op_test.py @@ -40,6 +40,14 @@ def test_protocols(): atol=1e-8) +@pytest.mark.parametrize('phase', [1, 1j, -1]) +def test_act_on(phase): + state = cirq.StabilizerStateChForm(0) + args = cirq.ActOnStabilizerCHFormArgs(state, []) + cirq.act_on(cirq.GlobalPhaseOperation(phase), args, allow_decompose=False) + assert state.state_vector() == [[phase]] + + def test_str(): assert str(cirq.GlobalPhaseOperation(1j)) == '1j'