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

Add option to QuantumCircuit.draw to omit final measurements #13581

Open
kevinsung opened this issue Dec 18, 2024 · 9 comments
Open

Add option to QuantumCircuit.draw to omit final measurements #13581

kevinsung opened this issue Dec 18, 2024 · 9 comments
Labels
type: feature request New feature or request

Comments

@kevinsung
Copy link
Contributor

What should we add?

Often the last operation in a circuit is a measurement of all the qubits, and this takes up a lot of space in the drawing. I would like to add an option to omit final measurements from the drawing.

@kevinsung kevinsung added the type: feature request New feature or request label Dec 18, 2024
@Cryoris
Copy link
Contributor

Cryoris commented Dec 19, 2024

The solution proposed in #4149 which would just align all final measurements would also be nice, that way it is compact but we can still see the measurements.

@kevinsung
Copy link
Contributor Author

The solution proposed in #4149 which would just align all final measurements would also be nice, that way it is compact but we can still see the measurements.

Ah that's also a nice idea!

@enavarro51
Copy link
Contributor

enavarro51 commented Dec 30, 2024

@Cryoris, @kevinsung, @jakelishman I can take a look at this, at least for the mpl drawer. It does bring up a number of design questions.

  • In the following circuit,
qr = QuantumRegister(2)
cr = ClassicalRegister(3)
qc = QuantumCircuit(qr, cr)
qc.x(0)
qc.h(0)
qc.measure(0, 0)
qc.x(1)
qc.h(1)
qc.measure(1, 1)
qc.x(1)
qc.measure(1, 2)
qc.h(1)
qc.draw()

Image

since the first 2 measures are at the same depth, it seems reasonable to make these without the double vertical line as pictured in #4149. Having said that, why not make the third measure the same and remove all the double lines to the classical bits since the bit will be indicated either in the measure box or under it?

  • Taking this a step further,
qr = QuantumRegister(2)
cr = ClassicalRegister(3)
qc = QuantumCircuit(qr, cr)
with qc.if_test((cr, 2)):
    qc.x(0)
with qc.if_test(expr.equal(cr, 2)):
    qc.y(0)
qc.draw()

Image

if we were to put c6 == 2 under the If in the first red box, there would be no need for the double vertical lines here either. Which brings up the ultimate point, since the old c_if is going away and the measures can be done as above, why not do away with the entire classical bit section of the drawers?

This would free up a lot of space both vertically and horizontially as we move to 100+ qubit drawings, and it should be workable for both the mpl and text drawers.

@Cryoris
Copy link
Contributor

Cryoris commented Jan 6, 2025

I like the idea for the measurements -- if we add the bit we measure into to the measurement box, there's no information in the double vertical lines and we can make the drawing a whole lot cleaner.

I'm less certain for the c_if bits, since the dots on the classical wire indicates the order in which operations are performed and thus do carry information.

@enavarro51
Copy link
Contributor

enavarro51 commented Jan 7, 2025

I was planning on doing separate PRs for the measures and the ifs, so I'll move ahead on the measure PR if you can assign that to me.

In regards to the c_if, I was assuming the If change would be for 2.0, since c_if is being deprecated and removed in 2.0. Currently the ControlFlowOps do not allow other operations to be displayed in the same layer (something that might be modified in the future if needed), so I think any order info is being preserved by the IfElseOp. Let me know if I'm missing something here.

@jakelishman
Copy link
Member

Thanks Edwin! (sorry for the slightly delayed response despite the tag - I just got back from paternity leave.)

I'm a bit nervous about committing to actually removing the clbits from the drawings (in Qiskit 2.0 land), but I do see the logic in it. Would we have space to put the clbit information into/near the measurement box in the text drawer as well?

@enavarro51
Copy link
Contributor

Yeah, I thought it might be a bit radical to remove the clbits, but realized if we don't need the double vertical lines, we don't really need the clbits.

For the mpl drawer, the clbit would appear in the measure box as a param would in a param gate. Might have to move the dial up slightly in the box, and the box would need to expand horizontally if the clbit name was long, but would probably be fine for the average use.

For the text drawer, the clbit would also have to appear where a param does now, which means it would add horizontal space to the drawing. For the original issue of final measurements of say 100 qubits, it clearly would use a whole lot less horizontal space, but individual measures would use more. My guess is on average, 2 to 3 old-style measures at the same depth would use about the same horizontal as 1 new style.

The same for the Ifs in the text drawer. It would add some horizontal to the If that's not using an expression already. This way Ifs with expressions and ones done with (bit, value) would appear the same.

Finally I just used 2.0 as a target because that's when c_if is supposed to go away. I was wondering if the look of a drawing changes but it still conveys the same information, is that a breaking change? Could it be done between major releases?

@enavarro51
Copy link
Contributor

And one more final comment. The issue has so far been brought up for the mpl drawer. Do we have to do the mpl and text drawers the same? The mpl changes would be a clear improvement in space without loss of information. If that's not true for the text drawer, can we do the mpl and leave the text as is?

@enavarro51
Copy link
Contributor

@jakelishman Here are a couple of samples of how the mpl changes would look.
Image
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants