Skip to main content

Backend-agnostic quantum circuit drawing library with Matplotlib as the first renderer.

Project description

Quantum Circuit Drawer logo

quantum-circuit-drawer

quantum-circuit-drawer draws quantum circuits from several ecosystems with one Matplotlib-based API.

The public API is now centered on two objects:

  • DrawConfig: one ordered configuration object for view, mode, saving, style, and hover
  • DrawResult: one consistent return object for managed figures, caller-owned axes, 2D, and 3D

Install

Inside your virtual environment:

python -m pip install quantum-circuit-drawer

For framework extras:

python -m pip install "quantum-circuit-drawer[qiskit]"
python -m pip install "quantum-circuit-drawer[cirq]"
python -m pip install "quantum-circuit-drawer[pennylane]"
python -m pip install "quantum-circuit-drawer[myqlm]"

Basic usage

from qiskit import QuantumCircuit

from quantum_circuit_drawer import DrawConfig, draw_quantum_circuit

circuit = QuantumCircuit(2, 1)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure(1, 0)

result = draw_quantum_circuit(
    circuit,
    config=DrawConfig(show=False),
)

figure = result.primary_figure
axes = result.primary_axes

Modes

from quantum_circuit_drawer import DrawConfig, DrawMode, draw_quantum_circuit

result = draw_quantum_circuit(
    circuit,
    config=DrawConfig(mode=DrawMode.PAGES_CONTROLS, show=True),
)

Available modes:

  • DrawMode.AUTO: notebooks default to pages; normal .py runs default to pages_controls
  • DrawMode.PAGES: one figure per page when the library owns the figure
  • DrawMode.PAGES_CONTROLS: managed Page / Visible controls
  • DrawMode.SLIDER: discrete slider navigation
  • DrawMode.FULL: full unpaged scene

Notes:

  • In 2D, pages with ax=... renders the static paged composition into that axes.
  • In 3D, pages, pages_controls, slider, and full are all supported.
  • Interactive modes require a library-managed figure, so do not combine them with ax=....

3D example

from quantum_circuit_drawer import DrawConfig, DrawMode, draw_quantum_circuit

result = draw_quantum_circuit(
    circuit,
    config=DrawConfig(
        view="3d",
        mode=DrawMode.PAGES_CONTROLS,
        topology="grid",
        topology_menu=True,
        show=False,
    ),
)

Saving

draw_quantum_circuit(
    circuit,
    config=DrawConfig(
        mode=DrawMode.SLIDER,
        output_path="circuit.png",
        show=False,
    ),
)

Interactive modes save a clean figure without widgets. Paged modes save the concatenated paged composition. full saves the full unpaged view.

Styling

from quantum_circuit_drawer import DrawConfig, draw_quantum_circuit

result = draw_quantum_circuit(
    circuit,
    config=DrawConfig(
        style={
            "theme": "paper",
            "max_page_width": 10.0,
            "wire_line_width": 1.8,
            "measurement_line_width": 1.4,
            "connection_line_width": 1.9,
        },
        hover={"enabled": True, "show_size": True},
        show=False,
    ),
)

DrawTheme now also covers the managed UI colors, hover colors, control colors, control-connection colors, and topology colors.

Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quantum_circuit_drawer-0.3.0.tar.gz (187.1 kB view details)

Uploaded Source

Built Distribution

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

quantum_circuit_drawer-0.3.0-py3-none-any.whl (152.6 kB view details)

Uploaded Python 3

File details

Details for the file quantum_circuit_drawer-0.3.0.tar.gz.

File metadata

  • Download URL: quantum_circuit_drawer-0.3.0.tar.gz
  • Upload date:
  • Size: 187.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for quantum_circuit_drawer-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2dfb45d0760f8f8e46d08c6eaa8720665c7069b139f30d88bd9de6f87c8b7020
MD5 c378cb4bdfbd2c6034c825974e686529
BLAKE2b-256 8a87f491dcacd66ce31879d9310e6a09217a6f07dbd87e3832eb5f1ec7139efd

See more details on using hashes here.

File details

Details for the file quantum_circuit_drawer-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quantum_circuit_drawer-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69403a23076dcc2c170ff0cfad70be96b6c810a9e2e55f3a5a8f8c02cab76acd
MD5 c2709cd6729e6c5260d6ee09c6c928ec
BLAKE2b-256 1985d935c0b9bf362601a3523d421ca280161e983d6e67700ef4dda63e4d4c50

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page