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

Overhaul Quil to LaTeX circuit generation #1074

Merged
merged 37 commits into from
Nov 1, 2019

Conversation

braised-babbage
Copy link
Contributor

@braised-babbage braised-babbage commented Oct 23, 2019

Description

This is an overhaul of the previous code generating LaTeX circuits. I've got an example notebook included in the the examples directory. This resolves #1023.

Checklist

  • The above description motivates these changes.
  • There is a unit test that covers these changes.
  • All new and existing tests pass locally and on Semaphore.
  • Parameters have type hints with PEP 484 syntax.
  • Functions and classes have useful sphinx-style docstrings.
  • (New Feature) The docs have been updated accordingly.
  • (Bugfix) The associated issue is referenced above using
    auto-close keywords.
  • The changelog is updated,
    including author and PR number (@username, gh-xxx).

@braised-babbage
Copy link
Contributor Author

braised-babbage commented Oct 23, 2019

The previous routine was not very usable, and generated ugly stuff like:
mystery (1)
(That's X 0; CNOT 0 1; H 1)

With the update, this renders as
no-mystery

Attached is an example of the usage of this (showing basic functionality, showing the use of custom settings, and showing the new PRAGMA LATEX_GATE_GROUP feature).
LaTeX Circuits.pdf

@notmgsk
Copy link
Contributor

notmgsk commented Oct 24, 2019

The original has a drop-shadow. I dunno if I can approve not having a drop-shadow.

Copy link
Contributor

@notmgsk notmgsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Looks like there is a missing dataclasses import according to the test errors.

pyquil/latex/ipython.py Outdated Show resolved Hide resolved
pyquil/latex/latex_generation.py Outdated Show resolved Hide resolved
pyquil/latex/latex_generation.py Outdated Show resolved Hide resolved
@braised-babbage braised-babbage force-pushed the feature/generate-quantikz-circuit-code branch 2 times, most recently from b3aaf68 to 30e58ee Compare October 25, 2019 17:20
@braised-babbage braised-babbage marked this pull request as ready for review October 25, 2019 21:08
@braised-babbage braised-babbage requested a review from a team as a code owner October 25, 2019 21:08
@karalekas karalekas added the enhancement ✨ A request for a new feature. label Oct 29, 2019
pyquil/latex/ipython.py Outdated Show resolved Hide resolved
pyquil/latex/ipython.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
pyquil/tests/test_latex.py Outdated Show resolved Hide resolved
pyquil/latex/latex_generation.py Outdated Show resolved Hide resolved
}
],
"source": [
"prog = Program(\"X 0\\n CNOT 0 1\\n H 1\")\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use += to build up programs -- if its annoying to use += then we should open an issue to fix whatever your pain points are (maybe the pragma and dagger?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the first two examples to avoid using escape characters etc. Those are built using the gate objects, e.g. Program(X(0), CNOT(0,1), H(1)). For the last example I'm going to keep it as a big multiline string -- this is how it came to me (I generated it from the compiler), and I don't think anything would be improved by changing this.

],
"source": [
"# extra kwargs are passed are passed straight to `IPython.display.Image`\n",
"display(prog, width=300)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gives me an obscure error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-3-6f822dbd0b9c> in <module>
      1 # extra kwargs are passed are passed straight to `IPython.display.Image`
----> 2 display(prog, width=300)

~/code/rigetti/github/pyquil/pyquil/latex/ipython.py in display(circuit, settings, **image_options)
     40         result = subprocess.call([pdflatex_path, "-output-directory", tmpdir, texfile.name])
     41         if result != 0:
---> 42             raise RuntimeError("pdflatex error")
     43 
     44         png = os.path.join(tmpdir, 'diagram.png')

RuntimeError: pdflatex error

which I see in my jupyter notebook logs is actually:

! Package tikz Error: I did not find the tikz library 'quantikz'. I looked for
files named tikzlibraryquantikz.code.tex and pgflibraryquantikz.code.tex, but n
either could be found in the current texmf trees..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add some good documentation for installing all the requirements for this module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding sphinx docs, and also adding a bit more care to the error reporting here.

pyquil/latex/ipython.py Outdated Show resolved Hide resolved
examples/LaTeX Circuits.ipynb Outdated Show resolved Hide resolved
@karalekas
Copy link
Contributor

Also, need to update the changelog -- I think this warrants the "Announcements" section.

@karalekas karalekas changed the title Overhaul LaTeX Circuits Overhaul Quil to LaTeX circuit generation Oct 30, 2019
@karalekas
Copy link
Contributor

Also -- do we have a way of aligning measurement (or any gates for that matter)? See the following example where I try to measure both qubits but everything is left justified:

image

@braised-babbage
Copy link
Contributor Author

braised-babbage commented Oct 30, 2019

There are two open features left to implement:

  • Add support for rendering RESET instructions as feedback subprograms.
  • Add optional support for right-alignment of terminal MEASURE instructions (on by default).

These could be part of this PR or could be part of a separate one (I think the latter is fairly easy to implement, but am running out of time for this today).

Copy link
Contributor

@karalekas karalekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some more stuff

requirements.txt Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
pyquil/latex/latex_generation.py Outdated Show resolved Hide resolved
pyquil/latex/_ipython.py Show resolved Hide resolved
pyquil/latex/latex_generation.py Outdated Show resolved Hide resolved
@karalekas
Copy link
Contributor

still need to update changelog, and I think the right alignment should be done for this PR. RESET and classical feedback control can definitely be another PR

@braised-babbage
Copy link
Contributor Author

This should be essentially good to go. I've incorporated feedback, and added support for alignment of terminal measurements e.g.
aligned

@braised-babbage braised-babbage force-pushed the feature/generate-quantikz-circuit-code branch from 99003e6 to 8a33153 Compare November 1, 2019 17:12
@karalekas karalekas added this to the v2.13 milestone Nov 1, 2019
Copy link
Contributor

@karalekas karalekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great

@karalekas karalekas merged commit dc07bae into master Nov 1, 2019
@karalekas karalekas deleted the feature/generate-quantikz-circuit-code branch November 1, 2019 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ A request for a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework and improve the LaTeX generation functionality
3 participants