Some checks failed
WAI conformance / cargo-class corpora · linux (push) Successful in 30s
WAI conformance / cargo-class corpora · linux-arm64 (push) Successful in 42s
WAI conformance / cross-arch byte-equality · linux (push) Successful in 13s
WAI conformance / cross-arch byte-equality · linux-arm64 (push) Successful in 17s
WAI conformance / cargo-class corpora · macos (push) Successful in 1m39s
WAI conformance / cross-arch byte-equality · macos (push) Successful in 18s
WAI conformance / cargo-class corpora · windows (push) Has been cancelled
WAI conformance / cross-arch byte-equality · windows (push) Has been cancelled
Deepens the phasor bridge from a scalar function to the full generative
distribution. A Born machine's amplitudes are complex m·e^{iθ}; the phase θ is the
interference-carrying quantity. So evolve the whole n-qubit state with the phases
held at qFHRR resolution (b-bit, integer-native) and read P(x)=|ψ(x)|² — a TRAINED
Quantum Circuit Born Machine deployed end-to-end on the phasor substrate.
- quantum_qfhrr.rs (feature quantum_qfhrr): the hardware-efficient ansatz run with
per-gate phase quantization; born_probs(bits) + tv_distance + tv_vs_exact. bits=0
reproduces the exact vml Born machine (<1e-12); the full distribution converges to
the exact state vector as phase bits grow (TV → 0), and even a few bits give a
usable generative model. Honest boundary: phases quantized (the qFHRR contract),
magnitudes kept f64 (full-integer would quantize those too).
- wai-web: BornMachine.qfhrr_probs(bits) + qfhrr_tv(bits) run the TRAINED model on
qFHRR; params exposed.
4 tests green: exact mode == vml Born machine, distribution normalized, converges
to exact as bits grow (10-bit essentially exact, 3-bit usable), bit-reproducible.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
61 lines
2.3 KiB
Rust
61 lines
2.3 KiB
Rust
//! Variational quantum ML in the browser (`wai.quantum.vml`) — the interference the
|
|
//! thermodynamic-computing pivot left behind. Train a Quantum Circuit Born Machine
|
|
//! to match a distribution on the classical state vector (exact parameter-shift
|
|
//! gradient), and probe the barren plateau — the honest limit — all on a laptop.
|
|
|
|
use wai::quantum_qfhrr as qf;
|
|
use wai::quantum_vml as vml;
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
#[wasm_bindgen]
|
|
pub struct BornMachine {
|
|
loss: Vec<f64>,
|
|
probs: Vec<f64>,
|
|
kl: f64,
|
|
params: Vec<f64>,
|
|
n: u8,
|
|
layers: u8,
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
impl BornMachine {
|
|
/// Train a Born machine on `target` (a distribution over `2ⁿ` outcomes).
|
|
#[wasm_bindgen(constructor)]
|
|
pub fn new(target: Vec<f64>, n: u8, layers: u8, steps: u32, lr: f64, seed: f64) -> BornMachine {
|
|
let fit = vml::train_born(&target, n, layers, steps, lr, seed as u64);
|
|
BornMachine { loss: fit.loss_curve, probs: fit.final_probs, kl: fit.final_kl, params: fit.params, n, layers }
|
|
}
|
|
/// The KL-loss curve over training.
|
|
pub fn loss_curve(&self) -> Vec<f64> {
|
|
self.loss.clone()
|
|
}
|
|
/// The learned model distribution `P_θ(x)`.
|
|
pub fn model_probs(&self) -> Vec<f64> {
|
|
self.probs.clone()
|
|
}
|
|
pub fn final_kl(&self) -> f64 {
|
|
self.kl
|
|
}
|
|
/// Run the TRAINED generative model on the qFHRR phasor substrate at `bits`-bit
|
|
/// phase resolution — its full distribution, deployed on the phasor fabric.
|
|
pub fn qfhrr_probs(&self, bits: u32) -> Vec<f64> {
|
|
qf::born_probs(self.n, self.layers, &self.params, bits)
|
|
}
|
|
/// Total-variation distance of the `bits`-bit qFHRR run from the exact model.
|
|
pub fn qfhrr_tv(&self, bits: u32) -> f64 {
|
|
qf::tv_vs_exact(self.n, self.layers, &self.params, bits)
|
|
}
|
|
}
|
|
|
|
/// The parity (interference) target on `n` qubits: uniform over even-parity strings,
|
|
/// zero on odd — matchable only by amplitudes that destructively cancel.
|
|
#[wasm_bindgen]
|
|
pub fn vml_parity_target(n: u8) -> Vec<f64> {
|
|
vml::parity_target(n)
|
|
}
|
|
|
|
/// The barren-plateau signature: variance of a cost gradient at `(n, layers)`.
|
|
#[wasm_bindgen]
|
|
pub fn vml_barren_variance(n: u8, layers: u8, samples: u32, seed: f64) -> f64 {
|
|
vml::barren_plateau_variance(n, layers, samples, seed as u64)
|
|
}
|