Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Moment allows conflicting measurements

Open daxfohl opened this issue 3 years ago • 4 comments

Description of the issue

Moment constructor checks for conflicting ops on qubits but not on measurement keys.

How to reproduce the issue

m = cirq.Moment(
    cirq.measure(cirq.NamedQubit('q1'), key='a'),
    cirq.measure(cirq.NamedQubit('q2'), key='a'),
    cirq.X(cirq.NamedQubit('q3')).with_classical_controls('a')
)
print(cirq.Circuit(m))
       ┌───┐
q1: ────M──────
        ║
q2: ────╫M─────
        ║║
q3: ────╫╫X────
        ║║║
a: ═════@@^════
       └───┘

Note: multiple classical controls should be able to depend on the same measurement key within a moment; just multiple measurements, or measurement+control on the same key should not be allowed in one moment.

Cirq version v1.0

daxfohl avatar Jul 15 '22 13:07 daxfohl

Looks like a bug. We should fix for a bug fix release 1.0.1

dabacon avatar Jul 27 '22 18:07 dabacon

I think we should allow the repeated measurement keys in a moment, since operations are ordered within in a moment there's not ambiguity about which operation will write first into the output array for the given key. But the classical control being used in the same moment is a problem.

maffoo avatar Jul 27 '22 19:07 maffoo

@maffoo an aside, from a HW perspective should we allow a qubit to be used as a control for multiple operations in the same moment? i.e. logically CX(0, 1) and CCX(0, 2, 3) can run in parallel. We don't currently allow them to appear in the same moment though. Is that restriction worth removing, or would HW be unable to support that anyway?

daxfohl avatar Jul 27 '22 20:07 daxfohl

I think it'd be fine to allow multiple gates that use a given control bit in the same moment.

maffoo avatar Jul 27 '22 22:07 maffoo

Closing due to lack of activity

daxfohl avatar Oct 14 '22 02:10 daxfohl