Skip to main content

StabGraph

Every stabilizer state can be transformed into a graph state by means of a local Clifford unitary. stabgraph provides a single public function, convert, that takes a stabilizer description of an n-qubit stabilizer state and returns a graph-state representation together with the local Clifford bookkeeping needed to recover the original state.

The package is useful when you want a graph-state form as an intermediate step for circuit synthesis or state-preparation workflows. Internally, the binary linear algebra is carried out over GF(2). On supported Python versions, stabgraph uses the maintained galois package for this backend. If that backend is unavailable, it falls back to a bundled NumPy implementation so the package still works.

[1] Design and Experimental Performance of Local Entanglement Witness Operators https://arxiv.org/abs/1911.01144

Installation

Install from PyPI:

python -m pip install stabgraph

For the accelerated backend on Python versions where galois is supported:

python -m pip install "stabgraph[accel]"

For local development:

git clone https://github.com/davamaro/stabgraph.git
cd stabgraph
python -m pip install -e .[test]

Usage

import stabgraph

G, c, t, z, R = stabgraph.convert(stabs, control=None, target=None, shuffle=False)

Reconstruct the signed post-processing generators and compare them with another stabilizer description:

signed_output = stabgraph.reconstruct_generators(G, t, z)
same_group = stabgraph.same_binary_stabilizer_group(
    [stab for _, stab in signed_output],
    stabs,
)
phase_signs = stabgraph.infer_generator_phase_signs(stabs, signed_output)

Input contract

  • stabs must be a non-empty list of exactly n independent commuting Pauli strings on n qubits.
  • Every stabilizer string must have the same length and use only the symbols I, X, Y, and Z.
  • control and target are optional lists of qubit labels in 0..n-1.
  • control and target must be disjoint and contain no duplicates.
  • shuffle=True randomizes the internal qubit ordering before selecting a valid control/target partition. This can be useful when searching for lower-degree graph representations.

At the moment, convert() expects exactly n independent commuting generators on n qubits. If you provide extra generators, the package now raises a clear error instead of failing later in the algorithm.

Return values

  • G is the adjacency matrix of the resulting graph state.
  • c is the completed list of control qubits.
  • t is the completed list of target qubits.
  • z is the subset of c where a pi/2 z-rotation is applied.
  • R is the binary matrix describing the stabilizer recombinations used during the transformation.

Reconstruction Helpers

The package also provides a few lightweight helper functions for checking and post-processing the output of convert():

  • reconstruct_generators(G, t, z) builds the signed generators obtained after applying the returned local Cliffords to the graph-state generators.
  • same_binary_stabilizer_group(left, right) checks whether two generator lists span the same binary stabilizer group over GF(2).
  • infer_generator_phase_signs(reference_stabs, signed_generators) infers the +/-1 phase of each reference generator relative to a signed generator basis, without requiring phase tracking inside convert().
  • recombine_generators(generators, R) applies a binary recombination matrix to either unsigned or signed generators.

Examples

Bell pair

>>> stabs = ['XX','ZZ']
>>> G , c , t , z , R = stabgraph.convert(stabs)
>>> G
np.array([[0,1],[1,0]])
>>> c
[0]
>>> t
[1]
>>> z
[]
>>> R
np.array([[1,0],[0,1]])

GHZ state fixing 0 as a control qubit and 1 as a target qubit

>>> stabs = ['XXX','ZZI','IZZ']
>>> G , c , t , z , R = stabgraph.convert(stabs,[0],[1])
>>> c
[0]
>>> t
[1,2]

Steane code in the |0> logical state. Multiple graphs can be obtained, so put shuffle=True to obtain one of them randomly chosen. The result respects the selection of control and target qubits

>>> stabs = ['XXXXIII','IXXIXXI','IIXXIXX','ZZZZIII','IZZIZZI','IIZZIZZ','ZZZZZZZ']
>>> G , c , t , z , R = stabgraph.convert(stabs, control = [0], shuffle=True)
>>> c
[0,1,2]
>>> G , c , t , z , R = stabgraph.convert(stabs, control = [2, 5], shuffle=True)
>>> c
[2,5,6]

Testing

Run the unit tests with:

python -m pytest

Continuous integration runs the test suite on supported Python versions through GitHub Actions.

Performance

Large stabilizer states can be slow because the heavy work is dense binary linear algebra over GF(2). This release also removes a few obvious Python-level bottlenecks in qubit reordering and Pauli-to-binary conversion. Notes for future backend work live in docs/ACCELERATION_NOTES.md.

Release notes

Recent user-facing changes are tracked in CHANGELOG.md.

Citation

@misc{amaro2019,
  author = 	"David Amaro",
  title = 	"StabGraph",
  year = 	"2019",
  month =   "July",
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/davamaro/stabgraph}}
}

Metadata

Release files for stabgraph 0.1.5

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

Source distribution (sdist)

Source distribution for stabgraph 0.1.5
File Size Uploaded Provenance Actions
stabgraph-0.1.5.tar.gz 16.8 kB With provenance Details for stabgraph-0.1.5.tar.gz

Built distribution (wheel)

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

Total release size: 30.8 kB

Release files / stabgraph-0.1.5.tar.gz

Download URL stabgraph-0.1.5.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9b3e4e8bf41adb6f00e44717a0a0810d27fa4198dab7b9928ab0998739d3d48a
BLAKE2b-256 checksum
How to use checksums
1dd025fb46e829c2f3ae87598e1ac4ca521e88b7dcd5abead3a4faaceff57684
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 25, 2026.

Transparency log

Release files / stabgraph-0.1.5-py3-none-any.whl

Download URL stabgraph-0.1.5-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2dc7fdcb6cf67e1fbeb93b3f3ac0894adfae5fc7dc67726985c0b3c6e7a6ce6f
BLAKE2b-256 checksum
How to use checksums
f5044130ba0c7873a90e1c47fa6aef987eff63d32847eb031f74647b55014f36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 25, 2026.

Transparency log

Security for stabgraph 0.1.5

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 stabgraph-0.1.5.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 Jun 25, 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