gatefold
Quantum circuit diagram plotting that is:
- Lightweight — the only dependency is matplotlib.
- Adaptable — gatefold can accept any circuit representation. Just write a small adapter converting your package's circuit objects into a
list[Layer]. - Sleek — a considered default palette, mathtext labels, auto-fit text, and clean packing.
pip install gatefold
# or
uv add gatefold
Usage
gatefold's whole vocabulary is Item (something drawn on one or more qubit
rows) grouped into Layers (packed left-to-right, ASAP, with a barrier
between layers).
Labels support matplotlib mathtext, e.g. r"$Z_0 Z_1^\dagger$".
Runnable versions of the examples below are in
examples/examples.ipynb.
from gatefold import Item, Layer, plot_circuit
layers = [
Layer(items=[Item(("q0",), "H"), Item(("q1",), "H")]),
Layer(items=[Item(("q0", "q1"), r"$e^{-i\theta Z_0 Z_1}$")]),
]
ax = plot_circuit(layers)
Items can span more than two rows, and a style key looks up a Palette
entry to color-code gates (e.g. by arity):
from gatefold import Item, Layer, plot_circuit, set_clean_rcparams
set_clean_rcparams() # LaTeX-like typography, call once at import time
layers = [
Layer(items=[Item(("q0",), "H", style="single"), Item(("q1",), "H", style="single")]),
Layer(items=[Item(("q0", "q3"), r"$e^{-i\theta Z_0 Z_3}$")]),
Layer(items=[Item(("q0",), "H", style="single"), Item(("q1", "q2"), "CNOT", style="multi")]),
Layer(items=[Item(("q2",), r"$R_z(\phi)$", style="single")]),
]
ax = plot_circuit(layers, qubit_display={"q0": "$q_0$", "q1": "$q_1$", "q2": "$q_2$", "q3": "$q_3$"})
Writing an adapter
An adapter is a single function, your_circuit ( + metadata) -> list[Layer]. It's the
only place that needs to know about both your package and gatefold. This is what the adapter needs to do:
-
For each gate/term in the circuit you input, it must infer three things to construct an
Item: which qubits the gate touches (tuple), a label (plain text or mathtext), and astylekey. -
Your package likely has methods to look up the first two properties from the gate/term objects the circuit is built from. If not, you need to pass metadata from which they can be inferred.
-
styleis yours to define.gatefoldjust uses it to look up aStyleSpecin aPaletteyou can define. ThePaletteis a dictionary mapping the "types" of gates you want to theStyleSpecyou want to decorate them with. For instance, you might want different styles for gates of different -arity, hardware-native vs. symbolic, etc. The adapter function must be able to infer these types and attach the appropriate style as the third argument of theItemclass. -
If your source representation has several sub-types (e.g. hardware gates vs. symbolic terms vs. encoded terms), each branch can have completely different internal logic captured in its own adapter function as long as every branch ends up emitting the same valid
list[Layer].
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gatefold-0.3.0.tar.gz.
File metadata
- Download URL: gatefold-0.3.0.tar.gz
- Upload date:
- Size: 145.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
959d3b2a32451f0f74fd674876c0c595f508c137d8bfb7915a8004b84d52d555
|
|
| MD5 |
b18bb6e15f2953033a0c2f630a406901
|
|
| BLAKE2b-256 |
271d1526ba6b8a3e5bf4750130f0c1884599ee2918eeba4d5272c08b38c6590f
|
File details
Details for the file gatefold-0.3.0-py3-none-any.whl.
File metadata
- Download URL: gatefold-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
600db6be0e9e1d1a60d89b53086f28bd6b28e6871e715c89ce1102c25eb05616
|
|
| MD5 |
05eb632d83dda4473a75f5b0319f0e3b
|
|
| BLAKE2b-256 |
9745e85a30c365ae95e49312cf344411b79c2b830502a0fe0fc49fbf5d32b748
|