Skip to main content

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 a style key.

  • 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.

  • style is yours to define. gatefold just uses it to look up a StyleSpec in a Palette you can define. The Palette is a dictionary mapping the "types" of gates you want to the StyleSpec you 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 the Item class.

  • 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

gatefold-0.3.0.tar.gz (145.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gatefold-0.3.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

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

Hashes for gatefold-0.3.0.tar.gz
Algorithm Hash digest
SHA256 959d3b2a32451f0f74fd674876c0c595f508c137d8bfb7915a8004b84d52d555
MD5 b18bb6e15f2953033a0c2f630a406901
BLAKE2b-256 271d1526ba6b8a3e5bf4750130f0c1884599ee2918eeba4d5272c08b38c6590f

See more details on using hashes here.

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

Hashes for gatefold-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 600db6be0e9e1d1a60d89b53086f28bd6b28e6871e715c89ce1102c25eb05616
MD5 05eb632d83dda4473a75f5b0319f0e3b
BLAKE2b-256 9745e85a30c365ae95e49312cf344411b79c2b830502a0fe0fc49fbf5d32b748

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

0.3.2

2 files

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page