High order correlation analysis of error models.
Project description
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
Project details
Release history Release notifications | RSS feed
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 correlation_analysis-0.2.0.tar.gz.
File metadata
- Download URL: correlation_analysis-0.2.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fbd2c75f091da92d7f2d7b331a3bac6560acc7c24d20828be60c26a4cf2bd06
|
|
| MD5 |
61b6bd6f0bf62f556ccaf1a271c2e047
|
|
| BLAKE2b-256 |
b9d98958ca8000e2ff27e1d2ea630088ec23467b9523cb0e49968110ff7a5b14
|
File details
Details for the file correlation_analysis-0.2.0-py3-none-any.whl.
File metadata
- Download URL: correlation_analysis-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c956104f925990e0a7fba66eca69683541050fde9c0fb0adb796d57726778996
|
|
| MD5 |
7306042b423b68ec4a7a71b05cc52d90
|
|
| BLAKE2b-256 |
b04006d91e16e181517c2d2edc9235aa2b8222bf0e0a3a4eddc64cebe5bdc565
|