Skip to content

Commit 4e699a5

Browse files
committed
Initial public release
0 parents  commit 4e699a5

23 files changed

Lines changed: 5365 additions & 0 deletions

.github/workflows/tests.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.11", "3.12", "3.13"]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
cache: pip
24+
- name: Install package
25+
run: python -m pip install --upgrade pip && python -m pip install -e .
26+
- name: Run tests
27+
run: python -m unittest discover -s tests -v

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*.egg-info/
5+
build/
6+
dist/
7+
.venv/
8+
venv/
9+
.pytest_cache/
10+
.mypy_cache/
11+
.ruff_cache/
12+
13+
# Editors and operating systems
14+
.DS_Store
15+
.idea/
16+
.vscode/
17+
18+
# Local agent configuration
19+
.agents/
20+
.codex/
21+
22+
# Generated simulation and report artifacts
23+
/output/
24+
/tmp/
25+
26+
# Local reference papers; cite or link to their public sources instead
27+
/2411.04688v1.pdf
28+
/Boson_Sampling_with_characteristic_function.pdf

CITATION.cff

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cff-version: 1.2.0
2+
message: "If you use this software, please cite it using the metadata below."
3+
title: "Bosonic verification simulator"
4+
type: software
5+
authors:
6+
- family-names: "Chabaud"
7+
given-names: "Ulysse"
8+
version: 0.1.0
9+
date-released: 2026-08-10
10+
repository-code: "https://github.com/UlysseChabaud/bosonic-verification"
11+
url: "https://github.com/UlysseChabaud/bosonic-verification"
12+
license: MIT

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Ulysse Chabaud
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Bosonic verification simulator
2+
3+
`cv-verification` is a NumPy-based simulator for fidelity-witness protocols
4+
in four-mode bosonic experiments. It models finite-support pure input states,
5+
a passive interferometer, binary characteristic-function measurements,
6+
readout-error mitigation, and finite-sample witness estimation.
7+
8+
The implemented protocols are:
9+
10+
- `single_mode`: \(W^{(1)}=\sum_i F_i-3\);
11+
- `disjoint_two_mode`: \(F_{ij}+F_{kl}-1\) for a fixed pairing;
12+
- `max_two_mode`: the maximum of 16 intersection-corrected spanning-tree
13+
witnesses.
14+
15+
## Installation
16+
17+
Python 3.11 or later is required.
18+
19+
```bash
20+
python -m venv .venv
21+
source .venv/bin/activate
22+
python -m pip install --upgrade pip
23+
python -m pip install -e .
24+
```
25+
26+
## Run one experiment
27+
28+
```bash
29+
python -m cv_verification examples/fock_hadamard.json \
30+
--output output/runs/fock_hadamard
31+
```
32+
33+
Equivalently, after installation:
34+
35+
```bash
36+
cv-verify examples/fock_hadamard.json \
37+
--output output/runs/fock_hadamard
38+
```
39+
40+
Each run writes a machine-readable summary, resolved configuration,
41+
per-trial data, and comparison plots. Generated files are placed under
42+
`output/`, which is excluded from version control.
43+
44+
Ideal single-mode inputs may be specified as number states, normalized finite
45+
Fock vectors, or the included finite GKP-core preset. Complex coefficients and
46+
unitary entries accept real numbers, Python-style complex strings, `[real,
47+
imag]`, or `{\"real\": ..., \"imag\": ...}`.
48+
49+
## Reproduce the Fock-input scaling study
50+
51+
```bash
52+
python scripts/run_hadamard_demo.py \
53+
--output output/demo/hadamard \
54+
--repetitions 5000
55+
```
56+
57+
This studies \({|1\rangle}^{\otimes4}\) followed by the normalized
58+
Sylvester-Hadamard interferometer, using sample counts from \(1\) to \(10^7\).
59+
The preparation, interferometer, and measurement fidelities may be changed
60+
with the corresponding command-line options.
61+
62+
The \(0.5\)-target threshold and selected \(0.9/0.9\) operating point are
63+
reproduced with:
64+
65+
```bash
66+
python scripts/find_hadamard_thresholds.py \
67+
--output output/demo/hadamard_high_fidelity
68+
69+
python scripts/run_hadamard_demo.py \
70+
--output output/demo/hadamard_high_fidelity \
71+
--repetitions 5000 \
72+
--preparation-fidelity 0.9 \
73+
--interferometer-fidelity 0.9 \
74+
--measurement-fidelity 1.0
75+
```
76+
77+
## Reproduce the truncated-GKP study
78+
79+
The finite GKP preset is the normalized projection of the finite-energy
80+
square-GKP \(|0\rangle\) ansatz onto Fock levels \(0,\ldots,6\), with
81+
\(\Delta=0.5\). Run the baseline, selected operating point, sample-count
82+
sweeps, and balanced-threshold search with:
83+
84+
```bash
85+
python scripts/run_gkp_hadamard_analysis.py \
86+
--output-root output/demo \
87+
--delta 0.5 \
88+
--cutoff 6 \
89+
--repetitions 5000
90+
```
91+
92+
The exact four-mode GKP evolution is computationally heavier than the Fock
93+
example; the script reuses each exact state across all sample counts.
94+
95+
## Statistical and physical conventions
96+
97+
- States and shots are independent and identically distributed.
98+
- Preparation and interferometer imperfections remain fixed within a sweep;
99+
repeated trials vary only shot noise.
100+
- The interferometer is passive and photon-number conserving.
101+
- All ideal inputs have finite Fock support.
102+
- Scalar device fidelities select a canonical seeded pure-error model; they do
103+
not uniquely specify an experimental noise channel.
104+
- Measurement fidelity is the assignment fidelity of one joint binary
105+
characteristic-function readout. It is neither a product of four per-mode
106+
detector fidelities nor a global state fidelity.
107+
- Known symmetric assignment errors are mitigated using visibility
108+
\(v=2f_{\mathrm{meas}}-1\). Mitigation removes asymptotic bias and increases
109+
statistical uncertainty by \(1/v\).
110+
- Hoeffding bounds are distribution-free and include the 16-candidate union
111+
bound for `max_two_mode`.
112+
113+
## Tests
114+
115+
```bash
116+
python -m unittest discover -s tests -v
117+
```
118+
119+
The test suite covers Fock evolution, marginal fidelities, interferometer
120+
calibration, characteristic-function identities and norms, all witness
121+
formulas, readout mitigation, Hoeffding coverage, reproducibility, and output
122+
schemas.
123+
124+
## Citation
125+
126+
Please use the metadata in [`CITATION.cff`](CITATION.cff). A versioned Zenodo
127+
DOI can be added after the first GitHub release.
128+
129+
## License
130+
131+
This project is released under the [MIT License](LICENSE).

cv_verification/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Four-mode characteristic-function fidelity-witness simulation."""
2+
3+
from .config import SimulationConfig
4+
from .simulation import SimulationResult, run_simulation
5+
6+
__all__ = ["SimulationConfig", "SimulationResult", "run_simulation"]

cv_verification/__main__.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Command-line interface for cv_verification."""
2+
3+
from __future__ import annotations
4+
5+
import argparse
6+
import json
7+
from pathlib import Path
8+
9+
from .config import SimulationConfig
10+
from .reporting import write_simulation_result
11+
from .simulation import run_simulation
12+
13+
14+
def build_parser() -> argparse.ArgumentParser:
15+
parser = argparse.ArgumentParser(
16+
prog="cv-verify",
17+
description=(
18+
"Simulate four-mode characteristic-function fidelity witnesses"
19+
),
20+
)
21+
parser.add_argument("config", type=Path, help="JSON simulation configuration")
22+
parser.add_argument(
23+
"--output",
24+
type=Path,
25+
required=True,
26+
help="directory for JSON, CSV, and PNG outputs",
27+
)
28+
return parser
29+
30+
31+
def main() -> None:
32+
args = build_parser().parse_args()
33+
config = SimulationConfig.from_json(args.config)
34+
result = run_simulation(config)
35+
output = write_simulation_result(result, args.output)
36+
print(
37+
json.dumps(
38+
{
39+
"output": str(output.resolve()),
40+
"witness_type": result.summary["witness_type"],
41+
"estimated_witness": result.summary[
42+
"one_run_mitigated_witness"
43+
],
44+
"exact_witness": result.summary["exact_selected_witness"],
45+
"true_fidelity": result.summary["true_global_fidelity"],
46+
"empirical_precision": result.summary["empirical_precision"],
47+
"hoeffding_precision": result.summary["hoeffding_precision"],
48+
},
49+
indent=2,
50+
sort_keys=True,
51+
)
52+
)
53+
54+
55+
if __name__ == "__main__":
56+
main()

0 commit comments

Comments
 (0)