Skip to content

synchronize_terminal_measurements() misorders measurements with the same key #6329

Description

@richrines1

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

1.3.0.dev20230830191034

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug-reportSomething doesn't seem to work.status/autoclosedAutomatically closed (e.g., due to being stale)status/staleClosed due to inactivity for an extended period of timetriage/needs-feasibility[Feature requests] Needs design work to prove feasibility before acceptingtriage/needs-more-evidence[Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions