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.2.0.tar.gz (143.4 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.2.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gatefold-0.2.0.tar.gz
  • Upload date:
  • Size: 143.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 94eabc6ef42590013e59e8a571ada545bb62aa97db68dfdca1eaa89cfc075c72
MD5 a71c0196d6bd044ba1ebf3358d6137e8
BLAKE2b-256 d7a6ab78927a4d0bb204a3b4d54b9994a3c2d4c67017050bc65ab3a453bd9549

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gatefold-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0faec1b55cc8daf647ffccd1e9dc8d47329362b3268c5dc70b418cffbf679da0
MD5 a2b7ed413b0e6843d116087bfeb97269
BLAKE2b-256 f90e1cd1b0db7eecc91b3f884927022f4d7af5f1624a7f78f515cfd3284910a6

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

0.3.2

2 files

0.3.0

2 files

This release

0.2.0 This release

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