An open API service indexing awesome lists of open source software.

https://github.com/defuse/qcircuitgen

Easily draw quantum circuits for LaTeX's picture environment
https://github.com/defuse/qcircuitgen

Last synced: about 1 year ago
JSON representation

Easily draw quantum circuits for LaTeX's picture environment

Awesome Lists containing this project

README

          

Quantum Circuit Generator for LaTeX
======================================

This is a script that takes an ASCII representation of a quantum circuit and
generates commands to draw it in LaTeX's `picture` environment.

To use it, you must first copy the gates.tex file into the same folder as your
document and then, *once*, do:

\input{gates.tex}

The `picture` command generated by the script can be placed anywhere in your
document below that line.

This script takes a text description of the circuit as input. Circuits are
encoded as follows:

1. Each line of the file is one qubit (horizontal line in the circuit).
2. Each character on a line corresponds to what to draw from that position. This
could be a single-qubit gate (e.g. `Z` for the Z gate), or part of
a multi-qubit gate with a line extending upwards or downwards (explained
below).

You can draw circuits using the following primitives:

- Single Qubit Gates: `X`, `Z`, `H`, and `I` (identity).
- Control lines: `U` for a control dot with a line going up, *leaving room for
a boxed gate above*, and `P` for a control dot with a line going up, *touching
the line above*. Similarly, for control lines going down, `D` (leaving room
for a boxed gate below), and `N` (touching the line below).
- For the XOR/OPLUS symbol part of a CNOT gate, use `O`.
- For circuits with more than two qubits, you may have to draw a line "crossing
over" another one without touching. This can be done using `L` (going up) and
`V` going down.
- Swap gates can be drawn by putting an `S` on the topmost qubit of the swap and
`W` on the bottommost qubit of the swap (with optional crossover lines with
`L` as necessary).

Your input is not sanity checked, i.e. you can have lines extending upward from
the top qubit, so make sure you get your input right.

Example
=========

Here is a three-qubit circuit illustrating how to use the primitives:

SSHXIHNN
WLHZONNV
IWUIPOOO

Once the output commands are rendered, it looks like:

![Circuit Image](https://defuse.ca/images/quantum-circuit-example2.png)