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 support for barriers to latex_drawer() #764

Merged
merged 3 commits into from Sep 3, 2018

Conversation

mtreinish
Copy link
Member

Summary

This commit adds support for drawing barriers to the latex_drawer(). The
Qcircuit LaTeX package doesn't have support for drawing barriers yet
(it's pending with CQuIC/qcircuit#33 ) so for now this commit inlines
the command definition. In the future when the Qcircuit package is
released to include the command we can remove that.

Details and comments

Fixes #731

@mtreinish
Copy link
Member Author

This is still WIP because the fixed offset for drawing barriers will overlap with the box for measurement if it's immediately after a gate. (because the measurement image is wider than a gate)

@ajavadia
Copy link
Member

@mtreinish It seems like your change has been released as part of Qcircuit, based on the conversation here: CQuIC/qcircuit#34.

So is this PR ready to be taken out of WIP and merged?

@mtreinish
Copy link
Member Author

@ajavadia it's still not quite ready yet. There is still an issue with the horizontal spacing between elements on the circuit. Like if you put it between a gate and a meter the barrier will overlap with the meter box. Unfortunately the fix for that will be kind of tricky to implement as the latex is generated today, because we won't be able to tell if there is anything on a qubit (and then know how much to space the barrier to center it) when we generate the \barrier string. I'll see if I can come up with a way to get it working tomorrow.

This will also need to be updated to remove the redefinition of \barrier since it's in a CTAN release now.

This commit adds support for drawing barriers to the latex_drawer(). The
Qcircuit LaTeX package was recently updated with the \barrier command,
which must be installed in your latex distribution for barriers to work.

Fixes Qiskit#731
@mtreinish mtreinish changed the title [WIP] Add support for barriers to latex_drawer() Add support for barriers to latex_drawer() Aug 22, 2018
@mtreinish
Copy link
Member Author

@ajavadia I've updated the patch to try and address those issues. The spacing for the barriers is still a bit weird because it's still not truly dynamic. So there are likely cases where the barrier won't be properly drawn in the middle of elements because it's naively assuming fixed spacing. That being said it seems to work for my simple test:

qp = QuantumProgram()

qr = qp.create_quantum_register('q1', 3)
qr_a = qp.create_quantum_register('q2', 2)
c = qp.create_classical_register('c1', 3)
c_a = qp.create_classical_register('c2', 2)
qc = qp.create_circuit('qc', [qr, qr_a], [c, c_a])

qc.h(qr[0])
qc.barrier(qr)
qc.y(qr[0])
qc.x(qr_a[0])
qc.h(qr[1])
qc.h(qr[2])
qc.x(qr_a[1])
qc.barrier(qr[0])
qc.measure(qr, c)
qc.measure(qr_a, c_a)
from qiskit.tools import visualization
visualization.latex_circuit_drawer(qc, filename='barrier.png')

normal

@ajavadia ajavadia self-assigned this Aug 28, 2018
@ajavadia
Copy link
Member

ajavadia commented Aug 31, 2018

@mtreinish can you please add the following commands to be drawn like barriers also?
snapshot, load, save, noise. These all take a parameter argument too, not sure if that can be written next to the dotted line. For example snapshot(slot=3) says take a snapshot of the state at that part of the circuit, and save it in slot 3.

These are simulator-specific instructions, and behave like barriers. So the circuit drawer should draw them like barriers. They are available when you do import qiskit.extensions.simulator.

@mtreinish
Copy link
Member Author

@ajavadia sure I can look into that. But I think it'll be better to do add support for the other commands in a follow up PR. Since it'll take me a bit of time to figure out how to best draw the annotation next to the barrier line.

@ajavadia
Copy link
Member

ajavadia commented Sep 2, 2018

@mtreinish Sure, that can be done later. The current barrier plotting looks great. Merging.

@ajavadia ajavadia merged commit 3d7af56 into Qiskit:master Sep 3, 2018
@mtreinish mtreinish deleted the latex-barriers branch September 3, 2018 04:34
@abdonrd abdonrd added this to In progress in Backends, Qobj, and Result via automation Sep 3, 2018
@abdonrd abdonrd moved this from In progress to Done in Backends, Qobj, and Result Sep 3, 2018
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
This commit adds support for drawing barriers to the latex_drawer(). The
Qcircuit LaTeX package was recently updated with the \barrier command,
which must be installed in your latex distribution for barriers to work.

Fixes Qiskit#731
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 this pull request may close these issues.

Draw barrier in latex_drawer
2 participants