Skip to content

Commit

Permalink
Fix cirq-to-stim conversion not adding TICKs for multi-moment singl…
Browse files Browse the repository at this point in the history
…e-rep `CircuitOperation`s (#728)
  • Loading branch information
AlexBourassa authored Mar 26, 2024
1 parent 1e16db2 commit bc638e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion glue/cirq/stimcirq/_cirq_to_stim.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ def __init__(self):

def process_circuit_operation_into_repeat_block(self, op: cirq.CircuitOperation) -> None:
if self.flatten or op.repetitions == 1:
self.process_operations(cirq.decompose_once(op))
moments = cirq.unroll_circuit_op(cirq.Circuit(op), deep=False, tags_to_check=None).moments
self.process_moments(moments)
self.out = self.out[:-1] # Remove a trailing TICK (to avoid double TICK)
return

child = CirqToStimHelper()
Expand Down
25 changes: 25 additions & 0 deletions glue/cirq/stimcirq/_cirq_to_stim_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,31 @@ def test_on_loop():
result = stimcirq.StimSampler().run(c)
assert result.measurements.keys() == {'0:a', '0:b', '1:a', '1:b', '2:a', '2:b'}


def test_multi_moment_circuit_operation():
q0 = cirq.LineQubit(0)
cc = cirq.Circuit(
cirq.CircuitOperation(
cirq.FrozenCircuit(
cirq.Moment(cirq.H(q0)),
cirq.Moment(cirq.H(q0)),
cirq.Moment(cirq.H(q0)),
cirq.Moment(cirq.H(q0)),
)
)
)
assert stimcirq.cirq_circuit_to_stim_circuit(cc) == stim.Circuit("""
H 0
TICK
H 0
TICK
H 0
TICK
H 0
TICK
""")


def test_on_tagged_loop():
a, b = cirq.LineQubit.range(2)
c = cirq.Circuit(
Expand Down

0 comments on commit bc638e3

Please sign in to comment.