moonlab 1.2.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.
Binary file
moonlab/__init__.py ADDED
@@ -0,0 +1,358 @@
1
+ """
2
+ Moonlab Quantum Computing Framework
3
+ ====================================
4
+
5
+ Python bindings for the Moonlab quantum simulator.
6
+
7
+ Features:
8
+ - 32-qubit quantum state simulation
9
+ - Complete universal gate set
10
+ - VQE for molecular simulation
11
+ - QAOA for combinatorial optimization
12
+ - Bell inequality violation on explicit Bell states
13
+ (CHSH ~ 2.87 measured; 2.828 is the Tsirelson bound)
14
+ - Native reverse-mode autograd (moonlab.diff) for parameterized
15
+ circuits -- adjoint gradients without PyTorch
16
+ - SIMD-dispatched C core with an optional Metal GPU backend on
17
+ Apple Silicon (see docs/benchmarks/reproducible-benchmarks.md)
18
+
19
+ Quick Start:
20
+ >>> from moonlab import QuantumState
21
+ >>> state = QuantumState(num_qubits=2)
22
+ >>> state.h(0) # Hadamard on qubit 0
23
+ >>> state.cnot(0, 1) # Entangle qubits
24
+ >>> result = state.measure(0) # Measure qubit 0
25
+ """
26
+
27
+ __version__ = "1.2.0"
28
+ __author__ = "tsotchke"
29
+
30
+ from .core import (
31
+ QuantumState,
32
+ Gates,
33
+ Measurement,
34
+ QuantumError
35
+ )
36
+
37
+ # Algorithm wrappers. These historically failed to load because of an
38
+ # ABI mismatch; the mismatch was resolved in the 0.2 sweep but we keep
39
+ # the import guard so a partial / stripped build of libquantumsim does
40
+ # not crash the module at import. The intended state is
41
+ # _ALGO_AVAILABLE == True on a full build.
42
+ try:
43
+ from .algorithms import (
44
+ VQE,
45
+ QAOA,
46
+ Grover,
47
+ BellTest,
48
+ )
49
+ _ALGO_AVAILABLE = True
50
+ except (ImportError, AttributeError, OSError):
51
+ _ALGO_AVAILABLE = False
52
+
53
+ # Everything below is optional in exactly the same sense as the guarded
54
+ # blocks further down this file: a stripped / size-trimmed libquantumsim
55
+ # build (e.g. WASM) can be missing any of these entry points, and that
56
+ # must not crash `import moonlab` itself. OSError is included alongside
57
+ # ImportError/AttributeError because a missing symbol surfaces as an
58
+ # OSError from ctypes' CDLL.__getattr__, not an ImportError.
59
+ try:
60
+ from .benchmarks import quantum_volume, QuantumVolumeResult
61
+ _BENCHMARKS_AVAILABLE = True
62
+ except (ImportError, AttributeError, OSError):
63
+ _BENCHMARKS_AVAILABLE = False
64
+
65
+ try:
66
+ from .clifford import Clifford
67
+ _CLIFFORD_AVAILABLE = True
68
+ except (ImportError, AttributeError, OSError):
69
+ _CLIFFORD_AVAILABLE = False
70
+
71
+ try:
72
+ from .topology import (
73
+ ChernKPM, qwz_chern, berry_grid_qwz,
74
+ berry_grid_haldane, ssh_winding,
75
+ # v0.3 additions
76
+ chern_qwz_proj, chern_qwz_parallel_transport,
77
+ kane_mele_z2, bhz_z2, kitaev_chain_z2, hofstadter_chern,
78
+ # v0.3.2 curvature-grid variants
79
+ berry_grid_qwz_proj, berry_grid_qwz_pt,
80
+ )
81
+ _TOPOLOGY_AVAILABLE = True
82
+ except (ImportError, AttributeError, OSError):
83
+ _TOPOLOGY_AVAILABLE = False
84
+
85
+ try:
86
+ from .diff import DiffCircuit, PauliTerm, OBS_Z, OBS_X, OBS_Y
87
+ _DIFF_AVAILABLE = True
88
+ except (ImportError, AttributeError, OSError):
89
+ _DIFF_AVAILABLE = False
90
+
91
+ try:
92
+ from . import crypto
93
+ _CRYPTO_AVAILABLE = True
94
+ except (ImportError, AttributeError, OSError):
95
+ _CRYPTO_AVAILABLE = False
96
+
97
+ # Matrix-product density operator noise simulator (since v0.3.0).
98
+ # Optional import: a stripped libquantumsim build without these
99
+ # entry points is still a usable Moonlab.
100
+ try:
101
+ from .mpdo import Mpdo
102
+ _MPDO_AVAILABLE = True
103
+ except (ImportError, AttributeError, OSError):
104
+ _MPDO_AVAILABLE = False
105
+
106
+ # Adaptive-bond time-dependent variational principle (since v0.4).
107
+ # Same optional-import policy as MPDO.
108
+ try:
109
+ from . import tdvp as _tdvp_module
110
+ tdvp = _tdvp_module
111
+ _TDVP_AVAILABLE = True
112
+ except (ImportError, AttributeError, OSError):
113
+ _TDVP_AVAILABLE = False
114
+
115
+ # Single-qubit gate-fusion DAG (since v0.4.4).
116
+ try:
117
+ from .fusion import FusedCircuit, FuseStats
118
+ _FUSION_AVAILABLE = True
119
+ except (ImportError, AttributeError, OSError):
120
+ _FUSION_AVAILABLE = False
121
+
122
+ # Clifford-Assisted MPS + var-D + gauge-aware warmstart + Z2 LGT.
123
+ # Optional import: a stripped libquantumsim build without these
124
+ # entry points (e.g. WASM size-trimmed) should still import the
125
+ # top-level moonlab module.
126
+ try:
127
+ from .ca_mps import (
128
+ CAMPS,
129
+ WARMSTART_IDENTITY,
130
+ WARMSTART_H_ALL,
131
+ WARMSTART_DUAL_TFIM,
132
+ WARMSTART_FERRO_TFIM,
133
+ WARMSTART_STABILIZER_SUBGROUP,
134
+ var_d_run,
135
+ gauge_warmstart,
136
+ z2_lgt_1d_build,
137
+ z2_lgt_1d_gauss_law,
138
+ status_string,
139
+ )
140
+ _CAMPS_AVAILABLE = True
141
+ except (ImportError, AttributeError, OSError):
142
+ _CAMPS_AVAILABLE = False
143
+
144
+ # Error mitigation: zero-noise extrapolation, probabilistic error
145
+ # cancellation, and readout-error mitigation. ZNE/PEC bind the stable
146
+ # zne.h surface; MeasurementMitigation is post-processing over the
147
+ # measurement engine, so it imports as long as core does.
148
+ try:
149
+ from .error_mitigation import (
150
+ ZNE,
151
+ PEC,
152
+ MeasurementMitigation,
153
+ ZNE_LINEAR,
154
+ ZNE_RICHARDSON,
155
+ ZNE_EXPONENTIAL,
156
+ )
157
+ _ERROR_MITIGATION_AVAILABLE = True
158
+ except (ImportError, AttributeError, OSError):
159
+ _ERROR_MITIGATION_AVAILABLE = False
160
+
161
+ # Noise: Kraus-channel trajectory unravellings (depolarizing, amplitude/phase
162
+ # damping, bit/phase flip, thermal relaxation, readout error, composite device
163
+ # model) over the real src/quantum/noise.c engine.
164
+ try:
165
+ from .noise import (
166
+ DepolarizingChannel,
167
+ AmplitudeDamping,
168
+ PhaseDamping,
169
+ BitFlip,
170
+ PhaseFlip,
171
+ BitPhaseFlip,
172
+ ThermalRelaxation,
173
+ ReadoutError,
174
+ DeviceNoiseModel,
175
+ )
176
+ _NOISE_AVAILABLE = True
177
+ except (ImportError, AttributeError, OSError):
178
+ _NOISE_AVAILABLE = False
179
+
180
+ # Distributed simulation: bounded MPI + CUDA state-vector sharding over the
181
+ # real dist_*/collective_*/mpi_bridge_* engine. Imports on any build; the MPI
182
+ # entry points raise an informative error when the library lacks MPI.
183
+ try:
184
+ from .distributed import (
185
+ DistributedContext,
186
+ DistributedState,
187
+ MpiUnavailableError,
188
+ init_mpi,
189
+ finalize_mpi,
190
+ is_mpi_available,
191
+ )
192
+ _DISTRIBUTED_AVAILABLE = True
193
+ except (ImportError, AttributeError, OSError):
194
+ _DISTRIBUTED_AVAILABLE = False
195
+
196
+ # Chemistry: first-principles STO-3G molecular Hamiltonians (H2, LiH) over
197
+ # the real vqe_create_*_hamiltonian / h2_sto3g_pauli_coeffs C surface.
198
+ try:
199
+ from .chemistry import (
200
+ Molecule,
201
+ Hamiltonian,
202
+ h2_sto3g_pauli_coeffs,
203
+ hartree_to_kcalmol,
204
+ H2_PAULI_LABELS,
205
+ CHEMICAL_ACCURACY_HARTREE,
206
+ )
207
+ _CHEMISTRY_AVAILABLE = True
208
+ except (ImportError, AttributeError, OSError):
209
+ _CHEMISTRY_AVAILABLE = False
210
+
211
+ try:
212
+ from .ca_peps import CAPEPS
213
+ _CAPEPS_AVAILABLE = True
214
+ except (ImportError, AttributeError, OSError):
215
+ _CAPEPS_AVAILABLE = False
216
+
217
+ try:
218
+ from .surface_code import SurfaceCode
219
+ _SURFACE_CODE_AVAILABLE = True
220
+ except (ImportError, AttributeError, OSError):
221
+ _SURFACE_CODE_AVAILABLE = False
222
+
223
+ try:
224
+ from .libirrep_qec import (
225
+ LibirrepQecCode,
226
+ LibirrepError,
227
+ LibirrepNotBuiltError,
228
+ is_available as libirrep_is_available,
229
+ )
230
+ _LIBIRREP_QEC_AVAILABLE = True
231
+ except (ImportError, AttributeError, OSError):
232
+ _LIBIRREP_QEC_AVAILABLE = False
233
+
234
+ try:
235
+ from .qgtl import QgtlCircuit, QgtlResults, QgtlError, GateType as QgtlGateType
236
+ _QGTL_AVAILABLE = True
237
+ except (ImportError, AttributeError, OSError):
238
+ _QGTL_AVAILABLE = False
239
+
240
+ try:
241
+ from .scheduler import Job, JobResults, SchedulerError
242
+ _SCHEDULER_AVAILABLE = True
243
+ except (ImportError, AttributeError, OSError):
244
+ _SCHEDULER_AVAILABLE = False
245
+
246
+ try:
247
+ from .decoder import (
248
+ DecoderSlot, DecoderError, DecoderNotBuiltError,
249
+ decode as decoder_decode,
250
+ slot_available as decoder_slot_available,
251
+ slot_name as decoder_slot_name,
252
+ )
253
+ _DECODER_AVAILABLE = True
254
+ except (ImportError, AttributeError, OSError):
255
+ _DECODER_AVAILABLE = False
256
+
257
+ # Base __all__: names from .core, imported unconditionally above (if
258
+ # these fail to import, the whole package fails to import, so they are
259
+ # always present). Everything else is appended below, gated on the same
260
+ # availability flag that gated its import, so __all__ never advertises a
261
+ # name that isn't actually bound on this build.
262
+ __all__ = [
263
+ 'QuantumState',
264
+ 'Gates',
265
+ 'Measurement',
266
+ 'QuantumError',
267
+ ]
268
+ if _ALGO_AVAILABLE:
269
+ __all__ += ['VQE', 'QAOA', 'Grover', 'BellTest']
270
+ if _BENCHMARKS_AVAILABLE:
271
+ __all__ += ['quantum_volume', 'QuantumVolumeResult']
272
+ if _CLIFFORD_AVAILABLE:
273
+ __all__ += ['Clifford']
274
+ if _TOPOLOGY_AVAILABLE:
275
+ __all__ += [
276
+ 'ChernKPM',
277
+ 'qwz_chern',
278
+ 'berry_grid_qwz',
279
+ 'berry_grid_haldane',
280
+ 'ssh_winding',
281
+ 'chern_qwz_proj',
282
+ 'chern_qwz_parallel_transport',
283
+ 'kane_mele_z2',
284
+ 'bhz_z2',
285
+ 'kitaev_chain_z2',
286
+ 'hofstadter_chern',
287
+ 'berry_grid_qwz_proj',
288
+ 'berry_grid_qwz_pt',
289
+ ]
290
+ if _DIFF_AVAILABLE:
291
+ __all__ += ['DiffCircuit', 'PauliTerm', 'OBS_Z', 'OBS_X', 'OBS_Y']
292
+ if _CRYPTO_AVAILABLE:
293
+ __all__ += ['crypto']
294
+ if _MPDO_AVAILABLE:
295
+ __all__ += ['Mpdo']
296
+ if _TDVP_AVAILABLE:
297
+ __all__ += ['tdvp']
298
+ if _FUSION_AVAILABLE:
299
+ __all__ += ['FusedCircuit', 'FuseStats']
300
+ if _CAMPS_AVAILABLE:
301
+ __all__ += [
302
+ 'CAMPS',
303
+ 'WARMSTART_IDENTITY',
304
+ 'WARMSTART_H_ALL',
305
+ 'WARMSTART_DUAL_TFIM',
306
+ 'WARMSTART_FERRO_TFIM',
307
+ 'WARMSTART_STABILIZER_SUBGROUP',
308
+ 'var_d_run',
309
+ 'gauge_warmstart',
310
+ 'z2_lgt_1d_build',
311
+ 'z2_lgt_1d_gauss_law',
312
+ 'status_string',
313
+ ]
314
+ if _ERROR_MITIGATION_AVAILABLE:
315
+ __all__ += [
316
+ 'ZNE', 'PEC', 'MeasurementMitigation',
317
+ 'ZNE_LINEAR', 'ZNE_RICHARDSON', 'ZNE_EXPONENTIAL',
318
+ ]
319
+ if _NOISE_AVAILABLE:
320
+ __all__ += [
321
+ 'DepolarizingChannel', 'AmplitudeDamping', 'PhaseDamping',
322
+ 'BitFlip', 'PhaseFlip', 'BitPhaseFlip', 'ThermalRelaxation',
323
+ 'ReadoutError', 'DeviceNoiseModel',
324
+ ]
325
+ if _DISTRIBUTED_AVAILABLE:
326
+ __all__ += [
327
+ 'DistributedContext', 'DistributedState', 'MpiUnavailableError',
328
+ 'init_mpi', 'finalize_mpi', 'is_mpi_available',
329
+ ]
330
+ if _CHEMISTRY_AVAILABLE:
331
+ __all__ += [
332
+ 'Molecule', 'Hamiltonian', 'h2_sto3g_pauli_coeffs',
333
+ 'hartree_to_kcalmol', 'H2_PAULI_LABELS', 'CHEMICAL_ACCURACY_HARTREE',
334
+ ]
335
+ if _CAPEPS_AVAILABLE:
336
+ __all__ += ['CAPEPS']
337
+ if _SURFACE_CODE_AVAILABLE:
338
+ __all__ += ['SurfaceCode']
339
+ if _LIBIRREP_QEC_AVAILABLE:
340
+ __all__ += [
341
+ 'LibirrepQecCode',
342
+ 'LibirrepError',
343
+ 'LibirrepNotBuiltError',
344
+ 'libirrep_is_available',
345
+ ]
346
+ if _QGTL_AVAILABLE:
347
+ __all__ += ['QgtlCircuit', 'QgtlResults', 'QgtlError', 'QgtlGateType']
348
+ if _SCHEDULER_AVAILABLE:
349
+ __all__ += ['Job', 'JobResults', 'SchedulerError']
350
+ if _DECODER_AVAILABLE:
351
+ __all__ += [
352
+ 'DecoderSlot',
353
+ 'DecoderError',
354
+ 'DecoderNotBuiltError',
355
+ 'decoder_decode',
356
+ 'decoder_slot_available',
357
+ 'decoder_slot_name',
358
+ ]