Some checks failed
wai cross-architecture byte-equality / windows-x86_64 (push) Successful in 24s
wai cross-architecture byte-equality / linux-aarch64 (push) Successful in 51s
joule-code conformance gate / Build + round-trip C1-C4 vectors (push) Failing after 1m5s
WAI conformance / cargo-class corpora · windows (push) Successful in 1m29s
jouleclaw public surface must stay documented / Public-surface audit (jouleclaw-rs) (push) Successful in 58s
WAI conformance / cargo-class corpora · linux-arm64 (push) Successful in 1m15s
wai cross-architecture byte-equality / macos-arm64 (reference) (push) Has been cancelled
wai cross-architecture byte-equality / linux-x86_64 (push) Has been cancelled
WAI conformance / cargo-class corpora · linux (push) Has been cancelled
WAI conformance / cargo-class corpora · macos (push) Has been cancelled
WAI conformance / cross-arch byte-equality · linux (push) Has been cancelled
WAI conformance / cross-arch byte-equality · windows (push) Has been cancelled
WAI conformance / cross-arch byte-equality · linux-arm64 (push) Has been cancelled
WAI conformance / cross-arch byte-equality · macos (push) Has been cancelled
The frequency-domain matched pair that extends the calibration suite to correlated / 1-f dephasing, in pure fixed-point (byte-exact), each sealing a wai.quantum.calibration receipt. Both run entirely offline against a model. - quantum_control.rs: the filter-function overlap χ = (1/π)∫S(ω)F(ω)/ω²; DD sequences (free/Hahn/CPMG/UDD) + their filter kernels; noise spectroscopy that reconstructs a hidden PSD from a CPMG filter bank via Richardson–Lucy deconvolution; filter-function robust control that reshapes a DD sequence to minimize the overlap against a PSD (coordinate descent). Reuses the calibration floor's sin/cos/exp; adds a fixed-point ln. - wai-web: SpectroDemo / RobustFFDemo wasm bindings. The robust receipt binds the PSD hash it was hardened against, so "robust vs that spectrum" is checkable, not asserted. Honest boundary: first-order dephasing model on a simulated device. Tests green (incl. echo<free<CPMG-8, spectroscopy recovery, robust beats CPMG). Co-Authored-By: Claude Opus 4.8 <[email protected]>
145 lines
4.9 KiB
Rust
145 lines
4.9 KiB
Rust
//! Filter-function control + noise spectroscopy in the browser (`wai.quantum.cal.*`,
|
|
//! frequency domain). The SAME deterministic fixed-point DSP a native sink runs,
|
|
//! compiled to wasm32: reconstruct a *hidden* noise PSD from a dynamical-decoupling
|
|
//! filter bank, and reshape a DD sequence so its filter's stopband sits over the
|
|
//! noise — byte-exact, each sealing a `wai.quantum.calibration` receipt. The
|
|
//! matched pair that extends the calibration suite to correlated / 1-f noise.
|
|
|
|
use ed25519_dalek::SigningKey;
|
|
use wai::quantum_control::{
|
|
dd_cpmg, optimize_dd, psd_model, reconstruct_psd, NoiseGrid, RobustResult, SpectroResult,
|
|
};
|
|
use wai::quantum_ops::GrantRef;
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
const ONE: f64 = (1u64 << 20) as f64;
|
|
fn f(v: i64) -> f64 {
|
|
v as f64 / ONE
|
|
}
|
|
fn signer() -> SigningKey {
|
|
SigningKey::from_bytes(&[0x51; 32])
|
|
}
|
|
fn grant() -> GrantRef {
|
|
GrantRef::unbounded("quantum.calibrate")
|
|
}
|
|
fn base_grid() -> NoiseGrid {
|
|
NoiseGrid::linear(0.5, 90.0, 180)
|
|
}
|
|
|
|
// ===========================================================================
|
|
// 1. Noise spectroscopy — recover a hidden PSD from a DD filter bank
|
|
// ===========================================================================
|
|
|
|
#[wasm_bindgen]
|
|
pub struct SpectroDemo {
|
|
g: NoiseGrid,
|
|
res: SpectroResult,
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
impl SpectroDemo {
|
|
/// Reconstruct a hidden `1/f + Lorentzian-bump` PSD from a bank of CPMG
|
|
/// filters, each a narrow-band probe. `seed` varies the sampling noise.
|
|
#[wasm_bindgen(constructor)]
|
|
pub fn new(seed: f64) -> SpectroDemo {
|
|
let g = base_grid();
|
|
let psd = psd_model(&g, 0.02, 0.6, 25.0, 5.0);
|
|
let res = reconstruct_psd(&g, &psd, 20, 40_000, 40, seed as u64);
|
|
SpectroDemo { g, res }
|
|
}
|
|
pub fn omega(&self) -> Vec<f64> {
|
|
self.g.omega.iter().map(|&w| f(w)).collect()
|
|
}
|
|
pub fn psd_true(&self) -> Vec<f64> {
|
|
self.res.psd_true.iter().map(|&v| f(v)).collect()
|
|
}
|
|
pub fn psd_est(&self) -> Vec<f64> {
|
|
self.res.psd_est.iter().map(|&v| f(v)).collect()
|
|
}
|
|
pub fn n_sequences(&self) -> u32 {
|
|
self.res.n_sequences as u32
|
|
}
|
|
pub fn error(&self) -> f64 {
|
|
f(self.res.error_fx)
|
|
}
|
|
pub fn mean_psd(&self) -> f64 {
|
|
f(self.res.psd_true.iter().sum::<i64>() / self.res.psd_true.len().max(1) as i64)
|
|
}
|
|
pub fn receipt_json(&self) -> String {
|
|
self.res.seal(&signer(), "did:key:demo-lab", 1_000_000, grant()).to_json()
|
|
}
|
|
pub fn receipt_verifies(&self) -> bool {
|
|
self.res.seal(&signer(), "did:key:demo-lab", 1_000_000, grant()).verify()
|
|
}
|
|
}
|
|
|
|
// ===========================================================================
|
|
// 2. Filter-function robust control — reshape a DD sequence to dodge the PSD
|
|
// ===========================================================================
|
|
|
|
#[wasm_bindgen]
|
|
pub struct RobustFFDemo {
|
|
g: NoiseGrid,
|
|
psd: Vec<i64>,
|
|
res: RobustResult,
|
|
n: u32,
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
impl RobustFFDemo {
|
|
/// Reshape an `n`-pulse DD sequence to minimise the filter overlap against a
|
|
/// `1/f + bump` PSD whose bump sits right under equal-spaced CPMG's passband.
|
|
#[wasm_bindgen(constructor)]
|
|
pub fn new(n: u32, seed: f64) -> RobustFFDemo {
|
|
let g = base_grid();
|
|
// bump location jittered by seed so "new spectrum" reshapes differently
|
|
let w0 = 22.0 + (seed as u64 % 12) as f64;
|
|
let psd = psd_model(&g, 0.02, 0.6, w0, 5.0);
|
|
let res = optimize_dd(&g, &psd, n as usize, 40);
|
|
RobustFFDemo { g, psd, res, n }
|
|
}
|
|
pub fn omega(&self) -> Vec<f64> {
|
|
self.g.omega.iter().map(|&w| f(w)).collect()
|
|
}
|
|
pub fn psd(&self) -> Vec<f64> {
|
|
self.psd.iter().map(|&v| f(v)).collect()
|
|
}
|
|
pub fn kern_cpmg(&self) -> Vec<f64> {
|
|
self.res.kern_cpmg.iter().map(|&v| f(v)).collect()
|
|
}
|
|
pub fn kern_opt(&self) -> Vec<f64> {
|
|
self.res.kern_opt.iter().map(|&v| f(v)).collect()
|
|
}
|
|
pub fn chi_cpmg(&self) -> f64 {
|
|
f(self.res.chi_cpmg)
|
|
}
|
|
pub fn chi_opt(&self) -> f64 {
|
|
f(self.res.chi_opt)
|
|
}
|
|
pub fn coh_cpmg(&self) -> f64 {
|
|
f(self.res.coh_cpmg)
|
|
}
|
|
pub fn coh_opt(&self) -> f64 {
|
|
f(self.res.coh_opt)
|
|
}
|
|
pub fn improvement(&self) -> f64 {
|
|
f(self.res.improvement_fx())
|
|
}
|
|
pub fn n_pulses(&self) -> u32 {
|
|
self.n
|
|
}
|
|
/// Equal-spaced CPMG pulse positions (in [0,1]).
|
|
pub fn pulses_cpmg(&self) -> Vec<f64> {
|
|
dd_cpmg(self.n as usize).iter().map(|&p| f(p)).collect()
|
|
}
|
|
/// The optimised (reshaped) pulse positions.
|
|
pub fn pulses_opt(&self) -> Vec<f64> {
|
|
self.res.pulses.iter().map(|&p| f(p)).collect()
|
|
}
|
|
pub fn receipt_json(&self) -> String {
|
|
self.res.seal(&signer(), "did:key:demo-lab", 1_000_000, grant()).to_json()
|
|
}
|
|
pub fn receipt_verifies(&self) -> bool {
|
|
self.res.seal(&signer(), "did:key:demo-lab", 1_000_000, grant()).verify()
|
|
}
|
|
}
|