quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.23k stars 1.01k forks source link

In text diagrams, writing a classical bit is shown as a control while using it as a control is not shown as a control #5688

Open Strilanc opened 2 years ago

Strilanc commented 2 years ago
import cirq

print(cirq.Circuit(
    cirq.measure(cirq.LineQubit(0), key="abc"),
    cirq.X(cirq.LineQubit(0)).with_classical_controls("abc"),
))
0: ─────M───X───
        ║   ║
abc: ═══@═══^═══

The @ means control elsewhere in diagrams. The character below the M isn't a control it's an output; it should probably be an X. And the ^ for the control on the NOT gate should be an @ since that means control.

dabacon commented 2 years ago

Would making the second one an "@" would be confusing, since it might make someone think it actually is a CNOT? Similarly for the first making it an "X" would also be slightly misleading in that people could think this means a measurement is a someone an "X" gate.

Strilanc commented 2 years ago

Would making the second one an "@" would be confusing, since it might make someone think it actually is a CNOT?

But it is a controlled not. It's a classically controlled not. They wouldn't be confused about that, they would be right. In any case, the double lines on the vertical bar is a dead giveaway that it's classically controlled.

people could think this means a measurement is a someone an "X" gate.

A measurement kinda is a NOT gate on a classical bit, controlled by a quantum bit. I don't think there's any physical experiment you can do that distinguishes "measurement" from "CNOT from qubit to bit where bit is promised to be initially OFF".

daxfohl commented 2 years ago

I agree with changing the control to @. For changing the target to X, my main concern is that now that we allow multiple writes to the same measurement key, X looks like an XOR, when it's actually just a write. Otherwise I agree here as well.

(I had also been thinking that we might want to add an "op" param to measure, allowing things like cirq.measure(q, key=m, op=XOR), which would XOR the current measurement with the previous one, and I kind of wanted to reserve X for that.)

verult commented 2 years ago

From Cirq sync - biggest question is whether changing text diagram output would be considered a breaking change.

seunomonije commented 2 years ago

From Cirq sync:

Consensus: We should accept this as a bug and get fixed