QSafety QAE
qsafety-qae is a small research package for testing quantum amplitude
estimation (QAE) on safety and reliability probability models. It separates a
validated probability model from the estimator, simulator, circuit builder,
and optional QPU runner so that examples are reproducible without depending on
the original project directory.
The package supports:
- finite mixtures of fault, failure, or accident-scenario probabilities;
- exact weighted probability calculation;
- classical Monte Carlo and ideal maximum-likelihood QAE (ML-QAE) at the same equivalent oracle-query budget;
- Qiskit state preparation, Grover amplification checks, and Aer simulation;
- opt-in IBM Quantum preview and execution with a mandatory confirmation flag.
Installation
Core estimators require only NumPy:
python -m pip install qsafety-qae
Install optional circuit or IBM Runtime support when needed:
python -m pip install "qsafety-qae[qiskit]"
python -m pip install "qsafety-qae[ibm]"
Python interface
from qsafety import RiskDistribution, compare_estimators
risk = RiskDistribution(
weights=[0.25, 0.25, 0.25, 0.25],
probabilities=[0.0095, 0.0145, 0.0231, 0.0638],
labels=["very low", "low", "medium", "high"],
)
print(risk.probability)
mc, qae = compare_estimators(
risk,
powers=[0, 1, 2],
shots=1024,
repeats=1000,
seed=42,
)
print(mc.rmse, qae.rmse)
Build and validate actual Qiskit circuits:
from qsafety.circuits import build_qae_circuits, run_aer, validate_bundle
print(validate_bundle(risk, powers=[0, 1, 2]))
bundle = build_qae_circuits(risk, powers=[0, 1, 2])
result = run_aer(risk, powers=[0, 1, 2], shots=4096, seed=42)
print(result.estimate.probability)
CSV and command-line interface
Input CSV files need one row per scenario or risk stratum:
label,weight,probability
very_low,0.25,0.0095
low,0.25,0.0145
medium,0.25,0.0231
high,0.25,0.0638
qsafety validate examples/phmsa_risk_strata.csv --label-column label
qsafety compare examples/phmsa_risk_strata.csv --label-column label \
--powers 0 1 2 --shots 1024 --repeats 1000
qsafety circuits examples/phmsa_risk_strata.csv --label-column label
Commands print machine-readable JSON. The circuit command is available only
with the qiskit extra.
IBM Quantum safety guard
preview_ibm transpiles circuits but does not submit them. The returned backend
and circuit resources should be reviewed before calling run_ibm. Submission
is blocked unless confirm=True is passed explicitly.
from qsafety.ibm import preview_ibm, run_ibm
preview = preview_ibm(risk, shots=512, open_plan_only=True)
print(preview.backend, preview.executions, preview.resources)
# This is the only call that submits a QPU workload.
result = run_ibm(preview, confirm=True)
Credentials are read by qiskit-ibm-runtime; this package never stores API
tokens.
Interpretation limits
The MC/QAE comparison is an algorithm-level comparison at an equal equivalent oracle-query budget. It is not a wall-clock speed, energy-use, or end-to-end quantum-advantage claim. State preparation, transpilation, QPU queue time, and error mitigation are separate costs. Input-data and model uncertainty can also be larger than either estimator's sampling error.
The included PHMSA-derived four-stratum file is a compact worked example, not a pipeline-segment prediction model. It estimates a conditional outcome among reported incidents and must not be used as an operational safety decision rule.
Reproducible development
python -m pip install -e ".[dev,qiskit]"
pytest
python -m build
twine check dist/*
Legacy research scripts remain in the repository for traceability. Generated
study data and results stay local and are excluded from the public package.
Stable third-party integrations should use the public qsafety interface
documented above.
License and citation
The software is released under the MIT License. Citation metadata is in
CITATION.cff. The version DOI will be added after the first Zenodo archive is
created.
Metadata
Release files for qsafety-qae 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| qsafety_qae-0.1.2.tar.gz | 18.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qsafety_qae-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.0 kB
Release files / qsafety_qae-0.1.2.tar.gz
| Download URL | qsafety_qae-0.1.2.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
523d0cb0d0199d0742d065aaacd42f3308af187ddad0a8d685f95960963e6799
|
|
BLAKE2b-256 checksum How to use checksums |
0e078e7a68b784824a442364ded832474802837c4c6ab517a7c782391a07fc5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 5, 2026.
Transparency logRelease files / qsafety_qae-0.1.2-py3-none-any.whl
| Download URL | qsafety_qae-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
247c9e02cde89ec4407e6c3b70f7a3e8531d80523a07844550f470b97b50de31
|
|
BLAKE2b-256 checksum How to use checksums |
f2225a34c5d314b34a2db6f3298d41bbd960dafc299f3d34dd9d362d4f62df2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 5, 2026.
Transparency log