Skip to content

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

Merged
merged 24 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e951c87
Add ActOnStabilizerCHFormArgs and related logic
smitsanghavi Aug 10, 2020
d830c9f
Merge branch 'master' into actch
smitsanghavi Aug 10, 2020
871860b
Some comment updates
smitsanghavi Aug 10, 2020
b01cb53
Fix _update_sum call
smitsanghavi Aug 10, 2020
6428bec
Update parameterized condition
smitsanghavi Aug 11, 2020
eba031d
Merge branch 'master' into actch
smitsanghavi Aug 21, 2020
50dab1f
Undo already split out change to stabilizerstatechfrom
smitsanghavi Sep 11, 2020
e49ec00
Merge branch 'master' into actch
smitsanghavi Sep 11, 2020
0ff6fd3
revert split out change
smitsanghavi Sep 11, 2020
2ce0ac5
Merge branch 'master' into actch
smitsanghavi Sep 22, 2020
df6cda3
Merge and clean
smitsanghavi Sep 22, 2020
ef8e70d
Improve error handling and documentation
smitsanghavi Sep 28, 2020
2afb08f
Merge branch 'master' into actch
smitsanghavi Sep 28, 2020
d3578de
Add comments with reference to the relevant sections of the paper
smitsanghavi Oct 13, 2020
e01317f
Merge branch 'master' into actch
smitsanghavi Oct 13, 2020
9e452d6
Fix the year in copyright
smitsanghavi Oct 21, 2020
c676f20
Use H instead of HPowGate()
smitsanghavi Oct 21, 2020
f6a93d3
Merge branch 'master' into actch
smitsanghavi Oct 21, 2020
02a08a5
Merge branch 'actch' of https://github.com/smitsanghavi/Cirq-1 into a…
smitsanghavi Oct 21, 2020
e4c49a0
Address comments
smitsanghavi Oct 26, 2020
e421f1b
Merge branch 'master' into actch
smitsanghavi Oct 26, 2020
790ec29
Merge branch 'master' into actch
CirqBot Oct 27, 2020
d54bcc8
Hide traceback and correct copyright year
smitsanghavi Oct 28, 2020
e612071
Merge branch 'actch' of https://github.com/smitsanghavi/Cirq-1 into a…
smitsanghavi Oct 28, 2020
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
111 changes: 108 additions & 3 deletions cirq/ops/common_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ 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
if H._act_on_(args) is True:
if ZPowGate(exponent=self._exponent)._act_on_(args) is True:
if H._act_on_(args) is True:
return True
# At least one, but not all, of the delegated _act_on_
# succeeded, so the state might have been corrupted, return
# False instead of NotImplemented.
return False # coverage: ignore

return NotImplemented

def in_su2(self) -> 'XPowGate':
Expand Down Expand Up @@ -322,6 +334,43 @@ 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:
if ZPowGate()._act_on_(args) is True:
if H._act_on_(args) is True:
state.omega *= (1 + 1j) / (2**0.5) # type: ignore
return True
# Only one of the delegated _act_on_ succeeded, so the
# state might have been corrupted, return False instead of
# NotImplemented.
return False # coverage: ignore
elif effective_exponent == 1:
if ZPowGate()._act_on_(args) is True:
if H._act_on_(args) is True:
if ZPowGate()._act_on_(args) is True:
if H._act_on_(args) is True:
state.omega *= 1j # type: ignore
return True
# At least one, but not all, of the delegated _act_on_
# succeeded, so the state might have been corrupted, return
# False instead of NotImplemented.
return False # coverage: ignore
elif effective_exponent == 1.5:
if H._act_on_(args) is True:
if ZPowGate()._act_on_(args) is True:
state.omega *= (1 - 1j) / (2**0.5) # type: ignore
return True
# Only one of the delegated _act_on_ succeeded, so the
# state might have been corrupted, return False instead of
# NotImplemented.
return False # coverage: ignore
else:
return True

return NotImplemented

def in_su2(self) -> 'YPowGate':
Expand Down Expand Up @@ -490,6 +539,17 @@ 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)):
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):
Expand Down Expand Up @@ -756,18 +816,37 @@ 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:
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):
Expand Down Expand Up @@ -900,6 +979,17 @@ 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:
state.M[q1, :] ^= state.G[q2, :]
state.M[q2, :] ^= state.G[q1, :]
return True

return NotImplemented

def _pauli_expansion_(self) -> value.LinearDict[str]:
Expand Down Expand Up @@ -1098,6 +1188,21 @@ 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:
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]:
Expand Down
Loading