`synchronize_terminal_measurements()` misorders measurements with the same key

Open
#6,329 21 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #8226 by @Sanjays2402 — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
20/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start by reading synchronize_terminal_measurements() and running the reproduction in the issue. Compare its output with align_right() and check whether measurements sharing a key retain their logical ordering. Done means synchronization no longer changes the expected measurement outcome; an open pull request is already linked.

Written by the indexing model from the issue text.

Description

area/transformers kind/bug-report triage/accepted

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
Dominant language
Python
Stars
5.1k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
48

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quantumlib/Cirq

All issues in quantumlib/Cirq

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.