Skip to content

print(moment) is confusing for crossing gates #3913

Open
@tanujkhattar

Description

@tanujkhattar

Description of the issue
When using line qubits and crossing gates in a single moment; the output on printing the moment is confusing and does not show the overlap correctly, unlike the output obtained on printing the whole circuit.

How to reproduce the issue

a, b, c, d = cirq.LineQubit.range(4)
c1 = cirq.Circuit([cirq.CNOT(a, d), cirq.CNOT(b, c)])
c2 = cirq.Circuit([cirq.CNOT(a, c), cirq.CNOT(b, d)])
In [22]: print(c1, '\n', c2)
      ┌──┐
0: ────@─────
       │
1: ────┼@────
       ││
2: ────┼X────
       │
3: ────X─────
      └──┘
       ┌──┐
0: ────@─────
       │
1: ────┼@────
       ││
2: ────X┼────

3: ─────X────
      └──┘
In [23]: print(c1[0], '\n', c2[0]) # <-- Confusing: The output should be different similar to circuit diagram above. 0 1 2 3
╶─┼─────────
0 │ @─@─XX
  │
   ╷ 0 1 2 3
╶─┼─────────
0 │ @─@─XX

Another Example:

In [18]: print(cirq.Circuit(cirq.ControlledGate(cirq.X, num_controls = 3).on(a, b, c, d))[0])
    ...: print(cirq.Circuit([cirq.CNOT(a, d), cirq.CZ(b, c)])[0])
  ╷ 0 1 2 3
╶─┼─────────
0 │ @─@─@─X
  │
  ╷ 0 1 2 3
╶─┼─────────
0 │ @─@─@─X

Cirq version

0.11.0.dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/circuitskind/bug-reportSomething doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions