Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Left justify the circuit in text visualizer #1707

Closed
maddy-tod opened this issue Jan 22, 2019 · 5 comments · Fixed by #1725
Closed

Left justify the circuit in text visualizer #1707

maddy-tod opened this issue Jan 22, 2019 · 5 comments · Fixed by #1725

Comments

@maddy-tod
Copy link
Contributor

What is the expected enhancement?

Currently when a circuit is displayed using the text drawer each gate in a circuit sits in its own column, as shown in the following circuit.

         ┌───┐          
q1_0: |0>┤ H ├──────────
         └───┘┌───┐     
q1_1: |0>─────┤ H ├─────
              └───┘     

It would be better if the circuits could be left justified, so the above circuit would appear as below.

         ┌───┐          
q1_0: |0>┤ H ├───────
         └───┘
         ┌───┐          
q1_1: |0>┤ H ├───────
         └───┘

It appears that circuits are already justified like this in the matplotlib drawer.

@maddy-tod
Copy link
Contributor Author

In a circuit such as

circuit.h(qr1[1])
circuit.cx(qr1[0], qr1[3])
circuit.h(qr1[2])

The fully left justified circuit would be

q1_0: |0>──■───────
           │  ┌───┐
q1_1: |0>──┼──┤ H ├
           │  ├───┤
q1_2: |0>──┼──┤ H ├
         ┌─┴─┐└───┘
q1_3: |0>┤ X ├─────
         └───┘    

However this now no longer respects the order in which the gates were declared, and I think would be less helpful to users. I think it would be better to follow the style already used in the matplotlib drawer and produce a circuit where the gates are in their own columns, in the order they were declared. This will take up more space but would be clearer.

@ajavadia
Copy link
Member

This is what matplotlib does. Do you mean this?
image

Or do you mean this?

                        
q3_0: |0>───────■───────
         ┌───┐  │       
q3_1: |0>┤ H ├──┼───────
         └───┘  │  ┌───┐
q3_2: |0>───────┼──┤ H ├
              ┌─┴─┐└───┘
q3_3: |0>─────┤ X ├─────
              └───┘     

You are right that the second one is more accurate in terms of gate order, but then that would not really be left justified. The reason I was proposing left justified is that it gives you a good sense of the circuit depth. Except when it is not visually appealing (in this example, circuit depth is 1, but you can't really draw it with a depth of 1, so you add one more column).

@taalexander
Copy link
Contributor

taalexander commented Jan 23, 2019

The reason I was proposing left justified is that it gives you a good sense of the circuit depth

In practice on a device, gates are right justified (ie. gates are done as late as possible). The above could be confusing to users (I don't have a better solution, just wanted to note this).

@maddy-tod
Copy link
Contributor Author

When I output that circuit to matplotlib the image I get is
image
which is the same as your second example. I get a different image because I was running it against a version of qiskit that includes my fix for #1685 - sorry for the confusion! It might make sense to have the circuits right justified if this is what is done on the devices, and this would also give a sense of the circuit depth.

@ajavadia
Copy link
Member

Sure, I think there is merit to a right justified drawing as well. Left-justified is common in backend-agnostic circuits (textbooks, papers). Also the device schedule is something that is backend-specific and can change with different schedulers.

I think if we could have this as a drawing option in circuit.draw() it would be best (maybe justify='left'/'right' or schedule='asap'/'alap').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants