Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions cirq-core/cirq/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3002,13 +3002,15 @@ def get_earliest_accommodating_moment_index(
mop_index = last_conflict + 1

# Update our dicts with data from this `mop` placement. Note `mop_index` will always be greater
# than the existing value for all of these, by construction.
# than the existing value for qubits and measurement keys, by construction.
for qubit in mop_qubits:
qubit_indices[qubit] = mop_index
for key in mop_mkeys:
mkey_indices[key] = mop_index
# For control keys, keep the maximum moment index seen so far because ops with the same control
# keys can commute past each other.
for key in mop_ckeys:
ckey_indices[key] = mop_index
ckey_indices[key] = max(mop_index, ckey_indices.get(key, -1))

return mop_index

Expand Down
11 changes: 11 additions & 0 deletions cirq-core/cirq/circuits/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ def test_append_control_key() -> None:
assert len(c) == 1


def test_append_control_key_before_measure() -> None:
c = cirq.Circuit()
q1, q2 = cirq.LineQubit.range(2)
c.append(cirq.X(q1))
c.append(cirq.X(q1))
c.append(cirq.X(q1).with_classical_controls('a'))
c.append(cirq.X(q2).with_classical_controls('a'))
c.append(cirq.measure(q2, key='a'))
assert len(c) == 4


def test_append_multiple() -> None:
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')
Expand Down