Description of the issue
(not 100% sure this isn't intended behavior)
when two measurements have the same key, reordering them results in a logically different circuit. Transformers like align_left() and align_right() correctly account for this by preventing the reordering of measurements with the same key, but synchronize_terminal_measurements() does not (see below)
How to reproduce the issue
circuit = cirq.Circuit(
cirq.X(cirq.q(1)),
cirq.measure(cirq.q(0), key="key1"),
cirq.measure(cirq.q(1), key="key1"),
cirq.measure(cirq.q(1), key="key2"),
)
print(circuit)
print(cirq.align_right(circuit)) # no change, as it would require reordering the two measurements with `key="key1"`
print(cirq.synchronize_terminal_measurements(circuit))
prints:
0: ───M('key1')───────────────────────────
1: ───X───────────M('key1')───M('key2')───
0: ───M('key1')───────────────────────────
1: ───X───────────M('key1')───M('key2')───
0: ───────────────────M('key1')───
1: ───X───M('key1')───M('key2')───
where the final circuit is not logically equivalent (the expected measurement outcome for "key1" is flipped)
Cirq version
Description of the issue
(not 100% sure this isn't intended behavior)
when two measurements have the same key, reordering them results in a logically different circuit. Transformers like
align_left()andalign_right()correctly account for this by preventing the reordering of measurements with the same key, butsynchronize_terminal_measurements()does not (see below)How to reproduce the issue
prints:
where the final circuit is not logically equivalent (the expected measurement outcome for
"key1"is flipped)Cirq version