Skip to main content

A python library for visualizing Crumble circuits in Jupyter

Project description

CrumPy

Visualize quantum circuits with error propagation in a Jupyter widget.

jupyter notebook cell with quantum circuit diagram output

This package builds off of the existing circuit visualizations of Crumble, a stabilizer circuit editor and sub-project of the open-source stabilizer circuit project Stim.


Installation

Requires: Python 3.11+

pip install crumpy

Usage

CrumPy provides a convenient Jupyter widget that makes use of Crumble's ability to generate quantum circuit timeline visualizations with Pauli propagation from Stim circuit specifications.

Using CircuitWidget

CircuitWidget takes a Stim circuit specification in the form of a Python str. To convert from the official Stim package's stim.Circuit, use str(stim_circuit). If coming from another circuit type, it is recommended to first convert to a stim.Circuit (e.g., with Stim's stimcirq package), then to str. Note that not all circuits may be convertible to Stim.

from crumpy import CircuitWidget

your_circuit = """
H 0
CNOT 0 1
"""

circuit = CircuitWidget(stim=your_circuit)
circuit
quantum circuit that creates EPR pair

Propagating Paulis

A useful feature of Crumble (and CrumPy) is the ability to propagate Paulis through a quantum circuit. Propagation is done automatically based on the specified circuit and Pauli markers. From the Crumble docs:

Propagating Paulis is done by placing markers to indicate where to add terms. Each marker has a type (X, Y, or Z) and an index (0-9) indicating which indexed Pauli product the marker is modifying.

Define a Pauli X, Y, or Z marker with the #!pragma MARK_ instruction. Note that for compatibility with Stim, the '#!pragma ' is included as MARK_ is not considered a standard Stim instruction:

z_error_on_qubit_2 = "#!pragma MARKZ(0) 2"

Legend

jupyter notebook cell with quantum circuit diagram output

Example

circuit_with_error = """
#!pragma MARKX(0) 0
TICK
CNOT 0 1
TICK
H 0
"""

CircuitWidget(stim=circuit_with_error)
quantum circuit with Pauli propagation markers

Notice how the single specified Pauli X marker propagates both through the control and across the connector of the CNOT, and gets transformed into a Pauli Z error when it encounters an H gate.

Local Development

See the contribution guidelines for a quick start guide and Python best practices.

Additional requirements

npm/Node.js (for bundling JavaScript); versions 11+/22+ recommended

Project Layout

CrumPy makes use of the widget creation tool AnyWidget. With AnyWidget, Python classes are able to take JavaScript and display custom widgets in Jupyter environments. CrumPy therefore includes both JavaScript and Python subparts:

crumpy/
├── src/
│   ├── crumpy/
│   │   ├── __init__.py       # Python code for CircuitWidget
│   │   └── bundle.js         # Bundled JavaScript will appear here
│   └── js/
│       ├── crumble/          # Modified Crumble code
│       │   ├── main.js       # Main circuit visualization/setup
│       │   └── ...
│       └── package.json      # Bundling setup and scripts
├── tests/                    # Python tests
└── ...

src/crumpy contains the main Python package code.

src/crumpy/__init__.py contains the main class of the crumpy package, CircuitWidget.

src/js/crumble/ contains the modified Crumble circuit visualization code that will be rendered in the CircuitWidget widget.

src/js/crumble/main.js contains the main circuit visualization and setup logic in the form of the render function used by AnyWidget.

Bundling

To create a Jupyter widget, AnyWidget takes in JavaScript as an ECMAScript Module (ESM). Any changes made to the JavaScript code that backs the circuit visualization will require re-bundling into one optimized ESM file.

To bundle the JavaScript:

  1. Navigate to src/js
  2. If you haven't yet, run npm install (this will install the esbuild bundler)
  3. Run npm run build (or npm run watch for watch mode)

A new bundle should appear at src/crumpy/bundle.js.

Note: If you are working in a Jupyter notebook and re-bundle the JavaScript, you may need to restart the notebook kernel and rerun any widget-displaying code for the changes to take effect.

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

crumpy-0.1.0.tar.gz (42.0 kB view details)

Uploaded Source

Built Distribution

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

crumpy-0.1.0-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file crumpy-0.1.0.tar.gz.

File metadata

  • Download URL: crumpy-0.1.0.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for crumpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3efd56b131d9f9688201b8cdd61058abb96deea3c7a4b0169b0bd10e96366c04
MD5 e369272722681463324c11f82accc1c3
BLAKE2b-256 530a4403ec98e38a2514fc74e6d5eb60588b8b8688473841098b8ad9b8e87e3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for crumpy-0.1.0.tar.gz:

Publisher: cd.yml on Deltakit/crumpy

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

File details

Details for the file crumpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: crumpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for crumpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd3ef2e3a9ead1d6c1f458100b2706e0d77f3ff5a59b9354b53e96ea49ff2ce7
MD5 9e7e8188e1506d9d359f022f2d434025
BLAKE2b-256 d1361f41b964c36d7e30843650dcce3f0d56df0ba23c0c2e5a3737ca4f477f43

See more details on using hashes here.

Provenance

The following attestation bundles were made for crumpy-0.1.0-py3-none-any.whl:

Publisher: cd.yml on Deltakit/crumpy

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

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