coheroncompute 1.0.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 (CETQAC) The Centre of Excellence for Technology Quantum and AI Canada
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.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: coheroncompute
3
+ Version: 1.0.0
4
+ Summary: Coheron Computing: a computational framework built on coherence rephasing in inhomogeneous media
5
+ Author-email: CETQAC <info@coheroncomputing.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://www.coheroncomputing.com
8
+ Project-URL: Documentation, https://www.coheroncomputing.com
9
+ Project-URL: Source, https://www.coheroncomputing.com
10
+ Keywords: coheron computing,photon echo,phonon echo,analog computing,reservoir computing,fourier transform,matched filter,quantum,physics
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Scientific/Engineering :: Physics
16
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: numpy>=1.20
21
+ Provides-Extra: viz
22
+ Requires-Dist: matplotlib>=3.3; extra == "viz"
23
+ Dynamic: license-file
24
+
25
+ # Coheron Computing
26
+
27
+ ### A Computational Framework Built on Coherence Rephasing in Inhomogeneous Media
28
+
29
+ [![PyPI](https://img.shields.io/badge/pip-coheroncompute-blue)]()
30
+ [![Python](https://img.shields.io/badge/python-3.8%2B-blue)]()
31
+ [![License](https://img.shields.io/badge/license-MIT-green)]()
32
+
33
+ **`coheroncompute`** is the reference Python stack for **Coheron Computing** — a
34
+ programmable computational paradigm whose physical substrate is the spontaneous
35
+ rephasing of coherence in an inhomogeneously broadened ensemble of two-level systems
36
+ (a real, replicated physical effect first measured in 1976). It is to Coheron
37
+ Computing what Qiskit is to quantum computing: a simulator core, a gate library, a
38
+ circuit model, an algorithm library, a backend interface, and a benchmarking suite —
39
+ everything needed to write, run, and verify Coheron programs on a laptop today, and on
40
+ real hardware when it exists.
41
+
42
+ ## The three pillars of Coheron
43
+
44
+ Coheron is built in three layers, each named under one brand:
45
+
46
+ - **Coheron Physics** — the foundational description. The coherence-rephasing effect
47
+ in an inhomogeneously broadened ensemble of two-level systems, the physical
48
+ phenomenon first measured in 1976, and the substrates that host it (rare-earth
49
+ crystals, spins).
50
+ - **Coheron Mechanics** — the mathematical formalism. The state `ψ(Δ) ∈ ℂ^N` over `N`
51
+ *coherons* (the fundamental unit), the generating gate set `{ E(t), Π, R }`, the
52
+ readout `M`, the **Coheron Transform Theorem**, and the complexity classes
53
+ (`CoheronP`, `CoheronBQP`).
54
+ - **Coheron Computing** — the computational process. Circuits, algorithms, backends,
55
+ and benchmarks. This package, `coheroncompute`, implements this layer.
56
+
57
+ > Coheron Computing does **not** claim to exceed quantum computing in complexity
58
+ > class. In the linear regime its native problems lie in classical **P**; its
59
+ > advantage there is constant-time transforms, analog precision, and built-in
60
+ > cancellation of static disorder. The nonlinear (reservoir) regime is a universal
61
+ > approximator of temporal maps whose exact complexity is an open problem. This
62
+ > library is honest about that boundary everywhere.
63
+
64
+ ---
65
+
66
+ ## Install
67
+
68
+ ```bash
69
+ pip install coheroncompute
70
+ # optional pulse-schedule plots:
71
+ pip install coheroncompute[viz]
72
+ ```
73
+
74
+ Requires only NumPy (matplotlib optional for visualization).
75
+
76
+ ## 60-second quickstart
77
+
78
+ ```python
79
+ import numpy as np
80
+ from coheroncompute import CoheronCircuit, coheron_fft, coheron_correlate
81
+
82
+ # 1) Native Fourier transform — the readout *is* the transform
83
+ x = np.random.randn(1024) + 1j*np.random.randn(1024)
84
+ spectrum = coheron_fft(x) # == np.fft.fft(x, norm="ortho")
85
+
86
+ # 2) Build a two-pulse rephasing circuit by hand
87
+ c = CoheronCircuit(N=1024, bandwidth=1e9, T2=1e-3, snr_db=30)
88
+ c.write(x).evolve(50e-6).conjugate().evolve(50e-6)
89
+ result = c.read()
90
+ print(result.fidelity, result.peak())
91
+
92
+ # 3) RESONANCE matched filter — locate a template in a signal in one coheron cycle
93
+ template = np.random.randn(64) + 1j*np.random.randn(64)
94
+ signal = np.zeros(2048, complex); signal[900:964] = template
95
+ y = coheron_correlate(signal, template, N=2048)
96
+ print("template found at index", int(np.argmax(np.abs(y))))
97
+ ```
98
+
99
+ ## The state model (Coheron Mechanics)
100
+
101
+ Coheron Computing has two regimes, so the simulator has two state representations:
102
+
103
+ - **Level A — coherence-vector model (linear regime).** The state is `psi ∈ ℂ^N`, one
104
+ complex amplitude per *coheron* (spectral cell). Exact, fast, FFT-based; the working
105
+ model for all transform-class programs. Classically simulable, consistent with
106
+ `CoheronP ⊆ P`.
107
+ - **Level B — Bloch-ensemble model (nonlinear regime).** Per-cell two-level states,
108
+ required for saturation, higher-order rephasing terms, and the reservoir regime.
109
+
110
+ The detuning grid spans the band `B = [−W/2, W/2]` with `N = W/δ` resolvable cells,
111
+ where `W` is the inhomogeneous bandwidth and `δ` the homogeneous linewidth.
112
+
113
+ ## The gate set
114
+
115
+ Everything derives from the generating set `{ E(t), Π, R }` plus the readout `M`.
116
+
117
+ | Gate | API | Action on state | Class |
118
+ |------|-----|-----------------|-------|
119
+ | INIT | `.reset()` | `ψ ← 0` | preparation |
120
+ | WRITE | `.write(a)` | `ψ ← a` | preparation (π/2 pulse) |
121
+ | E(τ) | `.evolve(tau)` | `ψ_k ↦ ψ_k e^{iΔ_k τ}` | diagonal unitary |
122
+ | Π | `.conjugate(phase)` | `ψ_k ↦ e^{iϕ} ψ*_k` | **antiunitary** |
123
+ | R | `.rotate(k, θ, ϕ)` | SU(2) rotation on coheron k | unitary |
124
+ | P | `.phase_mask(φ⃗)` | `ψ_k ↦ e^{iφ_k} ψ_k` | diagonal unitary |
125
+ | A | `.amp_mask(m⃗)` | `ψ_k ↦ m_k ψ_k` | attenuating |
126
+ | M | `.read()` | `s = F(g·ψ)` | measurement (Fourier) |
127
+ | REFOCUS | `.refocus(tau)` | `E(τ/2)·Π·E(τ/2)` | control |
128
+ | CPMG | `.cpmg(t, n)` | n-pulse decoupling train | control |
129
+
130
+ `Π` and time-reversal apply **complex conjugation**, not a matrix product — they are
131
+ antilinear. The readout `M` applies an N-point Fourier transform *for free* (it is the
132
+ measurement boundary, not a synthesized circuit).
133
+
134
+ ## The algorithm library (Coheron Computing)
135
+
136
+ The "hello-world" programs of Coheron Computing:
137
+
138
+ ```python
139
+ from coheroncompute import (coheron_fft, coheron_convolve, coheron_correlate,
140
+ coheron_time_reverse, coheron_reservoir, train_reservoir)
141
+
142
+ coheron_fft(signal) # native Fourier transform (one coheron cycle)
143
+ coheron_convolve(signal, kernel) # circular convolution (two-pulse rephasing)
144
+ coheron_correlate(signal, template) # matched filter / RESONANCE (three-pulse rephasing)
145
+ coheron_time_reverse(signal) # time-reversal / phase conjugation (Π in time)
146
+ W = train_reservoir(signals, labels) # train a nonlinear-regime classifier
147
+ coheron_reservoir(signal, W) # run it
148
+ ```
149
+
150
+ ## Backends — write once, run anywhere
151
+
152
+ The circuit is independent of where it runs, exactly as in Qiskit:
153
+
154
+ ```python
155
+ circuit.run(backend="simulator") # classical simulation (default, available now)
156
+ circuit.run(backend="hardware") # AWG + heterodyne detector (Stage-1 roadmap)
157
+ ```
158
+
159
+ The hardware contract is fixed now so nothing changes when a device is connected:
160
+ compile `circuit.schedule` into an AWG pulse program, fire it at a cryogenic
161
+ rare-earth substrate (e.g. Eu³⁺:Y₂SiO₅), and return the heterodyne-detected rephased
162
+ signal as a `CoheronResult`.
163
+
164
+ ## Benchmarks — verify the simulator matches theory
165
+
166
+ ```python
167
+ from coheroncompute import benchmarks
168
+ benchmarks.run_all()
169
+ ```
170
+
171
+ - **FFT fidelity** — the readout reproduces the exact DFT.
172
+ - **Static cancellation** — the framework's falsifiable prediction, made runnable:
173
+ under increasing static detuning disorder, the refocused fidelity stays flat
174
+ (static disorder cancels exactly at `t = 2τ`), while a no-refocus control collapses.
175
+ - **Coherence decay** — recover `T₂` from the rephasing amplitude vs. delay.
176
+ - **RESONANCE throughput** — matched-filter correlations per second.
177
+
178
+ A correct implementation keeps the static-cancellation fidelity at ≈1.0 across all
179
+ disorder levels — the signature property that distinguishes Coheron Computing from a
180
+ naive "rephasing as lossy memory" picture.
181
+
182
+ ## What is honest scope, and what is not claimed
183
+
184
+ - The **mathematics** (the Coheron Transform Theorem) is unconditional given the
185
+ Maxwell–Bloch equations.
186
+ - The **linear regime** is provably in **P**; the advantage is physical-time and
187
+ energy, not a complexity-class separation.
188
+ - The **nonlinear regime's** computational power is an **open problem**; this library
189
+ implements it but attaches no complexity claim to it.
190
+ - The **hardware backend** is not yet available — it is Stage 1 of the experimental
191
+ roadmap. The simulator is exact and runs today.
192
+
193
+ ## Citation
194
+
195
+ ```
196
+ Coheron Computing: A Computational Framework Built on Coherence
197
+ Rephasing in Inhomogeneous Media. Founding Document v1.0, 2026. Software:
198
+ coheroncompute v1.0.
199
+ ```
200
+
201
+ ## License
202
+
203
+ MIT. © CETQAC. See `LICENSE`.
204
+
205
+ ---
206
+
207
+ *Coheron — a phenomenon made formal (Coheron Physics), a mathematics made precise
208
+ (Coheron Mechanics), and a machine made programmable (Coheron Computing).*
@@ -0,0 +1,184 @@
1
+ # Coheron Computing
2
+
3
+ ### A Computational Framework Built on Coherence Rephasing in Inhomogeneous Media
4
+
5
+ [![PyPI](https://img.shields.io/badge/pip-coheroncompute-blue)]()
6
+ [![Python](https://img.shields.io/badge/python-3.8%2B-blue)]()
7
+ [![License](https://img.shields.io/badge/license-MIT-green)]()
8
+
9
+ **`coheroncompute`** is the reference Python stack for **Coheron Computing** — a
10
+ programmable computational paradigm whose physical substrate is the spontaneous
11
+ rephasing of coherence in an inhomogeneously broadened ensemble of two-level systems
12
+ (a real, replicated physical effect first measured in 1976). It is to Coheron
13
+ Computing what Qiskit is to quantum computing: a simulator core, a gate library, a
14
+ circuit model, an algorithm library, a backend interface, and a benchmarking suite —
15
+ everything needed to write, run, and verify Coheron programs on a laptop today, and on
16
+ real hardware when it exists.
17
+
18
+ ## The three pillars of Coheron
19
+
20
+ Coheron is built in three layers, each named under one brand:
21
+
22
+ - **Coheron Physics** — the foundational description. The coherence-rephasing effect
23
+ in an inhomogeneously broadened ensemble of two-level systems, the physical
24
+ phenomenon first measured in 1976, and the substrates that host it (rare-earth
25
+ crystals, spins).
26
+ - **Coheron Mechanics** — the mathematical formalism. The state `ψ(Δ) ∈ ℂ^N` over `N`
27
+ *coherons* (the fundamental unit), the generating gate set `{ E(t), Π, R }`, the
28
+ readout `M`, the **Coheron Transform Theorem**, and the complexity classes
29
+ (`CoheronP`, `CoheronBQP`).
30
+ - **Coheron Computing** — the computational process. Circuits, algorithms, backends,
31
+ and benchmarks. This package, `coheroncompute`, implements this layer.
32
+
33
+ > Coheron Computing does **not** claim to exceed quantum computing in complexity
34
+ > class. In the linear regime its native problems lie in classical **P**; its
35
+ > advantage there is constant-time transforms, analog precision, and built-in
36
+ > cancellation of static disorder. The nonlinear (reservoir) regime is a universal
37
+ > approximator of temporal maps whose exact complexity is an open problem. This
38
+ > library is honest about that boundary everywhere.
39
+
40
+ ---
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install coheroncompute
46
+ # optional pulse-schedule plots:
47
+ pip install coheroncompute[viz]
48
+ ```
49
+
50
+ Requires only NumPy (matplotlib optional for visualization).
51
+
52
+ ## 60-second quickstart
53
+
54
+ ```python
55
+ import numpy as np
56
+ from coheroncompute import CoheronCircuit, coheron_fft, coheron_correlate
57
+
58
+ # 1) Native Fourier transform — the readout *is* the transform
59
+ x = np.random.randn(1024) + 1j*np.random.randn(1024)
60
+ spectrum = coheron_fft(x) # == np.fft.fft(x, norm="ortho")
61
+
62
+ # 2) Build a two-pulse rephasing circuit by hand
63
+ c = CoheronCircuit(N=1024, bandwidth=1e9, T2=1e-3, snr_db=30)
64
+ c.write(x).evolve(50e-6).conjugate().evolve(50e-6)
65
+ result = c.read()
66
+ print(result.fidelity, result.peak())
67
+
68
+ # 3) RESONANCE matched filter — locate a template in a signal in one coheron cycle
69
+ template = np.random.randn(64) + 1j*np.random.randn(64)
70
+ signal = np.zeros(2048, complex); signal[900:964] = template
71
+ y = coheron_correlate(signal, template, N=2048)
72
+ print("template found at index", int(np.argmax(np.abs(y))))
73
+ ```
74
+
75
+ ## The state model (Coheron Mechanics)
76
+
77
+ Coheron Computing has two regimes, so the simulator has two state representations:
78
+
79
+ - **Level A — coherence-vector model (linear regime).** The state is `psi ∈ ℂ^N`, one
80
+ complex amplitude per *coheron* (spectral cell). Exact, fast, FFT-based; the working
81
+ model for all transform-class programs. Classically simulable, consistent with
82
+ `CoheronP ⊆ P`.
83
+ - **Level B — Bloch-ensemble model (nonlinear regime).** Per-cell two-level states,
84
+ required for saturation, higher-order rephasing terms, and the reservoir regime.
85
+
86
+ The detuning grid spans the band `B = [−W/2, W/2]` with `N = W/δ` resolvable cells,
87
+ where `W` is the inhomogeneous bandwidth and `δ` the homogeneous linewidth.
88
+
89
+ ## The gate set
90
+
91
+ Everything derives from the generating set `{ E(t), Π, R }` plus the readout `M`.
92
+
93
+ | Gate | API | Action on state | Class |
94
+ |------|-----|-----------------|-------|
95
+ | INIT | `.reset()` | `ψ ← 0` | preparation |
96
+ | WRITE | `.write(a)` | `ψ ← a` | preparation (π/2 pulse) |
97
+ | E(τ) | `.evolve(tau)` | `ψ_k ↦ ψ_k e^{iΔ_k τ}` | diagonal unitary |
98
+ | Π | `.conjugate(phase)` | `ψ_k ↦ e^{iϕ} ψ*_k` | **antiunitary** |
99
+ | R | `.rotate(k, θ, ϕ)` | SU(2) rotation on coheron k | unitary |
100
+ | P | `.phase_mask(φ⃗)` | `ψ_k ↦ e^{iφ_k} ψ_k` | diagonal unitary |
101
+ | A | `.amp_mask(m⃗)` | `ψ_k ↦ m_k ψ_k` | attenuating |
102
+ | M | `.read()` | `s = F(g·ψ)` | measurement (Fourier) |
103
+ | REFOCUS | `.refocus(tau)` | `E(τ/2)·Π·E(τ/2)` | control |
104
+ | CPMG | `.cpmg(t, n)` | n-pulse decoupling train | control |
105
+
106
+ `Π` and time-reversal apply **complex conjugation**, not a matrix product — they are
107
+ antilinear. The readout `M` applies an N-point Fourier transform *for free* (it is the
108
+ measurement boundary, not a synthesized circuit).
109
+
110
+ ## The algorithm library (Coheron Computing)
111
+
112
+ The "hello-world" programs of Coheron Computing:
113
+
114
+ ```python
115
+ from coheroncompute import (coheron_fft, coheron_convolve, coheron_correlate,
116
+ coheron_time_reverse, coheron_reservoir, train_reservoir)
117
+
118
+ coheron_fft(signal) # native Fourier transform (one coheron cycle)
119
+ coheron_convolve(signal, kernel) # circular convolution (two-pulse rephasing)
120
+ coheron_correlate(signal, template) # matched filter / RESONANCE (three-pulse rephasing)
121
+ coheron_time_reverse(signal) # time-reversal / phase conjugation (Π in time)
122
+ W = train_reservoir(signals, labels) # train a nonlinear-regime classifier
123
+ coheron_reservoir(signal, W) # run it
124
+ ```
125
+
126
+ ## Backends — write once, run anywhere
127
+
128
+ The circuit is independent of where it runs, exactly as in Qiskit:
129
+
130
+ ```python
131
+ circuit.run(backend="simulator") # classical simulation (default, available now)
132
+ circuit.run(backend="hardware") # AWG + heterodyne detector (Stage-1 roadmap)
133
+ ```
134
+
135
+ The hardware contract is fixed now so nothing changes when a device is connected:
136
+ compile `circuit.schedule` into an AWG pulse program, fire it at a cryogenic
137
+ rare-earth substrate (e.g. Eu³⁺:Y₂SiO₅), and return the heterodyne-detected rephased
138
+ signal as a `CoheronResult`.
139
+
140
+ ## Benchmarks — verify the simulator matches theory
141
+
142
+ ```python
143
+ from coheroncompute import benchmarks
144
+ benchmarks.run_all()
145
+ ```
146
+
147
+ - **FFT fidelity** — the readout reproduces the exact DFT.
148
+ - **Static cancellation** — the framework's falsifiable prediction, made runnable:
149
+ under increasing static detuning disorder, the refocused fidelity stays flat
150
+ (static disorder cancels exactly at `t = 2τ`), while a no-refocus control collapses.
151
+ - **Coherence decay** — recover `T₂` from the rephasing amplitude vs. delay.
152
+ - **RESONANCE throughput** — matched-filter correlations per second.
153
+
154
+ A correct implementation keeps the static-cancellation fidelity at ≈1.0 across all
155
+ disorder levels — the signature property that distinguishes Coheron Computing from a
156
+ naive "rephasing as lossy memory" picture.
157
+
158
+ ## What is honest scope, and what is not claimed
159
+
160
+ - The **mathematics** (the Coheron Transform Theorem) is unconditional given the
161
+ Maxwell–Bloch equations.
162
+ - The **linear regime** is provably in **P**; the advantage is physical-time and
163
+ energy, not a complexity-class separation.
164
+ - The **nonlinear regime's** computational power is an **open problem**; this library
165
+ implements it but attaches no complexity claim to it.
166
+ - The **hardware backend** is not yet available — it is Stage 1 of the experimental
167
+ roadmap. The simulator is exact and runs today.
168
+
169
+ ## Citation
170
+
171
+ ```
172
+ Coheron Computing: A Computational Framework Built on Coherence
173
+ Rephasing in Inhomogeneous Media. Founding Document v1.0, 2026. Software:
174
+ coheroncompute v1.0.
175
+ ```
176
+
177
+ ## License
178
+
179
+ MIT. © CETQAC. See `LICENSE`.
180
+
181
+ ---
182
+
183
+ *Coheron — a phenomenon made formal (Coheron Physics), a mathematics made precise
184
+ (Coheron Mechanics), and a machine made programmable (Coheron Computing).*
@@ -0,0 +1,45 @@
1
+ """
2
+ Coheron Computing
3
+ ==============
4
+ A Computational Framework Built on Coherence Rephasing in Inhomogeneous Media.
5
+
6
+ The reference simulator, gate library, circuit model, algorithm library,
7
+ backend interface, and benchmark suite for Coheron Computing.
8
+
9
+ Quickstart
10
+ ----------
11
+ import numpy as np
12
+ from coheroncompute import CoheronCircuit, coheron_fft
13
+
14
+ x = np.random.randn(1024) + 1j*np.random.randn(1024)
15
+ spectrum = coheron_fft(x) # native Fourier transform
16
+
17
+ c = CoheronCircuit(N=1024, bandwidth=1e9, T2=1e-3)
18
+ c.write(x).evolve(50e-6).conjugate().evolve(50e-6)
19
+ result = c.read()
20
+ print(result.fidelity, result.peak())
21
+ """
22
+ from .core import (detuning_grid, spectral_profile, readout, overlap_fidelity,
23
+ g_evolve, g_conjugate, g_rotate, g_phase_mask, g_amp_mask,
24
+ g_saturate, fit_signal)
25
+ from .circuit import CoheronCircuit, CoheronResult
26
+ from .algorithms import (coheron_fft, coheron_convolve, coheron_correlate,
27
+ coheron_time_reverse, coheron_reservoir,
28
+ reservoir_states, train_reservoir)
29
+ from .backends import (Backend, SimulatorBackend, HardwareBackend,
30
+ get_backend, list_backends)
31
+ from . import benchmarks
32
+
33
+ __version__ = "1.0.0"
34
+ __author__ = "(CETQAC)"
35
+
36
+ __all__ = [
37
+ "CoheronCircuit", "CoheronResult",
38
+ "coheron_fft", "coheron_convolve", "coheron_correlate", "coheron_time_reverse",
39
+ "coheron_reservoir", "reservoir_states", "train_reservoir",
40
+ "Backend", "SimulatorBackend", "HardwareBackend", "get_backend", "list_backends",
41
+ "detuning_grid", "spectral_profile", "readout", "overlap_fidelity",
42
+ "g_evolve", "g_conjugate", "g_rotate", "g_phase_mask", "g_amp_mask",
43
+ "g_saturate", "fit_signal", "benchmarks",
44
+ "__version__",
45
+ ]
@@ -0,0 +1,107 @@
1
+ """
2
+ coheroncompute.algorithms
3
+ =======================
4
+ The standard Coheron Computing algorithms -- the "hello-world" programs every new
5
+ user runs first. Each maps to an Coheron-Transform primitive (Founding Document
6
+ sec. 3.4) or the nonlinear reservoir (sec. 3.5).
7
+
8
+ coheron_fft native Fourier transform (one coheron cycle)
9
+ coheron_convolve circular convolution (two-pulse rephasing)
10
+ coheron_correlate cross-correlation / matched filter (RESONANCE, three-pulse rephasing)
11
+ coheron_time_reverse time-reversal / phase conjugation (Pi in the time domain)
12
+ coheron_reservoir nonlinear-regime temporal feature map + linear readout
13
+ """
14
+ from __future__ import annotations
15
+ import numpy as np
16
+ from .circuit import CoheronCircuit
17
+ from . import core
18
+
19
+
20
+ def coheron_fft(signal, N: int | None = None, bandwidth: float = 1e9,
21
+ T2: float = 1e-3, snr_db: float | None = None, seed: int | None = None):
22
+ """Native Fourier transform. The readout M *is* the transform.
23
+
24
+ With snr_db=None the result equals np.fft.fft(signal, norm='ortho').
25
+ """
26
+ x = np.asarray(signal).ravel()
27
+ N = int(N or x.size)
28
+ c = CoheronCircuit(N, bandwidth=bandwidth, T2=T2, snr_db=snr_db, seed=seed)
29
+ c.write(x)
30
+ return c.read().spectrum
31
+
32
+
33
+ def coheron_convolve(signal, kernel, N: int | None = None):
34
+ """Circular convolution (two-pulse rephasing)."""
35
+ x = core.fit_signal(signal, N or max(len(signal), len(kernel)))
36
+ h = core.fit_signal(kernel, x.size)
37
+ return np.fft.ifft(np.fft.fft(x) * np.fft.fft(h))
38
+
39
+
40
+ def coheron_correlate(signal, template, N: int | None = None, normalize: bool = False):
41
+ """Cross-correlation / matched filter -- the RESONANCE algorithm.
42
+
43
+ Returns y[n] = sum_m signal[m] conj(template[m-n]) (circular).
44
+ The detection peak index locates the template within the signal.
45
+ """
46
+ x = core.fit_signal(signal, N or max(len(signal), len(template)))
47
+ h = core.fit_signal(template, x.size)
48
+ y = np.fft.ifft(np.fft.fft(x) * np.conj(np.fft.fft(h)))
49
+ if normalize:
50
+ denom = (np.linalg.norm(x) * np.linalg.norm(h)) + 1e-30
51
+ y = y / denom
52
+ return y
53
+
54
+
55
+ def coheron_time_reverse(signal, N: int | None = None):
56
+ """Time-reversal / phase conjugate: x[n] -> conj(x[(-n) mod N])."""
57
+ x = core.fit_signal(signal, N or len(signal))
58
+ return np.conj(np.roll(x[::-1], 1))
59
+
60
+
61
+ # ---------------------------------------------------------------- reservoir
62
+ def reservoir_states(signal, N: int = 256, bandwidth: float = 1e9, tau: float = 1e-6,
63
+ leak: float = 0.3, sat_s: float = 5.0, n_features: int = 64,
64
+ seed: int = 0):
65
+ """Drive the medium into the nonlinear regime and collect feature vectors.
66
+
67
+ Returns an array of shape (len(signal), n_features) of real features
68
+ (the magnitude spectrum of the reservoir state, downsampled).
69
+ """
70
+ rng = np.random.default_rng(seed)
71
+ detuning = core.detuning_grid(N, bandwidth)
72
+ win = (rng.standard_normal(N) + 1j * rng.standard_normal(N)) / np.sqrt(N)
73
+ psi = np.zeros(N, dtype=np.complex128)
74
+ feats = []
75
+ sig = np.asarray(signal).ravel()
76
+ sel = np.linspace(0, N - 1, n_features).astype(int)
77
+ for xt in sig:
78
+ drive = win * xt
79
+ psi = (1.0 - leak) * core.g_evolve(psi, detuning, tau) + drive
80
+ psi = core.g_saturate(psi, sat_s) # nonlinearity
81
+ spec = np.abs(np.fft.fft(psi, norm="ortho"))
82
+ feats.append(spec[sel])
83
+ return np.asarray(feats)
84
+
85
+
86
+ def train_reservoir(signals, labels, ridge: float = 1e-3, **kw):
87
+ """Train a linear readout (ridge regression) on reservoir features.
88
+
89
+ signals: list of 1-D arrays. labels: 1-D or 2-D targets per signal.
90
+ Returns readout_weights usable by coheron_reservoir().
91
+ """
92
+ X = np.stack([reservoir_states(s, **kw).mean(axis=0) for s in signals])
93
+ X = np.hstack([X, np.ones((X.shape[0], 1))]) # bias term
94
+ Y = np.asarray(labels, dtype=float)
95
+ if Y.ndim == 1:
96
+ Y = Y[:, None]
97
+ A = X.T @ X + ridge * np.eye(X.shape[1])
98
+ W = np.linalg.solve(A, X.T @ Y)
99
+ return W
100
+
101
+
102
+ def coheron_reservoir(signal, readout_weights, **kw):
103
+ """Nonlinear-regime classifier/predictor: features @ trained weights."""
104
+ f = reservoir_states(signal, **kw).mean(axis=0)
105
+ f = np.concatenate([f, [1.0]]) # bias term
106
+ out = f @ readout_weights
107
+ return out.ravel()
@@ -0,0 +1,61 @@
1
+ """
2
+ coheroncompute.backends
3
+ =====================
4
+ Backend abstraction, mirroring Qiskit's circuit/backend split. The same
5
+ CoheronCircuit runs on the simulator today and on Coheron hardware when it exists
6
+ (Founding Document sec. 11.2, Stage 1).
7
+
8
+ circuit.run(backend="simulator") # classical simulation (default)
9
+ circuit.run(backend="hardware") # AWG + heterodyne detector (not yet available)
10
+ """
11
+ from __future__ import annotations
12
+
13
+
14
+ class Backend:
15
+ name = "abstract"
16
+
17
+ def run(self, circuit):
18
+ raise NotImplementedError
19
+
20
+
21
+ class SimulatorBackend(Backend):
22
+ """Runs the pulse schedule on CPU/GPU via NumPy."""
23
+ name = "simulator"
24
+
25
+ def run(self, circuit):
26
+ return circuit.read()
27
+
28
+
29
+ class HardwareBackend(Backend):
30
+ """Interface to a physical Coheron Computer.
31
+
32
+ The software contract is fixed now so nothing changes when hardware
33
+ arrives: compile circuit.schedule into an AWG pulse program, fire it at
34
+ the cryogenic rare-earth substrate, and return the heterodyne-detected
35
+ rephased signal as a CoheronResult. Until a device is connected this raises.
36
+ """
37
+ name = "hardware"
38
+
39
+ def __init__(self, address: str | None = None):
40
+ self.address = address
41
+
42
+ def run(self, circuit):
43
+ raise NotImplementedError(
44
+ "Hardware backend not available yet. This is Stage 1 of the "
45
+ "experimental roadmap: connect an arbitrary-waveform generator and "
46
+ "heterodyne detector here. The circuit API will not change."
47
+ )
48
+
49
+
50
+ _BACKENDS = {"simulator": SimulatorBackend, "hardware": HardwareBackend}
51
+
52
+
53
+ def get_backend(name: str = "simulator", **kw) -> Backend:
54
+ key = name.lower()
55
+ if key not in _BACKENDS:
56
+ raise ValueError(f"unknown backend {name!r}; choices: {list(_BACKENDS)}")
57
+ return _BACKENDS[key](**kw) if key == "hardware" else _BACKENDS[key]()
58
+
59
+
60
+ def list_backends():
61
+ return list(_BACKENDS)