dense-evolution 8.1.4__tar.gz → 8.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. dense_evolution-8.1.6/PKG-INFO +366 -0
  2. dense_evolution-8.1.6/README.md +322 -0
  3. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/__init__.py +1 -1
  4. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/chunk.py +264 -552
  5. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/compiler.py +5 -0
  6. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/gates.py +5 -0
  7. dense_evolution-8.1.6/dense_evolution/healing.py +143 -0
  8. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/parser.py +5 -0
  9. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/registry.py +5 -0
  10. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/simulator.py +3 -0
  11. dense_evolution-8.1.6/dense_evolution.egg-info/PKG-INFO +366 -0
  12. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution.egg-info/SOURCES.txt +0 -1
  13. dense_evolution-8.1.6/license.md +58 -0
  14. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/pyproject.toml +1 -1
  15. dense_evolution-8.1.4/PKG-INFO +0 -1049
  16. dense_evolution-8.1.4/README.md +0 -1005
  17. dense_evolution-8.1.4/dense_evolution/healing.py +0 -281
  18. dense_evolution-8.1.4/dense_evolution/test2.py +0 -76
  19. dense_evolution-8.1.4/dense_evolution.egg-info/PKG-INFO +0 -1049
  20. dense_evolution-8.1.4/license.md +0 -58
  21. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dash.py +0 -0
  22. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution/stress_test.py +0 -0
  23. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution.egg-info/dependency_links.txt +0 -0
  24. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution.egg-info/requires.txt +0 -0
  25. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/dense_evolution.egg-info/top_level.txt +0 -0
  26. {dense_evolution-8.1.4 → dense_evolution-8.1.6}/setup.cfg +0 -0
@@ -0,0 +1,366 @@
1
+ Metadata-Version: 2.4
2
+ Name: dense-evolution
3
+ Version: 8.1.6
4
+ Summary: Micro-optimized High-Performance NISQ Statevector Quantum Circuit Simulator (Hardware-Adaptive Integration of Native NumPy, CUDA-Accelerated CuPy, and Linear Kernel Fusion via JAX JIT/XLA Compilation)
5
+ Author-email: Salvatore Pennacchio <jtatopenn@libero.it>
6
+ License: Business Source License 1.1
7
+ Project-URL: Homepage, https://github.com/tatopenn-cell/Dense-Evolution
8
+ Project-URL: Documentation, https://github.com/tatopenn-cell/Dense-Evolution/blob/main/README.md
9
+ Project-URL: Repository, https://github.com/tatopenn-cell/Dense-Evolution
10
+ Project-URL: Bug Tracker, https://github.com/tatopenn-cell/Dense-Evolution/issues
11
+ Keywords: quantum-computing,quantum-simulation,statevector,jax,cupy,cuda-acceleration,openqasm,nisq-noise,hpc,linear-kernel-fusion,dashboard,visualization
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: Other/Proprietary License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Physics
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: license.md
26
+ Requires-Dist: numpy>=1.22.0
27
+ Requires-Dist: matplotlib>=3.5.0
28
+ Requires-Dist: psutil>=5.9.0
29
+ Provides-Extra: jax
30
+ Requires-Dist: jax>=0.4.0; extra == "jax"
31
+ Requires-Dist: jaxlib>=0.4.0; extra == "jax"
32
+ Provides-Extra: gpu
33
+ Requires-Dist: cupy-cuda12x>=12.0.0; extra == "gpu"
34
+ Provides-Extra: dashboard
35
+ Requires-Dist: dash>=2.0.0; extra == "dashboard"
36
+ Requires-Dist: plotly>=5.0.0; extra == "dashboard"
37
+ Provides-Extra: full
38
+ Requires-Dist: jax>=0.4.0; extra == "full"
39
+ Requires-Dist: jaxlib>=0.4.0; extra == "full"
40
+ Requires-Dist: cupy-cuda12x>=12.0.0; extra == "full"
41
+ Requires-Dist: dash>=2.0.0; extra == "full"
42
+ Requires-Dist: plotly>=5.0.0; extra == "full"
43
+ Dynamic: license-file
44
+
45
+ ```
46
+ ██████╗ ███████╗███╗ ██╗███████╗███████╗
47
+ ██╔══██╗██╔════╝████╗ ██║██╔════╝██╔════╝
48
+ ██║ ██║█████╗ ██╔██╗ ██║███████╗█████╗
49
+ ██║ ██║██╔══╝ ██║╚██╗██║╚════██║██╔══╝
50
+ ██████╔╝███████╗██║ ╚████║███████║███████╗
51
+ ╚═════╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚══════╝
52
+ ███████╗██╗ ██╗██████╗ ██╗ ██╗ ██╗████████╗██╗ ██████╗ ███╗ ██╗
53
+ ██╔════╝██║ ██║██╔══██╗██║ ██║ ██║╚══██╔══╝██║██╔═══██╗████╗ ██║
54
+ █████╗ ██║ ██║██║ ██║██║ ██║ ██║ ██║ ██║██║ ██║██╔██╗ ██║
55
+ ██╔══╝ ╚██╗ ██╔╝██║ ██║██║ ██║ ██║ ██║ ██║██║ ██║██║╚██╗██║
56
+ ███████╗ ╚████╔╝ ██████╔╝███████╗╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║
57
+ ╚══════╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
58
+ ```
59
+
60
+
61
+ **Dense Statevector Quantum Simulator · JAX XLA · NISQ · VQE · QML**
62
+
63
+ [![CI](https://github.com/tatopenn-cell/Dense-Evolution/actions/workflows/ci.yml/badge.svg)](https://github.com/tatopenn-cell/Dense-Evolution/actions/workflows/ci.yml)
64
+ [![PyPI](https://img.shields.io/pypi/v/dense-evolution?style=flat-square&color=00e5ff)](https://pypi.org/project/dense-evolution/)
65
+ [![Python](https://img.shields.io/badge/Python-3.9+-blue?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
66
+ [![License](https://img.shields.io/badge/License-BSL_1.1-orange?style=flat-square)](LICENSE.md)
67
+ [![Build](https://img.shields.io/badge/Build-Passing-00ff9d?style=flat-square)](https://github.com/tatopenn-cell/Dense-Evolution/actions)
68
+ [![Cross-Validation CI](https://github.com/tatopenn-cell/Dense-Evolution-Ising-Tests/actions/workflows/ci.yml/badge.svg)](https://github.com/tatopenn-cell/Dense-Evolution-Ising-Tests/actions/workflows/ci.yml)
69
+ =======
70
+
71
+ **Dense Statevector Quantum Simulator · JAX XLA · NISQ · VQE · QML**
72
+
73
+ ---
74
+
75
+ ## ▍ What It Is
76
+
77
+ **Dense Evolution** is a high-performance statevector simulator engineered for deep NISQ circuits, VQE pipelines, and QML workloads. It eliminates Kronecker product overhead entirely via stride-sliced linear kernel fusion compiled through JAX XLA — keeping memory at the theoretical minimum of `2ⁿ × 16 bytes`.
78
+
79
+ The integrated `dash.py` dashboard provides live ipywidgets telemetry across 6 quantum observables per simulation run, directly inside Google Colab or Jupyter.
80
+
81
+ ---
82
+
83
+ ## ▍ Install
84
+
85
+ ```bash
86
+ pip install dense-evolution
87
+
88
+ # full stack: JAX · GPU · dashboard
89
+ pip install dense-evolution[full]
90
+
91
+ # development
92
+ git clone https://github.com/tatopenn-cell/Dense-Evolution.git
93
+ cd Dense-Evolution && pip install -e .[full]
94
+ ```
95
+
96
+ **Google Colab (3 lines):**
97
+
98
+ ```python
99
+ !git clone https://github.com/tatopenn-cell/Dense-Evolution.git
100
+ %cd Dense-Evolution
101
+ !pip install -e .
102
+ ```
103
+
104
+ ---
105
+
106
+ ## ▍ Quick Start
107
+
108
+ ```python
109
+ from dense_evolution import DenseSVSimulator, QASMParser
110
+
111
+ # parse any OpenQASM 2.0 string
112
+ qasm = """
113
+ OPENQASM 2.0;
114
+ include "qelib1.inc";
115
+ qreg q[3];
116
+ h q[0];
117
+ cx q[0], q[1];
118
+ cx q[1], q[2];
119
+ """
120
+
121
+ parser = QASMParser()
122
+ circuit = parser.parse(qasm)
123
+
124
+ sim = DenseSVSimulator(n_qubits=3)
125
+ sim.run_circuit_jit_beast_mode(circuit.ops)
126
+ ```
127
+
128
+ ---
129
+
130
+ **Dashboard (Colab / Jupyter):**
131
+
132
+ ```python
133
+ import dash
134
+ from IPython.display import display, clear_output
135
+
136
+ clear_output()
137
+ display(dash.dashboard_unificata)
138
+ ```
139
+
140
+ ---
141
+
142
+ ## ▍ Architecture
143
+
144
+ ```
145
+ dense_evolution/
146
+ ├── registry.py hardware detection · JAX / CuPy / NumPy capability flags
147
+ ├── gates.py GATES{} · PARAMETRIC_GATES{} · GATE_IDS{}
148
+ ├── noise_model.py Kraus channels · stochastic trajectory engine
149
+ ├── parser.py QASMParser · QASMCircuit · OpenQASM 2.0 / 3.0
150
+ ├── compiler.py _apply_gate_fast_step (jit) · _compile_and_run_circuit_jit
151
+ ├── simulator.py DenseSVSimulator · vmap batch VQE · chunked execution
152
+ └── dash.py ipywidgets dashboard · VQE engine · MD simulation
153
+ ```
154
+
155
+ **Data flow per run:**
156
+ ```
157
+ ▶ Run
158
+ └─ core_calcolo_quantistico() parse → JIT execute → apply noise
159
+ ├─ ottimizza_vqe() Hellmann-Feynman AD → ADAM → df_vqe_telemetry
160
+ ├─ run_md_simulation_dummy() QM/MM dynamics → df_md_telemetry + Pearson matrix
161
+ └─ build_panel_*(res) matplotlib figure → display()
162
+ ```
163
+
164
+ ---
165
+
166
+ ## ▍ Core Features
167
+
168
+ | Feature | Detail |
169
+ |---|---|
170
+ | **Linear Kernel Fusion** | Stride-sliced tensor ops via JAX XLA — zero Kronecker matrices |
171
+ | **Circuit Chunking** | Fixed-size JIT blocks eliminate tracer overhead on 1000+ gate circuits |
172
+ | **Kraus Noise Channels** | `depolarizing` `amplitude_damping` `phase_damping` `bitflip` `combined` — stochastic, O(2ⁿ) cost |
173
+ | **VQE + ADAM** | Hellmann-Feynman gradient via JAX AD · positional parameter injection into any QASM 2.0 |
174
+ | **vmap Batch Sweep** | `run_parametric_batch_jit()` evaluates full parameter grids in one JIT call |
175
+ | **Backend Agnostic** | NumPy CPU · JAX XLA CPU/TPU · CuPy CUDA — runtime selection, zero code changes |
176
+ | **Live Dashboard** | 8-panel ipywidgets telemetry: probability, VQE energy, entropy, purity, gradient, noise, θ-correction, Pearson heatmap |
177
+
178
+ ---
179
+
180
+ ## ▍ Benchmarks
181
+
182
+ > Measured on Google Colab Free Tier (CPU runtime)
183
+
184
+ | Metric | Value |
185
+ |---|---|
186
+ | Numerical drift (30-layer Ansatz, 1360 gates) | `Δ = 1.11 × 10⁻¹⁶` |
187
+ | Memory footprint @ 20q | `32 MB` (float64) · `16 MB` (float32) |
188
+ | JIT compile overhead (first run) | `< 400 ms` |
189
+ | Gate throughput after warm-up | `> 10⁶ gates/s` (CPU) |
190
+ | Maximum tested qubits (Colab Free) | `24q` stable · `33q` high-RAM runtime |
191
+
192
+ ---
193
+
194
+ ## ▍ Dashboard Panels
195
+
196
+ | Panel | Contents |
197
+ |---|---|
198
+ | **Overview** | R0 header · R1 P(\|n⟩) histogram + Top-12 states · R2 wavefunction helix 3D + metrics table · R3 noise analysis + shot histogram · R4–R6 VQE telemetry × 6 · R7 Pearson heatmap |
199
+ | **Fisica Stato** | Bloch projection · Schmidt rank · coherence vector |
200
+ | **Mosaico 1008q** | 2D probability density map up to 1008 qubits |
201
+ | **VQE Results** | 6-subplot telemetry: energy convergence, entropy, purity, ‖∇L‖, noise factor, θ-correction |
202
+ | **MD Results** | 6-subplot MD telemetry + masked Pearson correlation heatmap |
203
+ | **Performance** | Gate throughput · JIT compile time · RAM usage |
204
+
205
+ ---
206
+
207
+
208
+ ## ▍ Circuit Library (30+ presets)
209
+
210
+ All circuits are stored as OpenQASM 2.0 strings in `QASM_LIBRARY`.
211
+
212
+ **Standard** — Bell Φ⁺, QFT 4q/8q, Toffoli, Adder 2-bit, Deutsch-Jozsa, Bernstein-Vazirani
213
+ **Algorithms** — Grover 3q/4q, Simon 4q, Shor 15, HHL, QAOA Max-Cut 4q, QPE 5q, Quantum Walk, Teleportation, BB84
214
+
215
+ ---
216
+
217
+ ## ▍ VQE Engine
218
+
219
+ **Positional parameter injection** — `QASMParser` tokenizes all literals to `0.0` for JIT speed. VQE recovers parameters by:
220
+ 1. counting parametric gates (`rx ry rz p u1 cp crz`) → `n_params`
221
+ 2. initializing `θ ∈ ℝⁿ` uniform in `[−π, π]`
222
+ 3. injecting `θ[i]` sequentially by gate order in the AST via `risolvi_qasm()`
223
+
224
+ Compatible with any custom OpenQASM 2.0 string without pre-labelling.
225
+
226
+ **Gradient & update rule:**
227
+
228
+ $$\frac{\partial E}{\partial \theta_i} = \langle\psi(\theta)|\,\frac{\partial H}{\partial \theta_i}\,|\psi(\theta)\rangle \qquad \theta \leftarrow \theta - \frac{\alpha\,\hat{m}_t}{\sqrt{\hat{v}_t}+\varepsilon}$$
229
+
230
+ **Telemetry columns** (→ `df_vqe_telemetry`):
231
+
232
+ | Column | Unit | Description |
233
+ |---|---|---|
234
+ | `VQE_Energy` | Ha | ⟨ψ\|H\|ψ⟩ |
235
+ | `Entropy` | bit | −Tr(ρ log₂ ρ) |
236
+ | `Purity` | — | Tr(ρ²) ∈ [1/d, 1] |
237
+ | `Gradient` | — | ‖∇L‖ — barren plateau detection |
238
+ | `Noise_Factor` | — | fidelity-derived noise proxy |
239
+ | `Theta_Correction` | rad | ADAM step norm |
240
+
241
+ ---
242
+
243
+ ## ▍ Hamiltonian Library
244
+
245
+ Auto-filtered by qubit count to prevent shape mismatch.
246
+
247
+ | Molecule | Qubits | Bond length | E₀ (Ha) |
248
+ |---|:---:|:---:|:---:|
249
+ | H₂ | 2 | 0.74 Å | −1.13 |
250
+ | H₃⁺ | 3 | 0.85 Å | −1.28 |
251
+ | LiH | 4 | 1.40 Å | −2.31 |
252
+ | H₂O | 5 | 0.96 Å | −4.12 |
253
+
254
+ Custom: JSON array of diagonal eigenvalues, length `2^n_qubits`.
255
+
256
+ ---
257
+
258
+ ## ▍ Noise Models
259
+
260
+ All channels applied as post-circuit Kraus operations on the full statevector.
261
+
262
+ | Model | Kraus operators | Physical process |
263
+ |---|---|---|
264
+ | `ideal` | I | noiseless |
265
+ | `depolarizing` | {√(1−p)I, √(p/3)X,Y,Z} | isotropic Pauli error |
266
+ | `amplitude_damping` | {K₀, K₁} | T₁ energy relaxation |
267
+ | `phase_damping` | {K₀, K₁} | T₂ dephasing |
268
+ | `bitflip` | {√(1−p)I, √p·X} | bit flip σₓ |
269
+ | `combined` | depolarizing(p/2) ∘ amp_damp(p/3) | worst-case NISQ |
270
+
271
+ Fidelity: Bhattacharyya `F = Σᵢ √(pᵢqᵢ)` and TVD `= ½Σᵢ|pᵢ−qᵢ|` computed on every noisy run.
272
+
273
+ ---
274
+
275
+ ## ▍ Mitigation & Predictive Healing Models
276
+
277
+ Active error tracking and stabilization parameters integrated natively into the simulation runtime.
278
+
279
+
280
+ | Model | Variables / Operators | Physical process |
281
+ |---|---|---|
282
+ | `dephasing_tracking` | Δ_pre_emp ∘ Σ | predictive deviation vs ideal eigenstate |
283
+ | `kappa_stabilization` | κ-strength routine | proactive statevector profile shielding |
284
+ | `richardson_integration` | {λ₁ = 1.0, λ₂ = 2.0} | dual-point zero-noise trajectory approximation |
285
+
286
+ Compilation: Full **XLA Kernel Fusion** via `@jax.jit` for mass-parallelized trajectory sweeps (< 1.0s).
287
+
288
+ ---
289
+
290
+ ## ▍ Chunk Engines (Anti-OOM)
291
+
292
+ All operations parcellized dynamically using dual-stage longitudinal and transverse architectural shields.
293
+
294
+
295
+ | Model | Execution parameters | Physical process |
296
+ |---|---|---|
297
+ | `chunk1` | `circuit_slice = target[i : i + chunk_size]` | instruction loop-unroll kill |
298
+ | `chunk2` | `alloc_dim = 2 ** chunk_size_bits` | transverse Hilbert slicing |
299
+ | `Chunk` | `sim = Chunk(n_qubits)` | hardware-adaptive anti-OOM |
300
+
301
+ Performance: Hard-locked at `15%` max RAM available with **-86.47% Latency Collapse** via global static JIT cache injection.
302
+
303
+ ---
304
+
305
+ ### 🪐 [SHIELD::OOM] // Chunk Engine
306
+
307
+ ```python
308
+ from dense_evolution import Chunk
309
+
310
+ sim = Chunk(27)
311
+ circuit_ops = [['h', i] for i in range(27)]
312
+ sim.run_chunk(circuit_ops, 500)
313
+ ```
314
+
315
+ ### 🧬 [SYS::ARCH]
316
+ * `chunk1` -> Slices gate arrays into windows to kill JAX compilation stalls.
317
+ * `chunk2` -> Slices raw Hilbert statevectors into isolated RAM allocations.
318
+
319
+ ### ⚡ [BENCH::VERDICT]
320
+ * **Qubits**: 27 Qubits // 134M States.
321
+ * **Memory**: Hard-locked at 15% RAM threshold.
322
+ * **Speed**: **-86.47% Latency Collapse** via Static JIT.
323
+
324
+ \---
325
+
326
+ ### Anti-OOM Chunk Engine vs PennyLane — Windows CPU (8 GB RAM)
327
+
328
+ > Dense Evolution maintains constant ~2 GB RAM at any qubit count via dynamic chunking.
329
+ > PennyLane allocates the full statevector — OOM beyond 26q.
330
+
331
+
332
+ | Qubits | Hilbert Space | PennyLane | PennyLane RAM | Dense Evolution | Dense RAM | Chunk Geometry |
333
+ |:------:|:-------------:|:---------:|:-------------:|:---------------:|:---------:|:--------------:|
334
+ | 24 | 16,777,216 | ✅ SUCCESS | 307 MB | ✅ SUCCESS | 516 MB | 1× (2²⁷) |
335
+ | 26 | 67,108,864 | ✅ SUCCESS | 1,074 MB | ✅ SUCCESS | 2,050 MB | 1× (2²⁷) |
336
+ | 28 | 268,435,456 | ❌ OOM | — | ✅ SUCCESS | 2,050 MB | 2× (2²⁷) |
337
+ | 30 | 1,073,741,824 | ❌ OOM | — | ✅ SUCCESS | 2,048 MB | 8× (2²⁷) |
338
+ | 32 | 4,294,967,296 | ❌ OOM | — | ✅ SUCCESS | 2,048 MB | 32× (2²⁷) |
339
+
340
+ ---
341
+
342
+ ## ▍ Changelog
343
+
344
+ ### v8.1.5
345
+ - `chunk.py` — `SafeMemoryGuard` class: hard block at configurable free-RAM threshold (default 15%), soft warning at 2× threshold, `gc.collect()` before every check
346
+ - `chunk.py` — `Chunk` no longer subclasses `DenseSVSimulator`; inner simulator allocated at `safe_qubits` only — eliminates `RESOURCE_EXHAUSTED` on 28q–34q circuits
347
+ - `chunk.py` — `CircuitChunker.split_circuit` RAM-checks every gate-slice before dispatch
348
+ - `chunk.py` — `MemoryChunker` attributes (`num_chunks`, `chunk_size_bits`, `dtype`) forwarded as `@property` on `Chunk` for benchmark compatibility
349
+
350
+ ### v8.1.6
351
+ - Modular package structure (`dense_evolution/` directory)
352
+ ## ▍ License
353
+
354
+ **Business Source License 1.1** — converts automatically to **Apache 2.0** on **1 June 2029**.
355
+
356
+ - Non-commercial use: unrestricted
357
+ - Commercial use: ≤ 24 allocated qubits · ≤ 1000 circuits/day · ≤ 10,000 shots/circuit
358
+ - Attribution required on all copies: `© 2026 Salvatore Pennacchio <jtatopenn@libero.it> — Dense Evolution`
359
+
360
+ Full text: [LICENSE.md](LICENSE.md)
361
+
362
+ ---
363
+
364
+ <div align="center">
365
+ <sub>© 2026 Salvatore Pennacchio — Dense Evolution</sub>
366
+ </div>
@@ -0,0 +1,322 @@
1
+ ```
2
+ ██████╗ ███████╗███╗ ██╗███████╗███████╗
3
+ ██╔══██╗██╔════╝████╗ ██║██╔════╝██╔════╝
4
+ ██║ ██║█████╗ ██╔██╗ ██║███████╗█████╗
5
+ ██║ ██║██╔══╝ ██║╚██╗██║╚════██║██╔══╝
6
+ ██████╔╝███████╗██║ ╚████║███████║███████╗
7
+ ╚═════╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚══════╝
8
+ ███████╗██╗ ██╗██████╗ ██╗ ██╗ ██╗████████╗██╗ ██████╗ ███╗ ██╗
9
+ ██╔════╝██║ ██║██╔══██╗██║ ██║ ██║╚══██╔══╝██║██╔═══██╗████╗ ██║
10
+ █████╗ ██║ ██║██║ ██║██║ ██║ ██║ ██║ ██║██║ ██║██╔██╗ ██║
11
+ ██╔══╝ ╚██╗ ██╔╝██║ ██║██║ ██║ ██║ ██║ ██║██║ ██║██║╚██╗██║
12
+ ███████╗ ╚████╔╝ ██████╔╝███████╗╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║
13
+ ╚══════╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
14
+ ```
15
+
16
+
17
+ **Dense Statevector Quantum Simulator · JAX XLA · NISQ · VQE · QML**
18
+
19
+ [![CI](https://github.com/tatopenn-cell/Dense-Evolution/actions/workflows/ci.yml/badge.svg)](https://github.com/tatopenn-cell/Dense-Evolution/actions/workflows/ci.yml)
20
+ [![PyPI](https://img.shields.io/pypi/v/dense-evolution?style=flat-square&color=00e5ff)](https://pypi.org/project/dense-evolution/)
21
+ [![Python](https://img.shields.io/badge/Python-3.9+-blue?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
22
+ [![License](https://img.shields.io/badge/License-BSL_1.1-orange?style=flat-square)](LICENSE.md)
23
+ [![Build](https://img.shields.io/badge/Build-Passing-00ff9d?style=flat-square)](https://github.com/tatopenn-cell/Dense-Evolution/actions)
24
+ [![Cross-Validation CI](https://github.com/tatopenn-cell/Dense-Evolution-Ising-Tests/actions/workflows/ci.yml/badge.svg)](https://github.com/tatopenn-cell/Dense-Evolution-Ising-Tests/actions/workflows/ci.yml)
25
+ =======
26
+
27
+ **Dense Statevector Quantum Simulator · JAX XLA · NISQ · VQE · QML**
28
+
29
+ ---
30
+
31
+ ## ▍ What It Is
32
+
33
+ **Dense Evolution** is a high-performance statevector simulator engineered for deep NISQ circuits, VQE pipelines, and QML workloads. It eliminates Kronecker product overhead entirely via stride-sliced linear kernel fusion compiled through JAX XLA — keeping memory at the theoretical minimum of `2ⁿ × 16 bytes`.
34
+
35
+ The integrated `dash.py` dashboard provides live ipywidgets telemetry across 6 quantum observables per simulation run, directly inside Google Colab or Jupyter.
36
+
37
+ ---
38
+
39
+ ## ▍ Install
40
+
41
+ ```bash
42
+ pip install dense-evolution
43
+
44
+ # full stack: JAX · GPU · dashboard
45
+ pip install dense-evolution[full]
46
+
47
+ # development
48
+ git clone https://github.com/tatopenn-cell/Dense-Evolution.git
49
+ cd Dense-Evolution && pip install -e .[full]
50
+ ```
51
+
52
+ **Google Colab (3 lines):**
53
+
54
+ ```python
55
+ !git clone https://github.com/tatopenn-cell/Dense-Evolution.git
56
+ %cd Dense-Evolution
57
+ !pip install -e .
58
+ ```
59
+
60
+ ---
61
+
62
+ ## ▍ Quick Start
63
+
64
+ ```python
65
+ from dense_evolution import DenseSVSimulator, QASMParser
66
+
67
+ # parse any OpenQASM 2.0 string
68
+ qasm = """
69
+ OPENQASM 2.0;
70
+ include "qelib1.inc";
71
+ qreg q[3];
72
+ h q[0];
73
+ cx q[0], q[1];
74
+ cx q[1], q[2];
75
+ """
76
+
77
+ parser = QASMParser()
78
+ circuit = parser.parse(qasm)
79
+
80
+ sim = DenseSVSimulator(n_qubits=3)
81
+ sim.run_circuit_jit_beast_mode(circuit.ops)
82
+ ```
83
+
84
+ ---
85
+
86
+ **Dashboard (Colab / Jupyter):**
87
+
88
+ ```python
89
+ import dash
90
+ from IPython.display import display, clear_output
91
+
92
+ clear_output()
93
+ display(dash.dashboard_unificata)
94
+ ```
95
+
96
+ ---
97
+
98
+ ## ▍ Architecture
99
+
100
+ ```
101
+ dense_evolution/
102
+ ├── registry.py hardware detection · JAX / CuPy / NumPy capability flags
103
+ ├── gates.py GATES{} · PARAMETRIC_GATES{} · GATE_IDS{}
104
+ ├── noise_model.py Kraus channels · stochastic trajectory engine
105
+ ├── parser.py QASMParser · QASMCircuit · OpenQASM 2.0 / 3.0
106
+ ├── compiler.py _apply_gate_fast_step (jit) · _compile_and_run_circuit_jit
107
+ ├── simulator.py DenseSVSimulator · vmap batch VQE · chunked execution
108
+ └── dash.py ipywidgets dashboard · VQE engine · MD simulation
109
+ ```
110
+
111
+ **Data flow per run:**
112
+ ```
113
+ ▶ Run
114
+ └─ core_calcolo_quantistico() parse → JIT execute → apply noise
115
+ ├─ ottimizza_vqe() Hellmann-Feynman AD → ADAM → df_vqe_telemetry
116
+ ├─ run_md_simulation_dummy() QM/MM dynamics → df_md_telemetry + Pearson matrix
117
+ └─ build_panel_*(res) matplotlib figure → display()
118
+ ```
119
+
120
+ ---
121
+
122
+ ## ▍ Core Features
123
+
124
+ | Feature | Detail |
125
+ |---|---|
126
+ | **Linear Kernel Fusion** | Stride-sliced tensor ops via JAX XLA — zero Kronecker matrices |
127
+ | **Circuit Chunking** | Fixed-size JIT blocks eliminate tracer overhead on 1000+ gate circuits |
128
+ | **Kraus Noise Channels** | `depolarizing` `amplitude_damping` `phase_damping` `bitflip` `combined` — stochastic, O(2ⁿ) cost |
129
+ | **VQE + ADAM** | Hellmann-Feynman gradient via JAX AD · positional parameter injection into any QASM 2.0 |
130
+ | **vmap Batch Sweep** | `run_parametric_batch_jit()` evaluates full parameter grids in one JIT call |
131
+ | **Backend Agnostic** | NumPy CPU · JAX XLA CPU/TPU · CuPy CUDA — runtime selection, zero code changes |
132
+ | **Live Dashboard** | 8-panel ipywidgets telemetry: probability, VQE energy, entropy, purity, gradient, noise, θ-correction, Pearson heatmap |
133
+
134
+ ---
135
+
136
+ ## ▍ Benchmarks
137
+
138
+ > Measured on Google Colab Free Tier (CPU runtime)
139
+
140
+ | Metric | Value |
141
+ |---|---|
142
+ | Numerical drift (30-layer Ansatz, 1360 gates) | `Δ = 1.11 × 10⁻¹⁶` |
143
+ | Memory footprint @ 20q | `32 MB` (float64) · `16 MB` (float32) |
144
+ | JIT compile overhead (first run) | `< 400 ms` |
145
+ | Gate throughput after warm-up | `> 10⁶ gates/s` (CPU) |
146
+ | Maximum tested qubits (Colab Free) | `24q` stable · `33q` high-RAM runtime |
147
+
148
+ ---
149
+
150
+ ## ▍ Dashboard Panels
151
+
152
+ | Panel | Contents |
153
+ |---|---|
154
+ | **Overview** | R0 header · R1 P(\|n⟩) histogram + Top-12 states · R2 wavefunction helix 3D + metrics table · R3 noise analysis + shot histogram · R4–R6 VQE telemetry × 6 · R7 Pearson heatmap |
155
+ | **Fisica Stato** | Bloch projection · Schmidt rank · coherence vector |
156
+ | **Mosaico 1008q** | 2D probability density map up to 1008 qubits |
157
+ | **VQE Results** | 6-subplot telemetry: energy convergence, entropy, purity, ‖∇L‖, noise factor, θ-correction |
158
+ | **MD Results** | 6-subplot MD telemetry + masked Pearson correlation heatmap |
159
+ | **Performance** | Gate throughput · JIT compile time · RAM usage |
160
+
161
+ ---
162
+
163
+
164
+ ## ▍ Circuit Library (30+ presets)
165
+
166
+ All circuits are stored as OpenQASM 2.0 strings in `QASM_LIBRARY`.
167
+
168
+ **Standard** — Bell Φ⁺, QFT 4q/8q, Toffoli, Adder 2-bit, Deutsch-Jozsa, Bernstein-Vazirani
169
+ **Algorithms** — Grover 3q/4q, Simon 4q, Shor 15, HHL, QAOA Max-Cut 4q, QPE 5q, Quantum Walk, Teleportation, BB84
170
+
171
+ ---
172
+
173
+ ## ▍ VQE Engine
174
+
175
+ **Positional parameter injection** — `QASMParser` tokenizes all literals to `0.0` for JIT speed. VQE recovers parameters by:
176
+ 1. counting parametric gates (`rx ry rz p u1 cp crz`) → `n_params`
177
+ 2. initializing `θ ∈ ℝⁿ` uniform in `[−π, π]`
178
+ 3. injecting `θ[i]` sequentially by gate order in the AST via `risolvi_qasm()`
179
+
180
+ Compatible with any custom OpenQASM 2.0 string without pre-labelling.
181
+
182
+ **Gradient & update rule:**
183
+
184
+ $$\frac{\partial E}{\partial \theta_i} = \langle\psi(\theta)|\,\frac{\partial H}{\partial \theta_i}\,|\psi(\theta)\rangle \qquad \theta \leftarrow \theta - \frac{\alpha\,\hat{m}_t}{\sqrt{\hat{v}_t}+\varepsilon}$$
185
+
186
+ **Telemetry columns** (→ `df_vqe_telemetry`):
187
+
188
+ | Column | Unit | Description |
189
+ |---|---|---|
190
+ | `VQE_Energy` | Ha | ⟨ψ\|H\|ψ⟩ |
191
+ | `Entropy` | bit | −Tr(ρ log₂ ρ) |
192
+ | `Purity` | — | Tr(ρ²) ∈ [1/d, 1] |
193
+ | `Gradient` | — | ‖∇L‖ — barren plateau detection |
194
+ | `Noise_Factor` | — | fidelity-derived noise proxy |
195
+ | `Theta_Correction` | rad | ADAM step norm |
196
+
197
+ ---
198
+
199
+ ## ▍ Hamiltonian Library
200
+
201
+ Auto-filtered by qubit count to prevent shape mismatch.
202
+
203
+ | Molecule | Qubits | Bond length | E₀ (Ha) |
204
+ |---|:---:|:---:|:---:|
205
+ | H₂ | 2 | 0.74 Å | −1.13 |
206
+ | H₃⁺ | 3 | 0.85 Å | −1.28 |
207
+ | LiH | 4 | 1.40 Å | −2.31 |
208
+ | H₂O | 5 | 0.96 Å | −4.12 |
209
+
210
+ Custom: JSON array of diagonal eigenvalues, length `2^n_qubits`.
211
+
212
+ ---
213
+
214
+ ## ▍ Noise Models
215
+
216
+ All channels applied as post-circuit Kraus operations on the full statevector.
217
+
218
+ | Model | Kraus operators | Physical process |
219
+ |---|---|---|
220
+ | `ideal` | I | noiseless |
221
+ | `depolarizing` | {√(1−p)I, √(p/3)X,Y,Z} | isotropic Pauli error |
222
+ | `amplitude_damping` | {K₀, K₁} | T₁ energy relaxation |
223
+ | `phase_damping` | {K₀, K₁} | T₂ dephasing |
224
+ | `bitflip` | {√(1−p)I, √p·X} | bit flip σₓ |
225
+ | `combined` | depolarizing(p/2) ∘ amp_damp(p/3) | worst-case NISQ |
226
+
227
+ Fidelity: Bhattacharyya `F = Σᵢ √(pᵢqᵢ)` and TVD `= ½Σᵢ|pᵢ−qᵢ|` computed on every noisy run.
228
+
229
+ ---
230
+
231
+ ## ▍ Mitigation & Predictive Healing Models
232
+
233
+ Active error tracking and stabilization parameters integrated natively into the simulation runtime.
234
+
235
+
236
+ | Model | Variables / Operators | Physical process |
237
+ |---|---|---|
238
+ | `dephasing_tracking` | Δ_pre_emp ∘ Σ | predictive deviation vs ideal eigenstate |
239
+ | `kappa_stabilization` | κ-strength routine | proactive statevector profile shielding |
240
+ | `richardson_integration` | {λ₁ = 1.0, λ₂ = 2.0} | dual-point zero-noise trajectory approximation |
241
+
242
+ Compilation: Full **XLA Kernel Fusion** via `@jax.jit` for mass-parallelized trajectory sweeps (< 1.0s).
243
+
244
+ ---
245
+
246
+ ## ▍ Chunk Engines (Anti-OOM)
247
+
248
+ All operations parcellized dynamically using dual-stage longitudinal and transverse architectural shields.
249
+
250
+
251
+ | Model | Execution parameters | Physical process |
252
+ |---|---|---|
253
+ | `chunk1` | `circuit_slice = target[i : i + chunk_size]` | instruction loop-unroll kill |
254
+ | `chunk2` | `alloc_dim = 2 ** chunk_size_bits` | transverse Hilbert slicing |
255
+ | `Chunk` | `sim = Chunk(n_qubits)` | hardware-adaptive anti-OOM |
256
+
257
+ Performance: Hard-locked at `15%` max RAM available with **-86.47% Latency Collapse** via global static JIT cache injection.
258
+
259
+ ---
260
+
261
+ ### 🪐 [SHIELD::OOM] // Chunk Engine
262
+
263
+ ```python
264
+ from dense_evolution import Chunk
265
+
266
+ sim = Chunk(27)
267
+ circuit_ops = [['h', i] for i in range(27)]
268
+ sim.run_chunk(circuit_ops, 500)
269
+ ```
270
+
271
+ ### 🧬 [SYS::ARCH]
272
+ * `chunk1` -> Slices gate arrays into windows to kill JAX compilation stalls.
273
+ * `chunk2` -> Slices raw Hilbert statevectors into isolated RAM allocations.
274
+
275
+ ### ⚡ [BENCH::VERDICT]
276
+ * **Qubits**: 27 Qubits // 134M States.
277
+ * **Memory**: Hard-locked at 15% RAM threshold.
278
+ * **Speed**: **-86.47% Latency Collapse** via Static JIT.
279
+
280
+ \---
281
+
282
+ ### Anti-OOM Chunk Engine vs PennyLane — Windows CPU (8 GB RAM)
283
+
284
+ > Dense Evolution maintains constant ~2 GB RAM at any qubit count via dynamic chunking.
285
+ > PennyLane allocates the full statevector — OOM beyond 26q.
286
+
287
+
288
+ | Qubits | Hilbert Space | PennyLane | PennyLane RAM | Dense Evolution | Dense RAM | Chunk Geometry |
289
+ |:------:|:-------------:|:---------:|:-------------:|:---------------:|:---------:|:--------------:|
290
+ | 24 | 16,777,216 | ✅ SUCCESS | 307 MB | ✅ SUCCESS | 516 MB | 1× (2²⁷) |
291
+ | 26 | 67,108,864 | ✅ SUCCESS | 1,074 MB | ✅ SUCCESS | 2,050 MB | 1× (2²⁷) |
292
+ | 28 | 268,435,456 | ❌ OOM | — | ✅ SUCCESS | 2,050 MB | 2× (2²⁷) |
293
+ | 30 | 1,073,741,824 | ❌ OOM | — | ✅ SUCCESS | 2,048 MB | 8× (2²⁷) |
294
+ | 32 | 4,294,967,296 | ❌ OOM | — | ✅ SUCCESS | 2,048 MB | 32× (2²⁷) |
295
+
296
+ ---
297
+
298
+ ## ▍ Changelog
299
+
300
+ ### v8.1.5
301
+ - `chunk.py` — `SafeMemoryGuard` class: hard block at configurable free-RAM threshold (default 15%), soft warning at 2× threshold, `gc.collect()` before every check
302
+ - `chunk.py` — `Chunk` no longer subclasses `DenseSVSimulator`; inner simulator allocated at `safe_qubits` only — eliminates `RESOURCE_EXHAUSTED` on 28q–34q circuits
303
+ - `chunk.py` — `CircuitChunker.split_circuit` RAM-checks every gate-slice before dispatch
304
+ - `chunk.py` — `MemoryChunker` attributes (`num_chunks`, `chunk_size_bits`, `dtype`) forwarded as `@property` on `Chunk` for benchmark compatibility
305
+
306
+ ### v8.1.6
307
+ - Modular package structure (`dense_evolution/` directory)
308
+ ## ▍ License
309
+
310
+ **Business Source License 1.1** — converts automatically to **Apache 2.0** on **1 June 2029**.
311
+
312
+ - Non-commercial use: unrestricted
313
+ - Commercial use: ≤ 24 allocated qubits · ≤ 1000 circuits/day · ≤ 10,000 shots/circuit
314
+ - Attribution required on all copies: `© 2026 Salvatore Pennacchio <jtatopenn@libero.it> — Dense Evolution`
315
+
316
+ Full text: [LICENSE.md](LICENSE.md)
317
+
318
+ ---
319
+
320
+ <div align="center">
321
+ <sub>© 2026 Salvatore Pennacchio — Dense Evolution</sub>
322
+ </div>
@@ -8,4 +8,4 @@ from .compiler import QuantumTranspiler
8
8
  from .registry import NoiseModel, QuantumHardwareRegistry
9
9
  from .gates import GATES, PARAMETRIC_GATES, GATE_IDS
10
10
 
11
- __version__ = "8.1.4"
11
+ __version__ = "8.1.6"