correlation
High-order correlation analysis for detector error models produced by stim.
Solvers
correlation.cal_2nd_order_correlations(...)computes 1st- and 2nd-order correlations analytically.correlation.cal_high_order_correlations(...)computes higher-order correlations cluster by cluster using a closed-form parity-moment inversion, with a numerical fallback for ill-conditioned sampled moments.correlation.TannerGraph(...)extracts hyperedges and probabilities from a detector error model.
Recommended Workflow
This repository includes a checked-in uv.lock. Prefer uv for reproducible local development and example runs:
uv sync --dev
uv run python examples/surface_code.py
uv run python examples/repetition_code.py
Installation
pip install correlation-analysis
If you only want the published package, pip is sufficient. If you are working from this repository, prefer uv sync --dev.
Quick Start
import numpy as np
import stim
import correlation
circuit = stim.Circuit.generated(
code_task="surface_code:rotated_memory_z",
distance=3,
rounds=2,
after_clifford_depolarization=0.01,
after_reset_flip_probability=0.01,
before_measure_flip_probability=0.01,
before_round_data_depolarization=0.01,
)
dets = circuit.compile_detector_sampler().sample(shots=250_000)
dem = circuit.detector_error_model(decompose_errors=True)
graph = correlation.TannerGraph(dem)
result = correlation.cal_high_order_correlations(dets, graph.hyperedges)
probs_dem = np.array(
[graph.hyperedge_probs[hyperedge] for hyperedge in graph.hyperedges],
dtype=np.float64,
)
probs_num = np.array(
[result.get(hyperedge) for hyperedge in graph.hyperedges],
dtype=np.float64,
)
print("max abs diff:", np.max(np.abs(probs_dem - probs_num)))
print("mean abs diff:", np.mean(np.abs(probs_dem - probs_num)))
If you only need pairwise correlations, use the analytic solver:
result = correlation.cal_2nd_order_correlations(dets)
boundary, edges = result.data
num_workers=1 is usually sufficient now because the common high-order path is closed form. Additional workers are mainly useful if many clusters fall back to the numerical root solver.
Documentation And Examples
- Algorithm article:
docs/high_order_correlations.typ - Compiled article:
docs/high_order_correlations.pdf - High-order example:
examples/surface_code.py - Analytic example:
examples/repetition_code.py
Development
uv sync --dev
uv run --with pytest python -m pytest -q
uv run --with ruff python -m ruff check src examples
Metadata
Release files for correlation-analysis 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| correlation_analysis-0.2.0.tar.gz | 14.9 kB | Without provenance | Details for correlation_analysis-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| correlation_analysis-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for correlation_analysis-0.2.0-py3-none-any.whl |
Total release size: 31.4 kB
Release files / correlation_analysis-0.2.0.tar.gz
| Download URL | correlation_analysis-0.2.0.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fbd2c75f091da92d7f2d7b331a3bac6560acc7c24d20828be60c26a4cf2bd06
|
|
BLAKE2b-256 checksum How to use checksums |
b9d98958ca8000e2ff27e1d2ea630088ec23467b9523cb0e49968110ff7a5b14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / correlation_analysis-0.2.0-py3-none-any.whl
| Download URL | correlation_analysis-0.2.0-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c956104f925990e0a7fba66eca69683541050fde9c0fb0adb796d57726778996
|
|
BLAKE2b-256 checksum How to use checksums |
b04006d91e16e181517c2d2edc9235aa2b8222bf0e0a3a4eddc64cebe5bdc565
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for correlation-analysis 0.2.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.