Metadata-Version: 2.5
Name: qdsr-audit
Version: 0.1.0
Summary: Open-source statistical, quantum-search, and QML post-selection auditing library: Heavy-Tail Q-DSR_nu, Minimax SIPS_infinity, Manski-Rosenbaum bounds, Welch-MIA duality, Detection Loophole/CbD, Classical Shadows, and Barren Plateau diagnostics.
Project-URL: Homepage, https://audit.wallstreetdebug.com
Project-URL: Repository, https://github.com/fabien-pierret/qdsr-audit
Project-URL: Research Suite, https://github.com/fabien-pierret/dcqe-postselection-ai
Project-URL: Paper 1 (Q-DSR_nu), https://doi.org/10.5281/zenodo.24591340
Project-URL: Paper 2 (Loopholes & CbD), https://doi.org/10.5281/zenodo.24591378
Project-URL: Paper 3 (SIPS_infty & MIA), https://doi.org/10.5281/zenodo.24591422
Project-URL: Zenodo Software DOI, https://doi.org/10.5281/zenodo.24591062
Author: Fabien Pierret
Maintainer: Fabien Pierret
License: MIT
License-File: LICENSE
Keywords: ai-safety,barren-plateaus,classical-shadows,contextuality-by-default,deflated-sharpe-ratio,detection-loophole,grover-search,heavy-tails,membership-inference,multiple-testing,post-selection,quantum-computing,quantum-machine-learning
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24.0
Requires-Dist: scipy>=1.10.0
Provides-Extra: dev
Requires-Dist: build>=1.2.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Requires-Dist: twine>=5.1.0; extra == 'dev'
Provides-Extra: plots
Requires-Dist: matplotlib>=3.7.0; extra == 'plots'
Description-Content-Type: text/markdown

# `qdsr-audit` — Quantum Overfitting, Post-Selection & QML Statistical Auditing Library

[![License: MIT](https://img.shields.io/badge/License-MIT-0E8A78.svg)](./LICENSE)
[![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-1B3B6F.svg)](https://www.python.org/downloads/)
[![Software DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24591062.svg)](https://doi.org/10.5281/zenodo.24591062)
[![Paper 1 DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24591340.svg)](https://doi.org/10.5281/zenodo.24591340)
[![Paper 2 DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24591378.svg)](https://doi.org/10.5281/zenodo.24591378)
[![Paper 3 DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24591422.svg)](https://doi.org/10.5281/zenodo.24591422)
[![ORCID](https://img.shields.io/badge/ORCID-0009--0001--1223--2170-A6CE39.svg)](https://orcid.org/0009-0001-1223-2170)

**Live Web Demo:** [https://audit.wallstreetdebug.com](https://audit.wallstreetdebug.com) · **Research Suite:** [fabien-pierret/dcqe-postselection-ai](https://github.com/fabien-pierret/dcqe-postselection-ai)

---

## Why `qdsr-audit`?

Quadratic quantum search (Grover / Dürr–Høyer / amplitude amplification), variational Quantum Machine Learning (QML), and selective AI evaluation pipelines share a silent statistical hazard: **post-selection overfitting**.

- At a fixed oracle query budget $C$, Grover search probes $M_{\mathrm{quant}}(C) = \lfloor (4C/\pi)^2 \rfloor$ hypotheses. On null heavy-tailed Student-$t_3$ data, it amplifies false in-sample discoveries by **$11.76\times$** at $C=1{,}000$ while out-of-sample expectation stays identically **$0$** — causing $C$-indexed Bonferroni and classical Gaussian Deflated Sharpe Ratios (DSR) to suffer **$53.4\%\text{--}100\%$ False Positive Rates**.
- Deep variational circuits trigger **$2^{-n}$ (local) and $4^{-n}$ (global) barren plateaus** and exponential kernel concentration, while noisy two-copy quantum memory loses its exponential advantage above depolarizing threshold $p_{\mathrm{cross}} = 1 - 1/\sqrt{2} \approx 29.29\%$.
- Selective abstention or rejection sampling ($\eta < 1$) opens a **detection loophole** ($\eta^* = 2/(1+\sqrt{2}) \approx 82.84\%$) creating spurious CHSH $> 2$ artifacts in both quantum optics and LLM benchmarks.
- Any linear post-selection audit score $\sum_k w_k I_k$ has **minimax risk $R_{\max} = 1$** against single-mode failure manifolds.

`qdsr-audit` turns these peer-verifiable theorems (**4 CERN Zenodo DOIs**) into a lightweight, zero-bloat (`numpy` + `scipy` only), strictly classical/unitary Python library and CLI — **zero quantum woo**.

---

## Installation

```bash
pip install qdsr-audit
```

From source (editable install with dev tools):

```bash
git clone https://github.com/fabien-pierret/qdsr-audit.git
cd qdsr-audit
pip install -e ".[dev]"
```

---

## Quickstart (Python API)

### 1. Heavy-Tail $\mathrm{Q\text{-}DSR}_\nu$ & Quantum Overfitting Audit (Paper 1)

```python
from qdsr_audit import compute_qdsr_audit, simulate_grover_search

# Audit a 4-year daily strategy (Sharpe = 3.2, T = 1,000) found via C = 1,000 Grover queries on Student-t_3 data
res = compute_qdsr_audit(
    sharpe_observed=3.2,
    query_budget_c=1000,
    sample_size_t=1000,
    search_mode="quantum_grover",
    tail_regime="student_t",
    student_nu=3.0,
)
print(res.verdict_code)           # POST_SELECTION_MIRAGE
print(f"Exact Q-DSR_nu: {res.qdsr_exact:.4f} (FWER p = {res.p_value_fwer_exact:.4f})")
print(f"Naive DSR(C):   {res.naive_dsr_c:.4f} (False green light: {res.false_green_light_trap})")
print(f"Amplification:  {res.amplification_ratio_at_c:.2f}x")

# Run an exact 10-qubit (M = 1,024) unitary statevector Grover overfitting check
grover = simulate_grover_search(q_qubits=10, tail_regime="student_t", student_nu=3.0, seed=42)
print(f"Unitarity err: {grover.unitarity_norm_err:.2e}, P_succ: {grover.p_succ_exact:.6f}")
```

### 2. Minimax $\mathrm{SIPS}_\infty$, Manski–Rosenbaum Bounds & Welch–MIA Duality (Paper 3)

```python
from qdsr_audit import compute_sips_audit, compute_welch_mia_duality

# Single-mode multiplicity failure: linear average = 0.235 (FALSE PASS), SIPS_infty = 0.85 (VETO)
sips = compute_sips_audit(i_mul=0.85, i_ood=0.04, i_inv=0.03, i_col=0.02)
print(sips.verdict_code, "| linear blindness exposed:", sips.linear_blindness_exposed)

# Welch-bound neural superposition <-> white-box MIA privacy duality (V_AI^2 + D_MIA^2 <= 1)
mia = compute_welch_mia_duality(bottleneck_dim_d=16, num_features_m=64)
print(f"rho={mia.rho:.1f} -> D_MIA={mia.d_mia_whitebox_opt:.3f}, V_AI^2+D_MIA^2={mia.duality_sum:.3f} <= 1")
```

### 3. QML Barren Plateaus, Pauli Classical Shadows & Detection Loopholes (Exp 5, 6, 7 & Paper 2)

```python
from qdsr_audit import (
    barren_plateau_audit,
    run_pauli_shadows_benchmark,
    simulate_lhv_loophole_point,
    compute_cbd_cycle,
    spectral_effective_multiplicity,
)

bp = barren_plateau_audit(n_qubits=6, depth=12, n_samples=200, seed=42)
print(f"Local shots: {bp.shots_required_local_snr1:.1f} vs Global shots: {bp.shots_required_global_snr1:.1f}")

sh = run_pauli_shadows_benchmark(n_qubits=4, n_shots=6000, weight=2, seed=42)
print(f"Classical Shadows max err: {sh.shadow_max_error:.4f} vs Dedicated: {sh.dedicated_max_error:.4f}")

lhv = simulate_lhv_loophole_point(eta=0.828427, n_pairs=80_000, seed=42)
print(f"Post-selected S={lhv['s_post_mc']:.3f} -> Loophole-free S={lhv['s_filled_mc']:.3f}")
```

---

## Command-Line Interface (`qdsr-audit`)

```bash
# Audit a 4-year Sharpe 3.2 strategy under Grover search + heavy tails
qdsr-audit check --sharpe 3.2 --trials 1000 --t-obs 1000 --mode quantum --tail student_t --nu 3

# Audit a multi-strategy backtest CSV
qdsr-audit csv examples/sample_backtest_returns.csv --tail student_t --nu 3

# Exact unitary Grover simulation
qdsr-audit grover --qubits 10 --nu 3

# Minimax SIPS_infinity four-pillar audit
qdsr-audit sips --mul 0.85 --ood 0.04 --inv 0.03 --col 0.02

# Welch-Superposition <-> MIA privacy duality
qdsr-audit mia --dim 16 --features 64

# Bell-CHSH / LLM detection loophole check
qdsr-audit loophole --eta 0.80

# Pauli Classical Shadows & HEA Barren Plateaus diagnostics
qdsr-audit shadows --qubits 4 --shots 6000 --weight 2
qdsr-audit barren --qubits 6 --depth 12

# Print BibTeX citation & Zenodo CERN DOIs
qdsr-audit cite
```

Add `--json` to any analytical subcommand for machine-readable CI/CD and agent integration.

---

## Module Overview

| Module | Scientific Basis | Key Functions |
| :--- | :--- | :--- |
| `qdsr_audit.qdsr` | Paper 1 (`10.5281/zenodo.24591340`) | `compute_qdsr_audit`, `exact_evt_scores`, `exact_evt_threshold`, `theoretical_amplification_ratio`, `landauer_selection_bounds`, `simulate_grover_search`, `audit_returns_matrix`, `audit_csv` |
| `qdsr_audit.sips` | Paper 3 (`10.5281/zenodo.24591422`) | `compute_sips_audit`, `compute_manski_rosenbaum_point`, `compute_welch_mia_duality`, `build_welch_tight_frame`, `audit_dictionary_superposition` |
| `qdsr_audit.loophole` | Paper 2 (`10.5281/zenodo.24591378`) & Exp 7 | `simulate_lhv_loophole_point`, `audit_bipartite_chsh`, `compute_cbd_cycle`, `spectral_effective_multiplicity` |
| `qdsr_audit.qml` | Software Suite (`10.5281/zenodo.24591062`) Exp 5–6 | `run_pauli_shadows_benchmark`, `bell_fwht_4ary`, `noisy_bell_memory_threshold`, `barren_plateau_audit`, `haar_2design_gradient_variance`, `compute_geometric_difference` |

---

## Citation

If you use `qdsr-audit` in academic research, QML benchmarking, or AI safety evaluations, please cite:

```bibtex
@software{pierret2026qdsr_audit,
  author       = {Pierret, Fabien},
  title        = {qdsr-audit: Open-Source Quantum Overfitting, Post-Selection, and QML Auditing Library},
  year         = {2026},
  version      = {0.1.0},
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.24591062},
  url          = {https://doi.org/10.5281/zenodo.24591062},
  license      = {MIT},
  note         = {ORCID: 0009-0001-1223-2170}
}
```
