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

latex drawer support for cregbundle #4291

Closed
1ucian0 opened this issue Apr 27, 2020 · 4 comments · Fixed by #4410
Closed

latex drawer support for cregbundle #4291

1ucian0 opened this issue Apr 27, 2020 · 4 comments · Fixed by #4410
Assignees
Labels
good first issue Good for newcomers status: pending PR It has one or more PRs pending to solve this issue type: feature request New feature or request

Comments

@1ucian0
Copy link
Member

1ucian0 commented Apr 27, 2020

In the spirit of #2797 it would be great if latex drawer add support for cregbundle.

Take the following example:

from qiskit import *
qr = QuantumRegister(3, 'q')
cr = ClassicalRegister(3, 'c')
circuit = QuantumCircuit(qr, cr)
circuit.measure(qr, cr)
circuit.draw('latex')

Screen Shot 2020-04-27 at 3 10 31 PM

I suggest something like this:

circuit.draw('latex', cregbundle=True)

Screen Shot 2020-04-27 at 3 11 26 PM

The latex code for that figure is:

\begin{equation*}
    \Qcircuit @C=1.0em @R=1.0em @!R {
	 	\lstick{ {q}_{0} :  } & \qw & \meter & \qw & \qw & \qw & \qw\\
	 	\lstick{ {q}_{1} :  } & \qw & \qw & \meter & \qw & \qw & \qw\\
	 	\lstick{ {q}_{2} :  } & \qw & \qw & \qw & \meter & \qw & \qw\\
	 	\lstick{c:} & {/_{_3}} \cw & \dstick{0} \cw \cwx[-3] & \dstick{1} \cw \cwx[-2] & \dstick{2} \cw \cwx[-1] & \cw & \cw\\
	 }
\end{equation*}
@1ucian0 1ucian0 added good first issue Good for newcomers type: feature request New feature or request labels Apr 27, 2020
@rao107
Copy link
Contributor

rao107 commented May 2, 2020

Hello! I haven't contributed to any open-source software but I want to try my hand at this.

@1ucian0
Copy link
Member Author

1ucian0 commented May 2, 2020

Sure! Go ahead. Let me know if I can help!

@1ucian0
Copy link
Member Author

1ucian0 commented May 18, 2020

It seems there is a small bug:

cr1 = ClassicalRegister(2, 'c1')
cr2 = ClassicalRegister(2, 'c2')
qr = QuantumRegister(2, 'q')
circuit = QuantumCircuit(qr, cr1, cr2)
circuit.measure(qr[0], cr1[0])
circuit.measure(qr[0], cr1[1])
circuit.measure(qr[0], cr2[0])
circuit.measure(qr[0], cr2[1])

with circuit.draw('latex', cregbundle=False):
image

with circuit.draw('latex', cregbundle=True):
image

The expected result is to have two registers in the last image.

A side note (if it's not easy to fix, no worries. We can leave it for later). Would it be possible avoid moving the gates right? Consider this:

circuit = QuantumCircuit(1, 1)
circuit.h(0)
circuit.measure(0, 0)
circuit.draw('latex', cregbundle=False)

download_1

circuit = QuantumCircuit(1, 1)
circuit.h(0)
circuit.measure(0, 0)
circuit.draw('latex', cregbundle=True)

download_2

@1ucian0 1ucian0 added the status: pending PR It has one or more PRs pending to solve this issue label May 18, 2020
@rao107
Copy link
Contributor

rao107 commented May 19, 2020

Oh wow, I never realized that multiple classical registers could be in the same circuit! That's pretty interesting. I'm working on squashing that bug now.

Relating to the side note: I'll certainly try my best to fix the formatting and avoid moving the gates to the right but, even from a brief look, the problem looks more complicated than I can handle. It's not going to stop me from trying though!

Unrelated to the bugs brought up, I found another bug where the number on the bundle would bug out:

circuit = QuantumCircuit(1, 10)
circuit.measure(0,0)
circuit.draw('latex', cregbundle=True)

image
But I then I fixed it:
image
I just wanted to let you know that I know about this and I've already dealt with it in case you also find the same bug as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers status: pending PR It has one or more PRs pending to solve this issue type: feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants