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

Fix stimcirq failing to round trip stim's example surface code circuit #874

Merged
merged 1 commit into from
Jan 27, 2025
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
14 changes: 13 additions & 1 deletion glue/cirq/stimcirq/_cirq_to_stim_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def test_on_tagged_loop():
repetitions=3,
).with_tags('my_tag')
)

stim_circuit = stimcirq.cirq_circuit_to_stim_circuit(c)
assert stim.CircuitRepeatBlock in {type(instr) for instr in stim_circuit}

Expand Down Expand Up @@ -410,3 +410,15 @@ def test_custom_tagging():
H[PAIR] 0
TICK
""")


def test_round_trip_example_circuit():
stim_circuit = stim.Circuit.generated(
"surface_code:rotated_memory_x",
distance=3,
rounds=1,
after_clifford_depolarization=0.01,
)
cirq_circuit = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit.flattened())
circuit_back = stimcirq.cirq_circuit_to_stim_circuit(cirq_circuit)
assert len(circuit_back.shortest_graphlike_error()) == 3
6 changes: 4 additions & 2 deletions glue/cirq/stimcirq/_measure_and_or_reset_gate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List
from typing import Any, Dict, List, Tuple

import cirq
import stim
Expand Down Expand Up @@ -91,7 +91,9 @@ def _stim_op_name(self) -> str:
result += self.basis
return result

def _stim_conversion_(self, *, edit_circuit: stim.Circuit, targets: List[int], tag: str, **kwargs):
def _stim_conversion_(self, *, edit_circuit: stim.Circuit, targets: List[int], tag: str, edit_measurement_key_lengths: List[Tuple[str, int]], **kwargs):
if self.measure:
edit_measurement_key_lengths.append((self.key, 1))
if self.invert_measure:
targets[0] = stim.target_inv(targets[0])
if self.measure_flip_probability:
Expand Down
Loading