Skip to content

Commit

Permalink
Fix split_into_unitary_then_general not spreading blocks across opera…
Browse files Browse the repository at this point in the history
…tion (quantumlib#3095)

This was such a dumb mistake for me to make.
  • Loading branch information
Strilanc authored Jun 17, 2020
1 parent 037afff commit b0a4599
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cirq/sim/sparse_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ def _split_into_unitary_then_general(circuit: 'cirq.Circuit'
general_part = []
for op in moment:
qs = set(op.qubits)
if not protocols.has_unitary(op):
if (not protocols.has_unitary(op) or
not qs.isdisjoint(blocked_qubits)):
blocked_qubits |= qs

if qs.isdisjoint(blocked_qubits):
Expand Down
15 changes: 15 additions & 0 deletions cirq/sim/sparse_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,3 +948,18 @@ def test_overlapping_measurements_at_end():
assert len(counts) == 2
assert 10 <= counts[0] <= 90
assert 10 <= counts[1] <= 90


def test_separated_measurements():
a, b = cirq.LineQubit.range(2)
c = cirq.Circuit([
cirq.H(a),
cirq.H(b),
cirq.CZ(a, b),
cirq.measure(a, key=''),
cirq.CZ(a, b),
cirq.H(b),
cirq.measure(b, key='zero'),
])
sample = cirq.Simulator().sample(c, repetitions=10)
np.testing.assert_array_equal(sample['zero'].values, [0] * 10)

0 comments on commit b0a4599

Please sign in to comment.