pyquil.latex package¶
Generate LaTeX diagrams from a Program.
- class pyquil.latex.DiagramSettings(texify_numerical_constants: bool = True, impute_missing_qubits: bool = False, label_qubit_lines: bool = True, abbreviate_controlled_rotations: bool = False, qubit_line_open_wire_length: int = 1, right_align_terminal_measurements: bool = True)[source]¶
Bases:
objectSettings to control the layout and rendering of circuits.
- abbreviate_controlled_rotations: bool = False¶
Write controlled rotations in a compact form.
For example, RX(pi) as X_{pi}, instead of the longer R_X(pi)
- impute_missing_qubits: bool = False¶
Include qubits with indices between those explicitly referenced in the Quil program.
For example, if true, the diagram for CNOT 0 2 would have three qubit lines: 0, 1, 2.
- label_qubit_lines: bool = True¶
Label qubit lines.
- qubit_line_open_wire_length: int = 1¶
The length by which qubit lines should be extended with open wires at the right of the diagram.
The default of 1 is the natural choice. The main reason for including this option is that it may be appropriate for this to be 0 in subdiagrams.
- right_align_terminal_measurements: bool = True¶
Align measurement operations which appear at the end of the program.
- texify_numerical_constants: bool = True¶
Convert numerical constants, such as pi, to LaTeX form.
- pyquil.latex.display(circuit: Program, settings: DiagramSettings | None = None, **image_options: Any) Image[source]¶
Display a PyQuil circuit as an IPython image object.
Note
For this to work, you need two external programs,
pdflatexandconvert, to be installed and accessible via your shell path.Further, your LaTeX installation should include class and style files for
standalone,geometry,tikz, andquantikz. If it does not, you need to install these yourself.- Parameters:
circuit – The circuit to be drawn, represented as a pyquil program.
settings – An optional object of settings controlling diagram rendering and layout.
- Returns:
PNG image render of the circuit.
- pyquil.latex.to_latex(circuit: Program, settings: DiagramSettings | None = None) str[source]¶
Translate a given pyQuil Program to a TikZ picture in a LaTeX document.
Here are some high points of the generation procedure (see
pyquil/latex/_diagram.py):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
DiagramState.The
DiagramBuilderis the actual driver. This traverses aProgramand, for each instruction, performs a suitable manipulation of theDiagramState. At the end of this, theDiagramStateis 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 theProgramsource: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.
- Parameters:
circuit – The circuit to be drawn, represented as a pyquil program.
settings – An optional object of settings controlling diagram rendering and layout.
- Returns:
LaTeX document string which can be compiled.