pyQuil programs may be converted to LaTeX circuit diagrams, or even rendered immediately in a Jupyter Notebook. The main entry point of LaTeX generation is
to_latex(). For inline rendering in a notebook, the main entry point is
Both of these functions take an optional
DiagramSettings, which may be used to control some aspects of circuit layout and appearance.
DiagramSettings(texify_numerical_constants=True, impute_missing_qubits=False, label_qubit_lines=True, abbreviate_controlled_rotations=False, qubit_line_open_wire_length=1, right_align_terminal_measurements=True)¶
Settings to control the layout and rendering of circuits.
Convert numerical constants, such as pi, to LaTeX form.
Include qubits with indices between those explicitly referenced in the Quil program.
Label qubit lines.
Write controlled rotations in a compact form.
The length by which qubit lines should be extended with open wires at the right of the diagram.
Align measurement operations which appear at the end of the program.
Translates a given pyQuil Program to a TikZ picture in a LaTeX document.
Here are some high points of the generation procedure (see
The most basic building block are the TikZ operators, which are constructed by the functions in
_diagram.py(e.g. TIKZ_CONTROL, TIKZ_NOP, TIKZ_MEASURE).
TikZ operators are maintained by a DiagramState object, with roughly each qubit line in a diagram represented as a list of TikZ operators on the
DiagramBuilderis the actual driver. This traverses a
Programand, for each instruction, performs a suitable manipulation of the
DiagramState. At the end of this, the
DiagramStateis traversed and raw LaTeX is emitted.
Most options are specified by
DiagramSettings. One exception is this: it is possible to request that a certain subset of the program is rendered as a group (and colored as such). This is specified by a new pragma in the
PRAGMA LATEX_GATE_GROUP <name>? … PRAGMA END_LATEX_GATE_GROUP
The <name> is optional, and will be used to label the group. Nested gate groups are currently not supported.
display(circuit, settings=None, **image_options)¶
Displays a PyQuil circuit as an IPython image object.
For this to work, you need two external programs,
convert, to be installed and accessible via your shell path.
Further, your LaTeX installation should include class and style files for
quantikz. If it does not, you need to install these yourself.