question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Classical conditions misalign in both ASCII and MPL output

See original GitHub issue

Environment

  • Qiskit Terra version: 0.19.1
  • Python version: 3.7.12
  • Operating system: Ubuntu 18.04.5 LTS (Google Colab)

What is happening?

I was testing my automatic code generation for Qiskit, and apparently the ~cphase~ controlled U1 gate with a classical condition will make the circuit misaligns in both of ASCII output and MPL output.

Screenshots:

q2_0: ─■───────■───────■───────■───────■───────■───────■───────■───────■──────»
       β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0) Β»
q2_1: ─■───────■───────■───────■───────■───────■───────■───────■───────■──────»
       β•‘       β•‘       β•‘       β•‘       β•‘       β•‘       β•‘       β•‘       β•‘      Β»
q2_2: ─╫───────╫───────╫───────╫───────╫───────╫───────╫───────╫───────╫──────»
      β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β” β”Œβ•«β”€β•¨β”€β”€β”€β”Β»
c2: 5/β•‘β•‘0x1 β•žβ•β•‘β•‘0x3 β•žβ•β•‘β•‘0x5 β•žβ•β•‘β•‘0x7 β•žβ•β•‘β•‘0x9 β•žβ•β•‘β•‘0xb β•žβ•β•‘β•‘0xd β•žβ•β•‘β•‘0xf β•žβ•β•‘β•‘0x11 β•žΒ»
      β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”˜ β””β•«β”€β”€β”€β”€β”€β”˜Β»
Β«                                                                         Β»
Β«q2_0: ─■───────■───────■───────■───────■───────■───────■───────────■─────»
Β«       β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0)  β”‚U1(0) β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”Β»
Β«q2_1: ─■───────■───────■───────■───────■───────■───────■─────── U2(0,0) β”œΒ»
Β«       β•‘       β•‘       β•‘       β•‘       β•‘       β•‘       β•‘      └────β•₯β”€β”€β”€β”€β”˜Β»
Β«q2_2: ─╫───────╫───────╫───────╫───────╫───────╫───────╫───────────╫─────»
Β«      β”Œβ•«β”€β•¨β”€β”€β”€β”β”Œβ•«β”€β•¨β”€β”€β”€β”β”Œβ•«β”€β•¨β”€β”€β”€β”β”Œβ•«β”€β•¨β”€β”€β”€β”β”Œβ•«β”€β•¨β”€β”€β”€β”β”Œβ•«β”€β•¨β”€β”€β”€β”β”Œβ•«β”€β•¨β”€β”€β”€β”  β”Œβ”€β”€β•¨β”€β”€β”  Β»
Β«c2: 5/β•‘β•‘0x13 β•žβ•‘β•‘0x15 β•žβ•‘β•‘0x17 β•žβ•‘β•‘0x19 β•žβ•‘β•‘0x1b β•žβ•‘β•‘0x1d β•žβ•‘β•‘0x1f β•žβ•β•β•‘ 0x2 β•žβ•β•Β»
Β«      β””β•«β”€β”€β”€β”€β”€β”˜β””β•«β”€β”€β”€β”€β”€β”˜β””β•«β”€β”€β”€β”€β”€β”˜β””β•«β”€β”€β”€β”€β”€β”˜β””β•«β”€β”€β”€β”€β”€β”˜β””β•«β”€β”€β”€β”€β”€β”˜β””β•«β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”˜  Β»
Β«                                                                        Β»
Β«q2_0: ─────■──────────■──────────■──────────■──────────■──────────■─────»
Β«      β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”Β»
Β«q2_1: ─ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œΒ»
Β«      └────β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜Β»
Β«q2_2: ─────╫──────────╫──────────╫──────────╫──────────╫──────────╫─────»
Β«        β”Œβ”€β”€β•¨β”€β”€β”    β”Œβ”€β”€β•¨β”€β”€β”    β”Œβ”€β”€β•¨β”€β”€β”    β”Œβ”€β”€β•¨β”€β”€β”    β”Œβ”€β”€β•¨β”€β”€β”    β”Œβ”€β”€β•¨β”€β”€β”  Β»
Β«c2: 5/══║ 0x3 β•žβ•β•β•β•β•‘ 0x6 β•žβ•β•β•β•β•‘ 0x7 β•žβ•β•β•β•β•‘ 0xa β•žβ•β•β•β•β•‘ 0xb β•žβ•β•β•β•β•‘ 0xe β•žβ•β•Β»
Β«        β””β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”˜  Β»
Β«                                                                        Β»
Β«q2_0: ─────■──────────■──────────■──────────■──────────■──────────■─────»
Β«      β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”Β»
Β«q2_1: ─ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œΒ»
Β«      └────β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜Β»
Β«q2_2: ─────╫──────────╫──────────╫──────────╫──────────╫──────────╫─────»
Β«        β”Œβ”€β”€β•¨β”€β”€β”    β”Œβ”€β”€β•¨β”€β”€β”€β”   β”Œβ”€β”€β•¨β”€β”€β”€β”   β”Œβ”€β”€β•¨β”€β”€β”€β”   β”Œβ”€β”€β•¨β”€β”€β”€β”   β”Œβ”€β”€β•¨β”€β”€β”€β” Β»
Β«c2: 5/══║ 0xf β•žβ•β•β•β•β•‘ 0x12 β•žβ•β•β•β•‘ 0x13 β•žβ•β•β•β•‘ 0x16 β•žβ•β•β•β•‘ 0x17 β•žβ•β•β•β•‘ 0x1a β•žβ•Β»
Β«        β””β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”˜ Β»
Β«                                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       Β»
Β«q2_0: ─────■──────────■──────────■────── U3(0,0,0) β”œβ”€ U3(0,0,0) β”œβ”€β”€β”€X───»
Β«      β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜   β”‚   Β»
Β«q2_1: ─ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€ U2(0,0) β”œβ”€β”€β”€β”€β”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€Β»
Β«      └────β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”˜      β•‘            β•‘         β”‚   Β»
Β«q2_2: ─────╫──────────╫──────────╫───────────╫────────────╫─────────X───»
Β«        β”Œβ”€β”€β•¨β”€β”€β”€β”   β”Œβ”€β”€β•¨β”€β”€β”€β”   β”Œβ”€β”€β•¨β”€β”€β”€β”    β”Œβ”€β”€β•¨β”€β”€β”€β”     β”Œβ”€β”€β•¨β”€β”€β”€β”  β”Œβ”€β”€β•¨β”€β”€β”Β»
Β«c2: 5/══║ 0x1b β•žβ•β•β•β•‘ 0x1e β•žβ•β•β•β•‘ 0x1f β•žβ•β•β•β•β•‘ 0x15 β•žβ•β•β•β•β•β•‘ 0x17 β•žβ•β•β•‘ 0x2 β•žΒ»
Β«        β””β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”˜Β»
Β«                                                           
Β«q2_0: ───X──────X──────X──────X───────X───────X───────X────
Β«         β”‚      β”‚      β”‚      β”‚       β”‚       β”‚       β”‚    
Β«q2_1: ───■──────■──────■──────■───────■───────■───────■────
Β«         β”‚      β”‚      β”‚      β”‚       β”‚       β”‚       β”‚    
Β«q2_2: ───X──────X──────X──────X───────X───────X───────X────
Β«      β”Œβ”€β”€β•¨β”€β”€β”β”Œβ”€β”€β•¨β”€β”€β”β”Œβ”€β”€β•¨β”€β”€β”β”Œβ”€β”€β•¨β”€β”€β”€β”β”Œβ”€β”€β•¨β”€β”€β”€β”β”Œβ”€β”€β•¨β”€β”€β”€β”β”Œβ”€β”€β•¨β”€β”€β”€β”
Β«c2: 5/β•‘ 0x3 β•žβ•‘ 0xa β•žβ•‘ 0xb β•žβ•‘ 0x12 β•žβ•‘ 0x13 β•žβ•‘ 0x1a β•žβ•‘ 0x1b β•ž
Β«      β””β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”˜

image

How can we reproduce the issue?

Using the source code below:

from numpy import pi, e as euler
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit.library.standard_gates import SdgGate, TdgGate, SXGate, RXGate, RYGate, RZGate, U1Gate, U2Gate, U3Gate, SwapGate, XGate, YGate, ZGate, HGate, PhaseGate, SGate, TGate

qr = QuantumRegister(3)
cr = ClassicalRegister(5)
qc = QuantumCircuit(qr, cr)

qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 1)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 3)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 5)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 7)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 9)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 11)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 13)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 15)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 17)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 19)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 21)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 23)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 25)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 27)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 29)
qc.append(U1Gate(0).control(1), [1, 0]).c_if(cr, 31)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 2)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 3)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 6)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 7)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 10)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 11)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 14)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 15)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 18)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 19)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 22)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 23)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 26)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 27)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 30)
qc.append(U2Gate(0, 0).control(1), [0, 1]).c_if(cr, 31)
qc.append(U3Gate(0, 0, 0).control(1), [1, 0]).c_if(cr, 21)
qc.append(U3Gate(0, 0, 0).control(1), [1, 0]).c_if(cr, 23)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 2)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 3)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 10)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 11)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 18)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 19)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 26)
qc.append(SwapGate().control(1), [1, 0, 2]).c_if(cr, 27)

qc.draw() # For ASCII output
# qc.draw('mpl') # For MPL output

What should happen?

They should align in a vertical manner.

Any suggestions?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
javabstercommented, Feb 16, 2022

i’d be hesitant to remove the side text gates completely just because a bug might be difficult to fix. The user’s experience should come first, and the side text gates have been in use for a while so removing them would probably have a negative impact on all users as opposed to just the handful that experience this bug.

0reactions
enavarro51commented, Feb 18, 2022

That was my most likely conclusion as well, so that’s what I did in #7673.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visualization and Juypter Tools - GitHub
Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and algorithms.
Read more >
flight-path plotting lidar: Topics by Science.gov
Both navigation technologies were essential to obtaining useful results ... Lidar binary data tapes were successfully converted to ASCII Code on the VAXΒ ......
Read more >
U5L1-Spell-Checker.xml - The Beauty and Joy of Computing
... ,could,after,even,because,us,said,good,way,two,should,work,use,through,see ... ,appropriate,possibly,join,seemed,powerful,speak,condition,spirit,findingΒ ...
Read more >
Oceans '88 - GovInfo
IEEE Catalog Number 88-CH2585-8 OCEANS '88 Proceedings Volume Two Table of Contents PLASTICS IN OUR OCEANS: WHAT ARE WE DOING MESOCOSMS AS TOOLS...
Read more >
Abstracts from the 50th European Society of Human Genetics ...
Results: We detected 21 (4.3%) cytogenetic aberrations, both ... This condition can be a result of a genomic instability and defects inΒ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found