Skip to content
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

Measure using StabilizerStateChForm #3564

Merged
merged 10 commits into from
Dec 15, 2020
2 changes: 1 addition & 1 deletion cirq/sim/clifford/clifford_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def perform_measurement(
state = self.copy()

for qubit in qubits:
result = state.tableau._measure(self.qubit_map[qubit], prng)
result = state.ch_form._measure(self.qubit_map[qubit], prng)
state.ch_form.project_Z(self.qubit_map[qubit], result)
results.append(result)

Expand Down
13 changes: 13 additions & 0 deletions cirq/sim/clifford/stabilizer_state_ch_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ def to_state_vector(self) -> np.ndarray:

return arr

def _measure(self, q, prng: np.random.RandomState) -> int:
"""Measures the q'th qubit.

Reference: Section 4.1 "Simulating measurements"

Returns: Computational basis measurement as 0 or 1.
"""
w = self.s.copy()
for i, v_i in enumerate(self.v):
if v_i == 1:
w[i] = bool(prng.randint(2))
balopat marked this conversation as resolved.
Show resolved Hide resolved
return sum(w & self.G[q, :]) % 2

def project_Z(self, q, z):
"""Applies a Z projector on the q'th qubit.

Expand Down