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.

Circuit incorrectly justifed

See original GitHub issue

Information

  • Qiskit Terra version: master
  • Python version: 3.7
  • Operating system: macOS

What is the current behavior?

The following circuit is not correctly justified, the first U2 after the measure appears in its own column, rather than underneath the other U2.

Steps to reproduce the problem

qasm = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[5];
creg c1[1];
u2(0,3.14159265358979) q[0];
u2(0,3.14159265358979) q[1];
cx q[1],q[0];
u2(0,3.14159265358979) q[0];
u2(0,3.14159265358979) q[1];
u2(0,3.14159265358979) q[1];
measure q[0] -> c1[0];
u2(0,3.14159265358979) q[0];
cx q[1],q[0];
u2(0,3.14159265358979) q[0];
u2(0,3.14159265358979) q[1];
 """
from qiskit import QuantumCircuit
qc = QuantumCircuit.from_qasm_str(qasm)
print(qc)
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
q_0: |0>─ U2(0,3.1416) β”œβ”€ X β”œβ”€ U2(0,3.1416) β”œβ”€Mβ”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ U2(0,3.1416) β”œβ”€ X β”œβ”€ U2(0,3.1416) β”œ
        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β””β”€β”¬β”€β”˜β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β””β•₯β”˜β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”¬β”€β”˜β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
q_1: |0>─ U2(0,3.1416) β”œβ”€β”€β– β”€β”€β”€ U2(0,3.1416) β”œβ”€β•«β”€β”€ U2(0,3.1416) β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€ U2(0,3.1416) β”œ
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•‘ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
q_2: |0>──────────────────────────────────────╫──────────────────────────────────────────────────────
                                              β•‘                                                      
q_3: |0>──────────────────────────────────────╫──────────────────────────────────────────────────────
                                              β•‘                                                      
q_4: |0>──────────────────────────────────────╫──────────────────────────────────────────────────────
                                              β•‘                                                      
c1_0: 0 ══════════════════════════════════════╩══════════════════════════════════════════════════════

What is the expected behavior?

        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
q_0: |0>─ U2(0,3.1416) β”œβ”€ X β”œβ”€ U2(0,3.1416) β”œβ”€Mβ”œβ”€ U2(0,3.1416) β”œβ”€ X β”œβ”€ U2(0,3.1416) β”œ
        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β””β”€β”¬β”€β”˜β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β””β•₯β”˜β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β””β”€β”¬β”€β”˜β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
q_1: |0>─ U2(0,3.1416) β”œβ”€β”€β– β”€β”€β”€ U2(0,3.1416) β”œβ”€β•«β”€β”€ U2(0,3.1416) β”œβ”€β”€β– β”€β”€β”€ U2(0,3.1416) β”œ
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•‘ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
q_2: |0>──────────────────────────────────────╫──────────────────────────────────────
                                              β•‘                                                      
q_3: |0>──────────────────────────────────────╫──────────────────────────────────────
                                              β•‘                                                      
q_4: |0>──────────────────────────────────────╫──────────────────────────────────────
                                              β•‘                                                      
c1_0: 0 ══════════════════════════════════════╩══════════════════════════════════════

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (27 by maintainers)

github_iconTop GitHub Comments

2reactions
jwoehrcommented, Aug 12, 2019

It seems like this example has the same issue (last round of H):

Screen Shot 2019-07-11 at 2 49 18 PM

@1ucian0 , I recreate qasm for the circuit you illustrated above and test draw left, right, and none with this code:

qasm = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[4];
h q[0];
h q[1];
h q[2];
h q[3];
cx q[0],q[3];
h q[1];
cx q[0],q[2];
cx q[0],q[1];
h q[2];
cx q[0],q[1];
h q[2];
cx q[0],q[2];
h q[1];
cx q[0],q[3];
h q[0];
h q[1];
h q[2];
h q[3];
 """
from qiskit import QuantumCircuit
qc = QuantumCircuit.from_qasm_str(qasm)
print("draw left")
print(qc.draw(justify='left'))
print("draw right")
print(qc.draw(justify='right'))
print("draw none")
print(qc.draw(justify='none'))

The resulting output is show below. Am I correct that both left and right are incorrect (left for the reason you pointed out above, and right for the positioning of the last h q[3]) while none is correct?

draw left
        β”Œβ”€β”€β”€β”                                             β”Œβ”€β”€β”€β”
q_0: |0>─ H β”œβ”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€ H β”œ
        β”œβ”€β”€β”€β”€  β”‚  β”Œβ”€β”€β”€β”  β”‚  β”Œβ”€β”΄β”€β”β”Œβ”€β”΄β”€β”  β”‚  β”Œβ”€β”€β”€β”  β”‚  β”Œβ”€β”€β”€β”β””β”€β”€β”€β”˜
q_1: |0>─ H β”œβ”€β”€β”Όβ”€β”€β”€ H β”œβ”€β”€β”Όβ”€β”€β”€ X β”œβ”€ X β”œβ”€β”€β”Όβ”€β”€β”€ H β”œβ”€β”€β”Όβ”€β”€β”€ H β”œβ”€β”€β”€β”€β”€
        β”œβ”€β”€β”€β”€  β”‚  β””β”€β”€β”€β”˜β”Œβ”€β”΄β”€β”β”œβ”€β”€β”€β”€β”œβ”€β”€β”€β”€β”Œβ”€β”΄β”€β”β””β”€β”€β”€β”˜  β”‚  β”œβ”€β”€β”€β”€     
q_2: |0>─ H β”œβ”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€ X β”œβ”€ H β”œβ”€ H β”œβ”€ X β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€ H β”œβ”€β”€β”€β”€β”€
        β”œβ”€β”€β”€β”€β”Œβ”€β”΄β”€β”     β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜     β”Œβ”€β”΄β”€β”β””β”€β”€β”€β”˜β”Œβ”€β”€β”€β”
q_3: |0>─ H β”œβ”€ X β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ X β”œβ”€β”€β”€β”€β”€β”€ H β”œ
        β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜                              β””β”€β”€β”€β”˜     β””β”€β”€β”€β”˜
draw right
        β”Œβ”€β”€β”€β”                                        β”Œβ”€β”€β”€β”
q_0: |0>─ H β”œβ”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€ H β”œ
        β”œβ”€β”€β”€β”€  β”‚  β”Œβ”€β”€β”€β”  β”‚  β”Œβ”€β”΄β”€β”β”Œβ”€β”΄β”€β”  β”‚  β”Œβ”€β”€β”€β”  β”‚  β”œβ”€β”€β”€β”€
q_1: |0>─ H β”œβ”€β”€β”Όβ”€β”€β”€ H β”œβ”€β”€β”Όβ”€β”€β”€ X β”œβ”€ X β”œβ”€β”€β”Όβ”€β”€β”€ H β”œβ”€β”€β”Όβ”€β”€β”€ H β”œ
        β”œβ”€β”€β”€β”€  β”‚  β””β”€β”€β”€β”˜β”Œβ”€β”΄β”€β”β”œβ”€β”€β”€β”€β”œβ”€β”€β”€β”€β”Œβ”€β”΄β”€β”β”œβ”€β”€β”€β”€  β”‚  β””β”€β”€β”€β”˜
q_2: |0>─ H β”œβ”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€ X β”œβ”€ H β”œβ”€ H β”œβ”€ X β”œβ”€ H β”œβ”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€
        β”œβ”€β”€β”€β”€β”Œβ”€β”΄β”€β”     β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β”Œβ”€β”΄β”€β”β”Œβ”€β”€β”€β”
q_3: |0>─ H β”œβ”€ X β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ X β”œβ”€ H β”œ
        β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜                              β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜
draw none
        β”Œβ”€β”€β”€β”                                                                      β”Œβ”€β”€β”€β”          
q_0: |0>─ H β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β– β”€β”€β”€β”€β– β”€β”€β”€ H β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
        β””β”€β”€β”€β”˜β”Œβ”€β”€β”€β”β”Œβ”€β”€β”€β”            β”‚    β”‚  β”Œβ”€β”΄β”€β”β”Œβ”€β”΄β”€β”β”Œβ”€β”€β”€β”β”Œβ”€β”€β”€β”            β”‚    β”‚  β””β”€β”€β”€β”˜          
q_1: |0>────── H β”œβ”€ H β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€ X β”œβ”€ X β”œβ”€ H β”œβ”€ H β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
             β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β”Œβ”€β”€β”€β”       β”‚  β”Œβ”€β”΄β”€β”β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β”Œβ”€β”€β”€β”β”Œβ”€β”€β”€β”β”Œβ”€β”΄β”€β”  β”‚       β”Œβ”€β”€β”€β”     
q_2: |0>──────────────── H β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€ X β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ H β”œβ”€ H β”œβ”€ X β”œβ”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€ H β”œβ”€β”€β”€β”€β”€
                       β””β”€β”€β”€β”˜β”Œβ”€β”€β”€β”β”Œβ”€β”΄β”€β”β””β”€β”€β”€β”˜                    β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β”Œβ”€β”΄β”€β”     β””β”€β”€β”€β”˜β”Œβ”€β”€β”€β”
q_3: |0>───────────────────── H β”œβ”€ X β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ X β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ H β”œ
2reactions
maddy-todcommented, Jul 17, 2019

I think the error is likely to be in qiskit-terra/qiskit/visualization/utils.py in the method _get_layered_instructions() as I am seeing the bug in both the mpl and the latex outputs too. It is probably an error with the way the layers are being generated rather than drawn. image image

Read more comments on GitHub >

github_iconTop Results From Across the Web

When can a project's wrong estimates be justified?
[Are] there any cases...when wrong estimates can be justified? Estimates are not guarantees. They are "educated guesses" based on experience, historical data,Β ...
Read more >
Rule 60. Relief from a Judgment or Order - Law.Cornell.Edu
(a) Corrections Based on Clerical Mistakes; Oversights and Omissions. The court may correct a clerical mistake or a mistake arising from oversight orΒ ......
Read more >
CIS 4930 Digital System Testing Testing for Single Stuck-at ...
Determine PI values that force value on line l to Μ…". This is known as the line-justification problem. 6. 6.2 ATG for SSFs...
Read more >
Plain Sentencing Guidelines errors "ordinarily" justify relief
When a federal district court sentences a defendant under an incorrect Sentencing Guidelines range, the defendant ordinarily is entitled toΒ ...
Read more >
The neural correlates of justified and unjustified killing - NCBI
One example is warfare, where killing enemy soldiers is seen as morally justified. Yet, the neural underpinnings distinguishing between justified andΒ ...
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