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

Internals

ARCHITECTURE.md covers the module layout, the packing algorithm, and how text auto-fit keeps large diagrams fast — worth a read before changing the layout or drawing code.

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.2.tar.gz (152.7 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.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file gatefold-0.3.2.tar.gz.

File metadata

  • Download URL: gatefold-0.3.2.tar.gz
  • Upload date:
  • Size: 152.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gatefold-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6ef791822fa47cb5b6b0ca5b5d0c760170b13f17cf466554432ad72bed87799e
MD5 e0d8cdb797e8e32553d31bac518599b6
BLAKE2b-256 bb984b6847dff64cae1c2ace826d63d1f307a589e905e4f168d49dbf558b1e3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gatefold-0.3.2.tar.gz:

Publisher: publish.yml on alam-faisal/gatefold

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gatefold-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: gatefold-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for gatefold-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5da31d46867ff88f4a4624fe327edcd1da150817a7093c1bd299bab248bd68e6
MD5 2948ec138513369e9afe29b32bd0138f
BLAKE2b-256 db3991798a9aa438962cc368df6c945353a55cdef818e06b777111a42a5e9b6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gatefold-0.3.2-py3-none-any.whl:

Publisher: publish.yml on alam-faisal/gatefold

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.0

2 files

This release

0.3.2 This release

2 files

0.3.0

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