-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support ActOnStabilizerCHFormArgs in the common gates and testing #3203
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
Changes from 15 commits
e951c87
d830c9f
871860b
b01cb53
6428bec
eba031d
50dab1f
e49ec00
0ff6fd3
2ce0ac5
df6cda3
ef8e70d
2afb08f
d3578de
e01317f
9e452d6
c676f20
f6a93d3
02a08a5
e4c49a0
e421f1b
790ec29
d54bcc8
e612071
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,16 @@ def _act_on_(self, args: Any): | |
tableau.xs[:, q] ^= tableau.zs[:, q] | ||
return True | ||
|
||
if isinstance(args, clifford.ActOnStabilizerCHFormArgs): | ||
if protocols.is_parameterized(self) or self.exponent % 0.5 != 0: | ||
return NotImplemented | ||
assert all( | ||
gate._act_on_(args) for gate in # type: ignore | ||
[HPowGate(), | ||
ZPowGate(exponent=self._exponent), | ||
HPowGate()]) | ||
return True | ||
|
||
return NotImplemented | ||
|
||
def in_su2(self) -> 'XPowGate': | ||
|
@@ -322,6 +332,29 @@ def _act_on_(self, args: Any): | |
tableau.xs[:, q].copy()) | ||
return True | ||
|
||
if isinstance(args, clifford.ActOnStabilizerCHFormArgs): | ||
if protocols.is_parameterized(self) or self.exponent % 0.5 != 0: | ||
return NotImplemented | ||
effective_exponent = self._exponent % 2 | ||
state = args.state | ||
if effective_exponent == 0.5: | ||
assert all( | ||
gate._act_on_(args) # type: ignore | ||
for gate in [ZPowGate(), HPowGate()]) | ||
state.omega *= (1 + 1j) / (2**0.5) # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the type ignore needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mypy assumes state.omega is an int since it was initialized by an int. It complains when I try to assign a complex value to it. Maybe adding |
||
elif effective_exponent == 1: | ||
assert all( | ||
gate._act_on_(args) for gate in # type: ignore | ||
[ZPowGate(), HPowGate(), | ||
ZPowGate(), HPowGate()]) | ||
state.omega *= 1j # type: ignore | ||
elif effective_exponent == 1.5: | ||
assert all( | ||
gate._act_on_(args) # type: ignore | ||
for gate in [HPowGate(), ZPowGate()]) | ||
state.omega *= (1 - 1j) / (2**0.5) # type: ignore | ||
balopat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return True | ||
|
||
return NotImplemented | ||
|
||
def in_su2(self) -> 'YPowGate': | ||
|
@@ -490,6 +523,19 @@ def _act_on_(self, args: Any): | |
tableau.zs[:, q] ^= tableau.xs[:, q] | ||
return True | ||
|
||
if isinstance(args, clifford.ActOnStabilizerCHFormArgs): | ||
if protocols.is_parameterized(self) or self.exponent % 0.5 != 0: | ||
return NotImplemented | ||
q = args.axes[0] | ||
effective_exponent = self._exponent % 2 | ||
state = args.state | ||
for _ in range(int(effective_exponent * 2)): | ||
# Prescription for S left multiplication. | ||
# Reference: https://arxiv.org/abs/1808.00128 Proposition 4 end | ||
state.M[q, :] ^= state.G[q, :] | ||
state.gamma[q] = (state.gamma[q] - 1) % 4 | ||
return True | ||
|
||
return NotImplemented | ||
|
||
def _decompose_into_clifford_with_qubits_(self, qubits): | ||
|
@@ -756,18 +802,40 @@ def _act_on_(self, args: Any): | |
from cirq.sim import clifford | ||
|
||
if isinstance(args, clifford.ActOnCliffordTableauArgs): | ||
if protocols.is_parameterized(self) or self.exponent % 0.5 != 0: | ||
if protocols.is_parameterized(self) or self.exponent % 1 != 0: | ||
return NotImplemented | ||
tableau = args.tableau | ||
q = args.axes[0] | ||
if self._exponent % 1 != 0: | ||
return NotImplemented | ||
if self._exponent % 2 == 1: | ||
(tableau.xs[:, q], tableau.zs[:, q]) = (tableau.zs[:, q].copy(), | ||
tableau.xs[:, q].copy()) | ||
tableau.rs[:] ^= (tableau.xs[:, q] & tableau.zs[:, q]) | ||
return True | ||
|
||
if isinstance(args, clifford.ActOnStabilizerCHFormArgs): | ||
if protocols.is_parameterized(self) or self.exponent % 1 != 0: | ||
return NotImplemented | ||
q = args.axes[0] | ||
state = args.state | ||
if self._exponent % 2 == 1: | ||
# Prescription for H left multiplication | ||
# Reference: https://arxiv.org/abs/1808.00128 | ||
# Equations 48, 49 and Proposition 4 | ||
t = state.s ^ (state.G[q, :] & state.v) | ||
u = state.s ^ (state.F[q, :] & | ||
(~state.v)) ^ (state.M[q, :] & state.v) | ||
|
||
alpha = sum(state.G[q, :] & (~state.v) & state.s) % 2 | ||
beta = sum(state.M[q, :] & (~state.v) & state.s) | ||
beta += sum(state.F[q, :] & state.v & state.M[q, :]) | ||
beta += sum(state.F[q, :] & state.v & state.s) | ||
beta %= 2 | ||
|
||
delta = (state.gamma[q] + 2 * (alpha + beta)) % 4 | ||
|
||
state.update_sum(t, u, delta=delta, alpha=alpha) | ||
return True | ||
|
||
return NotImplemented | ||
|
||
def _decompose_(self, qubits): | ||
|
@@ -900,6 +968,19 @@ def _act_on_(self, args: Any): | |
tableau.rs[:] ^= (tableau.xs[:, q2] & tableau.zs[:, q2]) | ||
return True | ||
|
||
if isinstance(args, clifford.ActOnStabilizerCHFormArgs): | ||
if protocols.is_parameterized(self) or self.exponent % 1 != 0: | ||
return NotImplemented | ||
q1 = args.axes[0] | ||
q2 = args.axes[1] | ||
state = args.state | ||
if self._exponent % 2 == 1: | ||
# Prescription for CZ left multiplication. | ||
# Reference: https://arxiv.org/abs/1808.00128 Proposition 4 end | ||
state.M[q1, :] ^= state.G[q2, :] | ||
state.M[q2, :] ^= state.G[q1, :] | ||
return True | ||
|
||
return NotImplemented | ||
|
||
def _pauli_expansion_(self) -> value.LinearDict[str]: | ||
|
@@ -1098,6 +1179,23 @@ def _act_on_(self, args: Any): | |
tableau.zs[:, q1] ^= tableau.zs[:, q2] | ||
return True | ||
|
||
if isinstance(args, clifford.ActOnStabilizerCHFormArgs): | ||
if protocols.is_parameterized(self) or self.exponent % 1 != 0: | ||
return NotImplemented | ||
q1 = args.axes[0] | ||
q2 = args.axes[1] | ||
state = args.state | ||
if self._exponent % 2 == 1: | ||
# Prescription for CZ left multiplication. | ||
smitsanghavi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Reference: https://arxiv.org/abs/1808.00128 Proposition 4 end | ||
state.gamma[q1] = ( | ||
state.gamma[q1] + state.gamma[q2] + 2 * | ||
(sum(state.M[q1, :] & state.F[q2, :]) % 2)) % 4 | ||
state.G[q2, :] ^= state.G[q1, :] | ||
state.F[q1, :] ^= state.F[q2, :] | ||
state.M[q1, :] ^= state.M[q2, :] | ||
return True | ||
|
||
return NotImplemented | ||
|
||
def _pauli_expansion_(self) -> value.LinearDict[str]: | ||
|
Uh oh!
There was an error while loading. Please reload this page.