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.

Versioning

Semantic versioning. The public API is the seven names re-exported from gatefold — Item, Layer, Palette, StyleSpec, DEFAULT_PALETTE, plot_circuit, set_clean_rcparams — and it will not break without a major version bump. Everything in gatefold.core / gatefold.style is internal. plot_circuit's options are keyword-only, so new ones can be added without breaking callers. Exact rendered output is not covered by this promise: diagrams may change appearance in a minor release.

License

MIT

Metadata

Release files for gatefold 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gatefold 1.0.0
File Size Uploaded Provenance Actions
gatefold-1.0.0.tar.gz 153.1 kB With provenance Details for gatefold-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gatefold 1.0.0
File Interpreter ABI Platform Actions
gatefold-1.0.0-py3-none-any.whl Python 3 none any Details for gatefold-1.0.0-py3-none-any.whl

Total release size: 163.2 kB

Release files / gatefold-1.0.0.tar.gz

Download URL gatefold-1.0.0.tar.gz
Size 153.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3f22087c5943253d6fb22c22901a856a5c8cc7a4a56b00b25a1fed66404c4e60
BLAKE2b-256 checksum
How to use checksums
c151955de29a8be462104f21847c0486db95420100ab9313a7a06543455eef00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release files / gatefold-1.0.0-py3-none-any.whl

Download URL gatefold-1.0.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
661454755648355d39f18075821ef5ef6a24305bec1b7c0eae0ab8c37c61fdff
BLAKE2b-256 checksum
How to use checksums
78e08b46c3878ae61d450a91511e22b2a2bca787dd87e75c018895dfe009e59f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Security for gatefold 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gatefold-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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