SPARQ
Spiking Physics-in-the-loop Autonomous Reinforcement triage
of Quantum emitters: the installable sparq package behind the manuscript
"Closed-loop, event-driven machine learning for autonomous triage of
single-photon emitters." The manuscript's companion repository,
a-spiking-RL-triage-of-solid-state-single-photon-emitters,
holds the experiment scripts, figure scripts and results that reproduce the
paper; this repository is the software's home for development, releases and
support.
Installation
pip install sparq-triage # physics core (numpy, scipy)
pip install sparq-triage[ml] # adds PyTorch for the estimators, twin and RL
The core (sparq.physics, sparq.exact, sparq.pulsed) imports without
PyTorch: the analytic HBT correlation functions, the exact-statistics
histogram twin, the master-equation reference and the pulsed comb analysis.
import numpy as np
from sparq import HBTConfig, sample_site, expected_histogram
rng = np.random.default_rng(0)
site = sample_site(rng, platform="NV") # literature-anchored priors
mu = expected_histogram(site, T_s=5.0, cfg=HBTConfig())
print(site.g2_0, site.is_good, mu.shape)
Analyzing your own data
analyze_histogram runs the full conventional pipeline on any measured CW
HBT histogram (dip centering, re-binning, flat-level normalization,
multi-start fit) and reports g2(0) with a parametric-bootstrap confidence
interval that propagates shot noise through every analysis step;
analyze_pulsed does the same for pulsed combs via the peak-area method.
Neither needs PyTorch.
from sparq import analyze_histogram
res = analyze_histogram(delay_ns, counts, T_s=30.0, n_bootstrap=200)
print(res["g2_0"], (res["g2_0_low"], res["g2_0_high"]),
res["single_emitter_confident"])
Sequential certification and rigorous intervals
SPRTCertifier implements Wald's sequential probability ratio test on
accumulating HBT histograms with exact Poisson log-likelihoods: acquisition
stops the moment the evidence crosses the error-rate thresholds, which on
twin benchmarks certifies bright sites in a fraction of a second instead of
a fixed 30 s dwell, at the nominal error rates. profile_likelihood_ci
gives a Wilks profile-likelihood confidence interval for g2(0) from the
exact Poisson likelihood, honest at low counts where linearized fit errors
are not. Both are torch-free; the plug-in-hypothesis caveat and the
empirical validation are documented in the module.
from sparq import SPRTCertifier, profile_likelihood_ci
cert = SPRTCertifier(site_single, site_pair, alpha=0.05, beta=0.05)
while cert.update(new_counts, dt) == "continue":
... # keep acquiring
print(cert.decision, cert.T_total, cert.expected_times())
Registering your own platform
The built-in priors (NV, hBN, GaN, SiV) are literature-anchored defaults,
not a limit: register_platform adds any emitter with your own
photophysical ranges, after which it works everywhere a platform name is
accepted (site sampling, the dataset generators, the triage environment,
the graph encoder's template).
from sparq import Platform, register_platform, sample_site
register_platform(Platform("MyQD", (0.5, 2.0), (20, 400), (0.0, 0.5),
(50, 500), (0.7, 0.99), 0.05, (5, 100), (0.5, 10)))
site = sample_site(rng, platform="MyQD")
What is in the package
sparq/
physics.py emitter photophysics, platform priors, HBT twin
(exact Poisson histogram statistics) and the full
Monte-Carlo photon-stream simulator w/ detector
impairments
exact.py numerically exact master-equation g2(tau)
pulsed.py pulsed-excitation twin + comb calibration +
conventional peak-area analysis
analysis.py g2 analysis of measured data: bootstrap and
profile-likelihood uncertainties (torch-free)
sequential.py Wald SPRT certifier on exact Poisson likelihoods
(torch-free)
datasets.py synthetic acquisition generators + loader for the
real sps-quality quantum-dot HBT data
estimators.py LM-fit baseline, CNN, surrogate-gradient spiking
network, physics-in-the-loop training
twin_torch.py differentiable twin (adjoint/pathwise gradients
through the measurement protocol) + profile
Fisher information
sac_per.py discrete-action Soft Actor-Critic + prioritized
experience replay (sum-tree)
rl_env.py closed-loop emitter-triage environment + baselines
gnn.py level-structure template graphs + message-passing
encoder for cross-platform transfer
Tests
pip install -e .[test]
pytest tests -q # a few seconds; ML tests skip when torch is absent
The suite pins the physics to exact references: the two-exponential g2 law against the master-equation eigen-decomposition, the closed-form IRF convolution against brute-force quadrature, Poisson statistics of the histogram twin, comb calibration and peak-area recovery, sum-tree replay proportionality, and the shape/gradient contracts of the estimators, the differentiable protocol twin and the triage environment. It runs in CI on every push and pull request.
Real data
The experimental quantum-dot HBT measurements used by
sparq.datasets.load_fisequr are from the openly licensed
sps-quality repository
(Kedziora et al., Mach. Learn.: Sci. Technol. 4, 045042 (2023));
they are not redistributed here.
Contributing and support
Bug reports, questions and pull requests are welcome through GitHub issues; see CONTRIBUTING.md for the development setup and the design rules. Tagged releases are published to PyPI by CI.
License and citation
Apache-2.0 (see LICENSE). Please cite the associated paper if you use this code; citation metadata is in CITATION.cff.
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 sparq_triage-0.3.0.tar.gz.
File metadata
- Download URL: sparq_triage-0.3.0.tar.gz
- Upload date:
- Size: 45.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5545c5162b5c0c70cd88dbc47c1fc72436c66ae03a7df6994ac2e3da8eb5924a
|
|
| MD5 |
3ddc548e603ebcd0868e7b1e8b7c6508
|
|
| BLAKE2b-256 |
c4493362da563d7989a3e1bd5f35747468d380540eee460a4ae04b0293549333
|
Provenance
The following attestation bundles were made for sparq_triage-0.3.0.tar.gz:
Publisher:
publish.yml on TaN-MM-Org/sparq-triage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sparq_triage-0.3.0.tar.gz -
Subject digest:
5545c5162b5c0c70cd88dbc47c1fc72436c66ae03a7df6994ac2e3da8eb5924a - Sigstore transparency entry: 2699326644
- Sigstore integration time:
-
Permalink:
TaN-MM-Org/sparq-triage@e937e1b15ee2d98829d8b917436a62e2f4c515c4 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/TaN-MM-Org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e937e1b15ee2d98829d8b917436a62e2f4c515c4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sparq_triage-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sparq_triage-0.3.0-py3-none-any.whl
- Upload date:
- Size: 40.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4711d82cfd01e4590577d4c5304165f62a340a37669745a6053847133a989ca9
|
|
| MD5 |
973f7179b20d7af9bb2ce618ec00e586
|
|
| BLAKE2b-256 |
d61c6098c9926bedc4be011c28a5710243e69e0fa9cb4ba31d1dbee99dbcf057
|
Provenance
The following attestation bundles were made for sparq_triage-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on TaN-MM-Org/sparq-triage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sparq_triage-0.3.0-py3-none-any.whl -
Subject digest:
4711d82cfd01e4590577d4c5304165f62a340a37669745a6053847133a989ca9 - Sigstore transparency entry: 2699326751
- Sigstore integration time:
-
Permalink:
TaN-MM-Org/sparq-triage@e937e1b15ee2d98829d8b917436a62e2f4c515c4 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/TaN-MM-Org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e937e1b15ee2d98829d8b917436a62e2f4c515c4 -
Trigger Event:
release
-
Statement type: