Skip to content

Add _act_on_ for StabilizerStateChForm to GlobalPhaseOp #3448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cirq/ops/global_phase_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions cirq/ops/global_phase_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down