dense-evolution 8.3.0__py3-none-win_amd64.whl
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.
- dashboard_core/__init__.py +115 -0
- dashboard_core/_gate_tables.py +30 -0
- dashboard_core/band_structure.py +71 -0
- dashboard_core/circuit_builder_component.py +232 -0
- dashboard_core/circuit_diagram.py +216 -0
- dashboard_core/crypto_protocols.py +77 -0
- dashboard_core/engine.py +326 -0
- dashboard_core/graphical_builder.py +114 -0
- dashboard_core/hamiltonians.py +593 -0
- dashboard_core/mass_decomposition_tool.py +47 -0
- dashboard_core/mitigation.py +343 -0
- dashboard_core/native_hf_diagnostics.py +62 -0
- dashboard_core/noise_tools.py +125 -0
- dashboard_core/qasm_library.py +233 -0
- dashboard_core/qmmm.py +16 -0
- dashboard_core/rag_tool.py +45 -0
- dashboard_core/state_visuals.py +288 -0
- dashboard_core/system_limits.py +60 -0
- dashboard_core/vector_healing.py +102 -0
- dashboard_core/visuals.py +158 -0
- dashboard_core/vqe.py +533 -0
- dashboard_core/wormhole.py +580 -0
- dense_evolution/__init__.py +114 -0
- dense_evolution/autodiff.py +10 -0
- dense_evolution/backends/__init__.py +5 -0
- dense_evolution/backends/chunk/__init__.py +37 -0
- dense_evolution/backends/chunk/_engine_imports.py +57 -0
- dense_evolution/backends/chunk/circuit_chunker.py +55 -0
- dense_evolution/backends/chunk/core.py +432 -0
- dense_evolution/backends/chunk/disk_overflow.py +232 -0
- dense_evolution/backends/chunk/geometry.py +95 -0
- dense_evolution/backends/chunk/guard.py +190 -0
- dense_evolution/backends/chunk/kernels.py +531 -0
- dense_evolution/backends/mps.py +1569 -0
- dense_evolution/backends/statevector.py +616 -0
- dense_evolution/chunk.py +25 -0
- dense_evolution/circuits/__init__.py +20 -0
- dense_evolution/circuits/compiler.py +488 -0
- dense_evolution/circuits/diagram.py +94 -0
- dense_evolution/circuits/gates.py +91 -0
- dense_evolution/circuits/parser.py +632 -0
- dense_evolution/circuits/qft.py +66 -0
- dense_evolution/circuits/random_circuit.py +85 -0
- dense_evolution/circuits/registry.py +74 -0
- dense_evolution/circuits/topology.py +79 -0
- dense_evolution/circuits/trotter.py +265 -0
- dense_evolution/circuits/uccsd.py +275 -0
- dense_evolution/cli.py +199 -0
- dense_evolution/compiler.py +9 -0
- dense_evolution/config.py +49 -0
- dense_evolution/drawing.py +10 -0
- dense_evolution/entropy.py +9 -0
- dense_evolution/fermions.py +9 -0
- dense_evolution/gates.py +9 -0
- dense_evolution/harrison_tb.py +16 -0
- dense_evolution/healing.py +18 -0
- dense_evolution/interop/__init__.py +18 -0
- dense_evolution/interop/qiskit_pennylane.py +406 -0
- dense_evolution/measurement.py +10 -0
- dense_evolution/mitigation/__init__.py +54 -0
- dense_evolution/mitigation/healing.py +215 -0
- dense_evolution/mitigation/kl_divergence.py +93 -0
- dense_evolution/mitigation/magic_entropy.py +163 -0
- dense_evolution/mitigation/magic_entropy_shadows.py +262 -0
- dense_evolution/mitigation/renyi.py +168 -0
- dense_evolution/mitigation/stabilizer_renyi_entropy.py +103 -0
- dense_evolution/mitigation/zne.py +990 -0
- dense_evolution/mps.py +9 -0
- dense_evolution/native_hf/__init__.py +26 -0
- dense_evolution/native_hf/_libcint/LICENSE-libcint +10 -0
- dense_evolution/native_hf/_libcint/libdecint.dll +0 -0
- dense_evolution/native_hf/assembly.py +304 -0
- dense_evolution/native_hf/basis.py +117 -0
- dense_evolution/native_hf/boys.py +35 -0
- dense_evolution/native_hf/bridge.py +112 -0
- dense_evolution/native_hf/cartesian.py +64 -0
- dense_evolution/native_hf/coulomb.py +196 -0
- dense_evolution/native_hf/differentiable.py +53 -0
- dense_evolution/native_hf/gaussians.py +79 -0
- dense_evolution/native_hf/kinetic.py +52 -0
- dense_evolution/native_hf/libcint_bridge.py +167 -0
- dense_evolution/native_hf/overlap.py +91 -0
- dense_evolution/native_hf/scf.py +404 -0
- dense_evolution/noise/__init__.py +79 -0
- dense_evolution/noise/coherent_attack.py +264 -0
- dense_evolution/noise/cosmic_ray.py +61 -0
- dense_evolution/noise/density_matrix_channels.py +78 -0
- dense_evolution/noise/differentiable.py +66 -0
- dense_evolution/noise/kraus/__init__.py +6 -0
- dense_evolution/noise/kraus/amplitude_damping.py +47 -0
- dense_evolution/noise/kraus/bitflip.py +22 -0
- dense_evolution/noise/kraus/combined.py +16 -0
- dense_evolution/noise/kraus/depolarizing.py +47 -0
- dense_evolution/noise/kraus/ideal.py +10 -0
- dense_evolution/noise/kraus/phaseflip.py +21 -0
- dense_evolution/noise/kraus_channels.py +285 -0
- dense_evolution/noise/oscillating.py +32 -0
- dense_evolution/noise/pink.py +80 -0
- dense_evolution/observables.py +11 -0
- dense_evolution/parser.py +9 -0
- dense_evolution/physics/__init__.py +27 -0
- dense_evolution/physics/entropy.py +161 -0
- dense_evolution/physics/fermions.py +322 -0
- dense_evolution/physics/observables.py +523 -0
- dense_evolution/physics/qec.py +1113 -0
- dense_evolution/physics/spectral.py +143 -0
- dense_evolution/physics/states.py +43 -0
- dense_evolution/protocols/__init__.py +27 -0
- dense_evolution/protocols/bb84.py +133 -0
- dense_evolution/protocols/di_qkd_ghz.py +199 -0
- dense_evolution/protocols/dicka_protocol2.py +124 -0
- dense_evolution/qec.py +20 -0
- dense_evolution/qft.py +9 -0
- dense_evolution/qmmm/__init__.py +13 -0
- dense_evolution/qmmm/ase_bridge.py +97 -0
- dense_evolution/qmmm/forces.py +388 -0
- dense_evolution/qmmm/propagation.py +80 -0
- dense_evolution/qmmm/region.py +137 -0
- dense_evolution/random_circuit.py +15 -0
- dense_evolution/registry.py +9 -0
- dense_evolution/simulator.py +10 -0
- dense_evolution/solvers/__init__.py +19 -0
- dense_evolution/solvers/autodiff.py +169 -0
- dense_evolution/solvers/harrison_tb.py +189 -0
- dense_evolution/solvers/vhd_tb.py +187 -0
- dense_evolution/states.py +9 -0
- dense_evolution/topology.py +9 -0
- dense_evolution/trotter.py +9 -0
- dense_evolution/utils/__init__.py +13 -0
- dense_evolution/utils/drawing.py +101 -0
- dense_evolution/utils/mass_decomposition.py +246 -0
- dense_evolution/utils/measurement.py +94 -0
- dense_evolution/vhd_tb.py +16 -0
- dense_evolution-8.3.0.dist-info/METADATA +366 -0
- dense_evolution-8.3.0.dist-info/RECORD +165 -0
- dense_evolution-8.3.0.dist-info/WHEEL +5 -0
- dense_evolution-8.3.0.dist-info/entry_points.txt +2 -0
- dense_evolution-8.3.0.dist-info/licenses/license.md +58 -0
- dense_evolution-8.3.0.dist-info/top_level.txt +5 -0
- ia_utils/__init__.py +0 -0
- ia_utils/adversarial_vector_attack.py +196 -0
- ia_utils/rag.py +288 -0
- ia_utils/vector_healing.py +399 -0
- local_site/__init__.py +0 -0
- local_site/app/__init__.py +0 -0
- local_site/app/server.py +1009 -0
- mcp_server/__init__.py +0 -0
- mcp_server/client.py +324 -0
- mcp_server/config.py +32 -0
- mcp_server/models.py +347 -0
- mcp_server/molecules.py +71 -0
- mcp_server/server.py +119 -0
- mcp_server/tools/__init__.py +0 -0
- mcp_server/tools/chemistry_tools.py +225 -0
- mcp_server/tools/circuit_tools.py +83 -0
- mcp_server/tools/crypto_tools.py +66 -0
- mcp_server/tools/mitigation_tools.py +81 -0
- mcp_server/tools/noise_tools.py +60 -0
- mcp_server/tools/retrieval_tools.py +44 -0
- mcp_server/tools/system_tools.py +149 -0
- mcp_server/tools/wormhole_tools.py +142 -0
- mcp_server/utils/__init__.py +0 -0
- mcp_server/utils/cache.py +55 -0
- mcp_server/utils/images.py +67 -0
- mcp_server/utils/truncation.py +38 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Dense-Evolution
|
|
3
|
+
High-performance quantum statevector simulator optimized for NISQ circuits.
|
|
4
|
+
"""
|
|
5
|
+
from .backends.statevector import DenseSVSimulator
|
|
6
|
+
from .circuits.parser import QASMParser, QASMCircuit
|
|
7
|
+
from .circuits.compiler import QuantumTranspiler
|
|
8
|
+
from .noise import (NoiseModel, NoiseSpec, global_depolarizing_channel, amplitude_damping_channel,
|
|
9
|
+
phaseflip_channel_exact, cosmic_ray_burst_profile, oscillating_p_eff,
|
|
10
|
+
pink_noise_p_eff)
|
|
11
|
+
from .circuits.registry import QuantumHardwareRegistry
|
|
12
|
+
from .circuits.gates import GATES, PARAMETRIC_GATES, GATE_IDS
|
|
13
|
+
from .backends.chunk import Chunk
|
|
14
|
+
# Also bind dense_evolution.chunk as an attribute of this package (the
|
|
15
|
+
# shim at dense_evolution/chunk.py is otherwise only reachable via an
|
|
16
|
+
# explicit `import dense_evolution.chunk` / `from dense_evolution.chunk
|
|
17
|
+
# import ...` -- Python only auto-binds a submodule as a package
|
|
18
|
+
# attribute when something actually imports that exact module path, and
|
|
19
|
+
# `from .backends.chunk import Chunk` above binds backends.chunk, not
|
|
20
|
+
# chunk). Real external code (dashboard_core.hamiltonians) does
|
|
21
|
+
# `de.chunk.SafeMemoryGuard()` -- attribute access, not an import -- so
|
|
22
|
+
# this import's only job is that side effect.
|
|
23
|
+
from . import chunk as chunk
|
|
24
|
+
from .config import set_precision
|
|
25
|
+
from .interop import (
|
|
26
|
+
from_qiskit, from_pennylane, run_qiskit_circuit, run_pennylane_circuit,
|
|
27
|
+
noise_model_from_qiskit_backend, to_stim,
|
|
28
|
+
)
|
|
29
|
+
from .solvers.autodiff import circuit_to_energy_fn
|
|
30
|
+
from .backends.mps import MPSSimulator
|
|
31
|
+
from .mitigation.zne import (richardson_extrapolate, richardson_amplification_factor,
|
|
32
|
+
zero_noise_extrapolation, polynomial_extrapolate,
|
|
33
|
+
bounded_exponential_extrapolate,
|
|
34
|
+
project_to_physical, uhlmann_fidelity, zne_density_matrix,
|
|
35
|
+
jsd_predictive_zne_density_matrix,
|
|
36
|
+
coherence_predictive_zne_density_matrix,
|
|
37
|
+
classically_augmented_zne_phaseflip,
|
|
38
|
+
richardson_extrapolate_jit, zero_noise_extrapolation_jit,
|
|
39
|
+
polynomial_extrapolate_jit, uhlmann_fidelity_jit, zne_density_matrix_jit)
|
|
40
|
+
from .circuits.diagram import plot_circuit
|
|
41
|
+
from .circuits.topology import entangling_layer
|
|
42
|
+
from .physics.observables import (pauli_expectation, pauli_sum_expectation, pauli_hamiltonian_to_matrix,
|
|
43
|
+
pauli_sum_matvec, multiply_pauli_terms,
|
|
44
|
+
pauli_sum_matvec_jax, pauli_sum_expectation_jax, PauliSumOperator)
|
|
45
|
+
from .physics.states import ghz_state
|
|
46
|
+
from .utils.measurement import sample_counts, statevector_fidelity
|
|
47
|
+
from .circuits.qft import qft
|
|
48
|
+
from .circuits.random_circuit import random_circuit
|
|
49
|
+
from .utils.drawing import draw_circuit
|
|
50
|
+
from .solvers.harrison_tb import (ELEMENTS as HARRISON_ELEMENTS, ETA as HARRISON_ETA,
|
|
51
|
+
sp3_dimer_hamiltonian, zincblende_hamiltonian)
|
|
52
|
+
from .solvers.vhd_tb import (MATERIALS as VHD_MATERIALS, sp3s_star_hamiltonian,
|
|
53
|
+
direct_gap_at_gamma, band_extrema_along_path)
|
|
54
|
+
from .physics.fermions import majorana_pauli_terms, total_parity_operator, hubbard_hamiltonian_pauli_terms, square_lattice_edges
|
|
55
|
+
from .physics.entropy import partial_trace, von_neumann_entropy, mutual_information, central_charge
|
|
56
|
+
from .circuits.trotter import (pauli_rotation_ops, trotter_evolve_ops, continuous_pulse_evolve,
|
|
57
|
+
continuous_dissipative_evolve)
|
|
58
|
+
from .circuits.uccsd import find_excitations, single_excitation_ops, double_excitation_ops
|
|
59
|
+
from .physics.qec import (pauli_commutes, compute_syndrome, erasure_aware_decode, pymatching_decode,
|
|
60
|
+
blind_minimum_weight_decode, decode_with_erasure_fallback,
|
|
61
|
+
counts_in_intervals_dimension, nearest_coset_decode, erasure_ml_decode,
|
|
62
|
+
peeling_decode, union_find_decode, matching_erasure_decode,
|
|
63
|
+
estimate_edge_probabilities_from_detection_events)
|
|
64
|
+
|
|
65
|
+
__version__ = "8.3.0"
|
|
66
|
+
|
|
67
|
+
__all__ = [
|
|
68
|
+
"__version__",
|
|
69
|
+
# Precision -- process-wide JAX config, set explicitly (see config.py)
|
|
70
|
+
"set_precision",
|
|
71
|
+
# Backends -- the compute engines
|
|
72
|
+
"DenseSVSimulator", "MPSSimulator",
|
|
73
|
+
# Circuits -- representation, parsing, compilation
|
|
74
|
+
"QASMParser", "QASMCircuit", "QuantumTranspiler",
|
|
75
|
+
"NoiseModel", "NoiseSpec", "QuantumHardwareRegistry",
|
|
76
|
+
"GATES", "PARAMETRIC_GATES", "GATE_IDS",
|
|
77
|
+
"entangling_layer", "qft",
|
|
78
|
+
"pauli_rotation_ops", "trotter_evolve_ops", "continuous_pulse_evolve",
|
|
79
|
+
"continuous_dissipative_evolve",
|
|
80
|
+
"find_excitations", "single_excitation_ops", "double_excitation_ops",
|
|
81
|
+
# Chunking / anti-OOM
|
|
82
|
+
"Chunk",
|
|
83
|
+
# Interop -- Qiskit / PennyLane / STIM bridges
|
|
84
|
+
"from_qiskit", "from_pennylane", "run_qiskit_circuit", "run_pennylane_circuit",
|
|
85
|
+
"noise_model_from_qiskit_backend", "to_stim",
|
|
86
|
+
# Solvers -- VQE/autodiff, tight-binding
|
|
87
|
+
"circuit_to_energy_fn",
|
|
88
|
+
"HARRISON_ELEMENTS", "HARRISON_ETA", "sp3_dimer_hamiltonian", "zincblende_hamiltonian",
|
|
89
|
+
"VHD_MATERIALS", "sp3s_star_hamiltonian", "direct_gap_at_gamma", "band_extrema_along_path",
|
|
90
|
+
# Mitigation -- Zero-Noise Extrapolation
|
|
91
|
+
"richardson_extrapolate", "richardson_amplification_factor",
|
|
92
|
+
"zero_noise_extrapolation", "polynomial_extrapolate",
|
|
93
|
+
"bounded_exponential_extrapolate",
|
|
94
|
+
"project_to_physical", "uhlmann_fidelity", "zne_density_matrix",
|
|
95
|
+
"jsd_predictive_zne_density_matrix", "coherence_predictive_zne_density_matrix",
|
|
96
|
+
"classically_augmented_zne_phaseflip",
|
|
97
|
+
"global_depolarizing_channel", "amplitude_damping_channel", "phaseflip_channel_exact",
|
|
98
|
+
"cosmic_ray_burst_profile", "oscillating_p_eff", "pink_noise_p_eff",
|
|
99
|
+
"richardson_extrapolate_jit", "zero_noise_extrapolation_jit",
|
|
100
|
+
"polynomial_extrapolate_jit", "uhlmann_fidelity_jit", "zne_density_matrix_jit",
|
|
101
|
+
# Physics -- states, observables, entropy, fermions, QEC
|
|
102
|
+
"ghz_state",
|
|
103
|
+
"pauli_expectation", "pauli_sum_expectation", "pauli_hamiltonian_to_matrix", "pauli_sum_matvec",
|
|
104
|
+
"multiply_pauli_terms",
|
|
105
|
+
"pauli_sum_matvec_jax", "pauli_sum_expectation_jax", "PauliSumOperator",
|
|
106
|
+
"partial_trace", "von_neumann_entropy", "mutual_information", "central_charge",
|
|
107
|
+
"majorana_pauli_terms", "total_parity_operator", "hubbard_hamiltonian_pauli_terms", "square_lattice_edges",
|
|
108
|
+
"pauli_commutes", "compute_syndrome", "erasure_aware_decode", "pymatching_decode", "blind_minimum_weight_decode",
|
|
109
|
+
"decode_with_erasure_fallback", "counts_in_intervals_dimension", "nearest_coset_decode",
|
|
110
|
+
"erasure_ml_decode", "peeling_decode", "union_find_decode", "matching_erasure_decode",
|
|
111
|
+
"estimate_edge_probabilities_from_detection_events",
|
|
112
|
+
# Utils -- drawing, measurement, random circuits
|
|
113
|
+
"draw_circuit", "plot_circuit", "sample_counts", "statevector_fidelity", "random_circuit",
|
|
114
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Backward-compatibility shim -- the real implementation moved to
|
|
2
|
+
dense_evolution.solvers.autodiff as part of the Phase 2 subpackage split
|
|
3
|
+
(see prog.txt). Kept so `from dense_evolution.autodiff import
|
|
4
|
+
circuit_to_energy_fn` (used by external consumers, e.g.
|
|
5
|
+
Dense-Evolution-Discovery) keeps working unchanged. Import from
|
|
6
|
+
dense_evolution.solvers.autodiff directly in new code.
|
|
7
|
+
"""
|
|
8
|
+
from dense_evolution.solvers.autodiff import circuit_to_energy_fn
|
|
9
|
+
|
|
10
|
+
__all__ = ["circuit_to_energy_fn"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Anti-OOM chunked statevector simulation, split into one file per concern:
|
|
2
|
+
|
|
3
|
+
guard.py SafeMemoryGuard, MemoryPressureError
|
|
4
|
+
geometry.py MemoryChunker, get_dynamic_chunk (pure arithmetic, no allocation)
|
|
5
|
+
kernels.py the JAX multi-chunk / distributed-chunk compiled kernels
|
|
6
|
+
circuit_chunker.py CircuitChunker (single-chunk gate-slicing path)
|
|
7
|
+
core.py Chunk, the public anti-OOM wrapper
|
|
8
|
+
|
|
9
|
+
Re-exported here as a flat namespace identical to the pre-split module: this
|
|
10
|
+
package is imported by path in several places (dense_evolution.chunk's own
|
|
11
|
+
sys.modules self-replacement shim, tools/dashboard/core/system_limits.py) that
|
|
12
|
+
reach for names like `.jax`, `.np`, `.psutil`, and `.HAS_JAX` as module
|
|
13
|
+
attributes, not just the classes -- so `jax`/`np`/`psutil` are imported here
|
|
14
|
+
directly, not just via the submodules that happen to use them.
|
|
15
|
+
"""
|
|
16
|
+
import gc
|
|
17
|
+
import numpy as np
|
|
18
|
+
import jax
|
|
19
|
+
import jax.numpy as jnp
|
|
20
|
+
import psutil
|
|
21
|
+
|
|
22
|
+
from ._engine_imports import DenseSVSimulator, QuantumTranspiler, GATE_IDS
|
|
23
|
+
from .guard import HAS_JAX, MemoryPressureError, SafeMemoryGuard
|
|
24
|
+
from .geometry import MemoryChunker, get_dynamic_chunk
|
|
25
|
+
from .kernels import (
|
|
26
|
+
_build_multi_chunk_step, _build_multi_chunk_runner,
|
|
27
|
+
_build_distributed_chunk_step, _build_distributed_chunk_runner,
|
|
28
|
+
_compile_multi_chunk_ops,
|
|
29
|
+
)
|
|
30
|
+
from .circuit_chunker import CircuitChunker
|
|
31
|
+
from .core import Chunk, chunk1, chunk2, Chunk2Incrociato
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
"Chunk", "MemoryChunker", "CircuitChunker", "SafeMemoryGuard",
|
|
35
|
+
"MemoryPressureError", "get_dynamic_chunk",
|
|
36
|
+
"chunk1", "chunk2", "Chunk2Incrociato",
|
|
37
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
# ── Flexible import with stub fallback ─────────────────────────────────────────
|
|
4
|
+
# Both except-branches below are for deployment layouts other than the
|
|
5
|
+
# installed package this test suite always runs against (a flat/Colab
|
|
6
|
+
# notebook cell with no `dense_evolution.` prefix, or an incomplete
|
|
7
|
+
# install missing simulator/compiler/gates entirely) -- genuinely
|
|
8
|
+
# unreachable here without artificially breaking sys.path, so excluded
|
|
9
|
+
# from coverage rather than chased with an artificial test.
|
|
10
|
+
try:
|
|
11
|
+
from simulator import DenseSVSimulator
|
|
12
|
+
from compiler import QuantumTranspiler # pragma: no cover
|
|
13
|
+
from circuits.compiler import _gate_1q_matrix # pragma: no cover
|
|
14
|
+
from gates import GATE_IDS # pragma: no cover
|
|
15
|
+
except ModuleNotFoundError:
|
|
16
|
+
try:
|
|
17
|
+
from dense_evolution.simulator import DenseSVSimulator
|
|
18
|
+
from dense_evolution.compiler import QuantumTranspiler
|
|
19
|
+
from dense_evolution.circuits.compiler import _gate_1q_matrix
|
|
20
|
+
from dense_evolution.gates import GATE_IDS
|
|
21
|
+
except ModuleNotFoundError: # pragma: no cover
|
|
22
|
+
class DenseSVSimulator: # type: ignore[no-redef]
|
|
23
|
+
def __init__(self, n_qubits, **kwargs):
|
|
24
|
+
self.n = n_qubits
|
|
25
|
+
self.dim = 2 ** n_qubits
|
|
26
|
+
self.dtype = np.complex128
|
|
27
|
+
self.sv = np.zeros(self.dim, dtype=self.dtype)
|
|
28
|
+
self.sv[0] = 1.0
|
|
29
|
+
def run_circuit_jit(self, circuit_slice): pass
|
|
30
|
+
def memory_mb(self) -> float:
|
|
31
|
+
return (self.dim * np.dtype(self.dtype).itemsize) / 1_000_000
|
|
32
|
+
|
|
33
|
+
def _unavailable(self, name):
|
|
34
|
+
raise NotImplementedError(
|
|
35
|
+
f"DenseSVSimulator stub: {name}() is not implemented here -- this "
|
|
36
|
+
"class only exists because the real dense_evolution/JAX modules "
|
|
37
|
+
"were not importable in this deployment (see this module's own "
|
|
38
|
+
"comment above); it is not a working simulator."
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def get_probabilities(self): self._unavailable("get_probabilities")
|
|
42
|
+
def get_statevector(self): self._unavailable("get_statevector")
|
|
43
|
+
def apply_gate_1q(self, gate, q1): self._unavailable("apply_gate_1q")
|
|
44
|
+
def apply_gate_2q(self, gate, q1, q2): self._unavailable("apply_gate_2q")
|
|
45
|
+
|
|
46
|
+
class QuantumTranspiler: # type: ignore[no-redef]
|
|
47
|
+
@staticmethod
|
|
48
|
+
def transpile(circuit): return circuit
|
|
49
|
+
|
|
50
|
+
def _gate_1q_matrix(g_id, param, dtype): # type: ignore[no-redef]
|
|
51
|
+
raise NotImplementedError(
|
|
52
|
+
"_gate_1q_matrix stub: real dense_evolution/JAX not importable in this deployment"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
GATE_IDS: dict = {}
|
|
56
|
+
|
|
57
|
+
__all__ = ["DenseSVSimulator", "QuantumTranspiler", "GATE_IDS", "_gate_1q_matrix"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from typing import List, Optional
|
|
2
|
+
|
|
3
|
+
from ._engine_imports import DenseSVSimulator, QuantumTranspiler
|
|
4
|
+
from .guard import SafeMemoryGuard
|
|
5
|
+
|
|
6
|
+
__all__ = ["CircuitChunker"]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CircuitChunker:
|
|
10
|
+
"""
|
|
11
|
+
Transpile a circuit once, then execute it in fixed-size gate-slices so
|
|
12
|
+
XLA sees the same trace shape on every compilation.
|
|
13
|
+
|
|
14
|
+
A SafeMemoryGuard is checked **before every slice** — if RAM drops below
|
|
15
|
+
15% the current slice is aborted with MemoryPressureError before JAX
|
|
16
|
+
attempts the allocation.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
simulator_instance : DenseSVSimulator
|
|
21
|
+
Physical simulator (sized to safe_qubits, not logical n_qubits).
|
|
22
|
+
memory_threshold : float
|
|
23
|
+
Passed to SafeMemoryGuard. Default 0.15 (15%).
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
simulator_instance: Optional[DenseSVSimulator] = None,
|
|
29
|
+
memory_threshold: float = 0.15,
|
|
30
|
+
):
|
|
31
|
+
self.sim = simulator_instance
|
|
32
|
+
self._guard = SafeMemoryGuard(threshold_pct=memory_threshold)
|
|
33
|
+
|
|
34
|
+
def split_circuit(self, circuit: List, chunk_size: int = 500) -> None:
|
|
35
|
+
"""
|
|
36
|
+
Execute *circuit* in slices of *chunk_size* gates.
|
|
37
|
+
|
|
38
|
+
Raises
|
|
39
|
+
------
|
|
40
|
+
RuntimeError if no simulator instance is attached.
|
|
41
|
+
MemoryPressureError if RAM drops below threshold before a slice.
|
|
42
|
+
"""
|
|
43
|
+
if self.sim is None:
|
|
44
|
+
raise RuntimeError(
|
|
45
|
+
"CircuitChunker: no simulator instance attached. "
|
|
46
|
+
"Pass simulator_instance= at construction or assign .sim."
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
target: List = QuantumTranspiler.transpile(circuit)
|
|
50
|
+
n_slices = (len(target) + chunk_size - 1) // chunk_size
|
|
51
|
+
|
|
52
|
+
for idx, i in enumerate(range(0, len(target), chunk_size)):
|
|
53
|
+
# ── Anti-OOM check before every slice ──────────────────────────────────────────────────────────────
|
|
54
|
+
self._guard.check(f"slice {idx + 1}/{n_slices}")
|
|
55
|
+
self.sim.run_circuit_jit(target[i : i + chunk_size])
|