Skip to main content

QECX: Quantum Error Correction eXchange format

Full documentation

The Quantum Error Correction eXchange format (QECX) is a portable, self-contained and toolkit-agnostic file format for quantum-error-correction (QEC) codes and the operations, error-correction cycles and decoders needed to run them. One QECX file holds everything a compiler and a simulator or device runtime need to know: the code's algebraic definition, its register template, the circuits for every logical operation and error-correction cycle and, optionally, the configuration of supported decoders, the qubit layout (topology and geometry) and more. The goal of QECX as an abstraction is to help formalize QEC research and to simplify the sharing of codes, regardless of their implementation details, which are often tied to a specific software toolkit or hardware vendor. The aim is to get as much adoption and integration with other QEC tools as possible.

A QECX file (with the standard file extension .qecx) is a plain-text (or ZIP-achived) JSON-based document in the QECX format, with its own schema and validation rules; see what a .qecx file looks like.

QECX files for a range of codes are available in Haiqu's public QEC code library and on the QECX Examples page.

python-qecx

This repository is for the python-qecx package, the reference implementation for working with QECX files in Python. It can be used to load, parse, validate, edit and create QECX files. It also provides a command-line tool qecx that offers similar functionality.

Installation

Install it with:

pip install python-qecx

Python 3.12 or newer is required. If you also intend to pretty-print .qecx files in the terminal or render HTML previews in Jupyter notebooks, the CLI tool and Jupyter HTML renderer needs extra plotting and rendering dependencies, installed with a viewer extra:

pip install "python-qecx[viewer]"

For more details, see the Installation section in the docs.

Usage

In Python, import it as qecx:

import qecx

# load a QECX file
doc = qecx.QECXDocument.load("my_code.qecx")

# print every validation finding: errors and warnings
for finding in doc.validate():
    print(finding)

# print any information from the QECX file
print(f"{doc.code_data.n}, {doc.code_data.k}, {doc.code_data.d}")

# convert QECXDocument to a Python dict. Construct document from dict with QECXDocument.from_dict()
print(doc.to_dict())

# Requires `viewer` extra installed. Text summary of the doc, with syntax highlighting. In Jupyter renders as HTML.
doc.view().summary()

# declare BP+OSD as another decoder for the code's syndromes
doc.add_decoder(slug="bposd")

# save the QECX document to a file. Saving validates first. force_archive=True writes a ZIP archive
doc.save("my_code_copy.qecx")

For more details, see Quickstart.

CLI interface

A qecx CLI command is also provided by the package. It summarizes and validates files from the command line, implemented the same Python:

qecx my_code.qecx                               # summary
qecx my_code.qecx --validate                    # validation findings
qecx my_code.qecx --section code                # one section in detail
qecx my_code.qecx --gate cx                     # a logical gate's variants
qecx my_code.qecx --variant syndrome_measurement.sequential   # a single variant
python -m qecx my_code.qecx                     # alternative way to invoke qecx

Run qecx --help for every option. qecx command is only available in the virtual environment where the python-qecx package was installed. Install the viewer extra for syntax highlighting.

For more details, see Command line.

What a .qecx file looks like

The Steane code, taken from steane_7_1_3.qecx. The ... marks what's left out in this README, for clarity.

{
  "qec_version": "0.1",
  "code": {
    "name": "Steane Code",
    "code_type": "css",
    "n": 7, "k": 1, "d": 3,
    "H_X": [[1, 1, 1, 1, 0, 0, 0], ...],      // parity-check matrices
    "H_Z": [[1, 1, 1, 1, 0, 0, 0], ...],
    "logical_operators": {"X": ["IIIIXXX"], "Z": ["IIIIZZZ"]}
  },
  "register_template": {
    "per_code_block": {
      "data_qreg": {"size": 7},
      "ancilla_qregs": {"syndrome": {"size": 3, "purpose": "syndrome"}}
    }
  },
  "operations": {
    "state_preparation": {...},               // logical |0>
    "reset": {...},
    "data_measurement": {...},
    "logical_gates": {...},                   // transversal H, S and CX
    "syndrome_measurement": {
      "default": "sequential",
      "variants": {
        "sequential": {
          ...,
          "fault_tolerant": false,
          "syndrome_cregs": [{"name": "c_z_syndrome", "source": "H_Z"}, ...],
          "qregs": {...},
          "cregs": {...},
          "qasm": "..."                       // an OpenQASM 3 circuit
        }
      }
    }
  },
  "error_correction_cycle": {
    "default": "single_sequential",
    "variants": {
      "single_sequential": {...},             // one round of syndrome measurement
      "repeated_sequential": {...}            // d rounds
    }
  },
  "decoder_config": {"tesseract": {}},        // syndrome decoders for this code
  "properties": {
    ...,
    "license": "CC-BY-4.0",
    ...,
    "references": [
      {"key": "steane_1996", "title": "Error correcting codes in quantum theory", ...},
      ...
    ]
  }
}

See Steane code example in the docs for a detailed field-by-field walkthough of a of the QECX file steane_7_1_3.qecx for a Steane code (CSS) with n=7, k=1 and d=3.

The same document can also be stored as a ZIP archive, to compress its circuits and matrices, which is useful for large QECX files. See Format Specification for more details.

Example .qecx files

Examples of codes represented as QECX files in the src/qecx/examples directory in this repository. They can be downloaded directly from this repository.

Name Code Container
steane_7_1_3.qecx Steane code (CSS) with n=7, k=1 and d=3 JSON
steane_7_1_3_stabilizer.qecx Steane code (stabilizer) with n=7, k=1 and d=3 JSON
color_488_d3.qecx Triangular 4.8.8 color code with n=7, k=1 and d=3 JSON
color_488_d5.qecx Triangular 4.8.8 color code with n=17, k=1 and d=5 JSON
color_488_d7.qecx Triangular 4.8.8 color code with n=31, k=1 and d=7 ZIP archive
color_666_d3.qecx Triangular 6.6.6 color code with n=7, k=1 and d=3 JSON
rotated_surface_d3.qecx Rotated surface code with n=9, k=1 and d=3 JSON

These example files are also bundled with the Python package in qecx.examples module:

import qecx

doc = qecx.QECXDocument.load(qecx.examples.path("steane_7_1_3.qecx")) # get path for code name and load file

qecx.examples.path(name) returns the file path inside the installed package. Copy any example code name from the table above and replace "steane_7_1_3.qecx" to load any other code instead. The same path also works the qecx command. Alternatively, to get all names of example codes available in the qecx.examples package:

import qecx

all_files = qecx.examples.names() # return a list with every example's file name, such as "steane_7_1_3.qecx"
print(all_files) # print all code names available in examples (same as the table above), pass any of the names to qecx.examples.path() to get a path for a correspondig .qecx file 

More QECX files for a range of codes are available in Haiqu's public QEC code library. For more details, see the Examples section in the docs.

Tutorials

  • using_qecx_files.ipynb: load a QECX file, see what it contains, check it, and switch to another code.
  • authoring_qecx_files.ipynb: build a document from scratch, validate and save it, edit and repair files, and write a code with more than one logical qubit.

For more details, see the Tutorials section in the docs.

Development

To install the package in an editable mode from this repo, clone it and run:

pip install -e ".[viewer]"

The project uses uv to build wheels. The dev dependency group holds the test, lint, notebook and docs tooling:

uv sync --group dev
uv run pytest              # fast suite; slow tests are skipped by default
uv run pytest -m slow      # slow tests only
uv run flake8
uv build                   # wheel and sdist in dist/
uv run make -C docs html   # docs site in docs/_build/dirhtml/
uv run make -C docs docs   # the same, then served at http://localhost:8000/

The package version comes from git tags (vX.Y.Z); untagged commits build as X.Y.devN.

License

Apache License 2.0. See LICENSE.

Metadata

Release files for python-qecx 0.1.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 python-qecx 0.1.0
File Size Uploaded Provenance Actions
python_qecx-0.1.0.tar.gz 558.8 kB Without provenance Details for python_qecx-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-qecx 0.1.0
File Interpreter ABI Platform Actions
python_qecx-0.1.0-py3-none-any.whl Python 3 none any Details for python_qecx-0.1.0-py3-none-any.whl

Total release size: 866.8 kB

Release files / python_qecx-0.1.0.tar.gz

Download URL python_qecx-0.1.0.tar.gz
Size 558.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b5b193b731ce52c098cfa853ddd14a23cd301651e8c4b923f96bbe177fdc9b9d
BLAKE2b-256 checksum
How to use checksums
168bdeb56c2b8039de45127aa45813adad57ddd38962c9dd42736f5efb59fe4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / python_qecx-0.1.0-py3-none-any.whl

Download URL python_qecx-0.1.0-py3-none-any.whl
Size 307.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
210b9bc228f621c53962950b86964a8e7ec2f7838a631fe1742dbcf99d31e443
BLAKE2b-256 checksum
How to use checksums
cf575c724a973dea981bfacd656cf333405ca9c5d8014e0e94f90504dd7ab284
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for python-qecx 0.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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