Transforms stabilizer state into graph state
Project description
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
stabsmust be a non-empty list of exactlynindependent commuting Pauli strings onnqubits.- Every stabilizer string must have the same length and use only the symbols
I,X,Y, andZ. controlandtargetare optional lists of qubit labels in0..n-1.controlandtargetmust be disjoint and contain no duplicates.shuffle=Truerandomizes 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
Gis the adjacency matrix of the resulting graph state.cis the completed list of control qubits.tis the completed list of target qubits.zis the subset ofcwhere a pi/2 z-rotation is applied.Ris 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+/-1phase of each reference generator relative to a signed generator basis, without requiring phase tracking insideconvert().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}}
}
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stabgraph-0.1.5.tar.gz.
File metadata
- Download URL: stabgraph-0.1.5.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b3e4e8bf41adb6f00e44717a0a0810d27fa4198dab7b9928ab0998739d3d48a
|
|
| MD5 |
8737376ecec55daea9c5eb75b3c1abe4
|
|
| BLAKE2b-256 |
1dd025fb46e829c2f3ae87598e1ac4ca521e88b7dcd5abead3a4faaceff57684
|
Provenance
The following attestation bundles were made for stabgraph-0.1.5.tar.gz:
Publisher:
publish.yml on davamaro/stabgraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stabgraph-0.1.5.tar.gz -
Subject digest:
9b3e4e8bf41adb6f00e44717a0a0810d27fa4198dab7b9928ab0998739d3d48a - Sigstore transparency entry: 1957565138
- Sigstore integration time:
-
Permalink:
davamaro/stabgraph@d9bd84cbe19cdcfe009f8f73a394f58e52180504 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/davamaro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d9bd84cbe19cdcfe009f8f73a394f58e52180504 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file stabgraph-0.1.5-py3-none-any.whl.
File metadata
- Download URL: stabgraph-0.1.5-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dc7fdcb6cf67e1fbeb93b3f3ac0894adfae5fc7dc67726985c0b3c6e7a6ce6f
|
|
| MD5 |
9d5e16d24f20ab3fa8fbd4e482862dc4
|
|
| BLAKE2b-256 |
f5044130ba0c7873a90e1c47fa6aef987eff63d32847eb031f74647b55014f36
|
Provenance
The following attestation bundles were made for stabgraph-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on davamaro/stabgraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stabgraph-0.1.5-py3-none-any.whl -
Subject digest:
2dc7fdcb6cf67e1fbeb93b3f3ac0894adfae5fc7dc67726985c0b3c6e7a6ce6f - Sigstore transparency entry: 1957565301
- Sigstore integration time:
-
Permalink:
davamaro/stabgraph@d9bd84cbe19cdcfe009f8f73a394f58e52180504 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/davamaro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d9bd84cbe19cdcfe009f8f73a394f58e52180504 -
Trigger Event:
workflow_dispatch
-
Statement type: