- The C settlement kernel graded every receipt measured, from hardware, by
hardware_meter, whatever its meter; it now writes the grade and device the
meter states. Its host harness's figures are constants: projected, from a
simulation, by model_estimated (oer-receipts §2: an Estimator figure is
projected). The Zephyr skeleton states projected and no longer seals a
compute figure of 0. firmware_vectors.json is regenerated; both verifiers
pass it.
- wai-web: the world demo seals the page's estimate labelled Estimator and says
so on screen (label_page_figure, tested); the quantum demos seal the unmetered
marker instead of invented constants, and their getters say a 0 is unmetered.
- The quantum studio shows a figure with its class, coverage and uncertainty;
the quantum CLI prints the unmetered marker as unmetered (tested); the
metering tools head a bracket as a bracket and print the marker on stdout when
they seal it; a provenance total names the class it reads at (tested).
- energy-measurement §2.8 and §6 record which demos still seal an illustrative
figure the page passes in.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2a8d45aa0d)
128 lines
4.2 KiB
Rust
128 lines
4.2 KiB
Rust
//! Neutral-atom rearrangement in the browser (`wai.quantum.rearrange`). The SAME
|
||
//! deterministic Hungarian / LSAP solver a native sink runs, compiled to wasm32:
|
||
//! load a stochastic ~half-full trap array, assign every defect-free target site a
|
||
//! distinct atom at minimum total move distance, seal the signed plan — and watch
|
||
//! the same check reject a tampered plan.
|
||
|
||
use ed25519_dalek::SigningKey;
|
||
use wai::quantum_atom::{rearrange_and_seal, solve, target_block, verify, Array, Plan};
|
||
use wai::quantum_ops::{GrantRef, RearrangeReceipt};
|
||
use wasm_bindgen::prelude::*;
|
||
|
||
fn signer() -> SigningKey {
|
||
SigningKey::from_bytes(&[0x51; 32])
|
||
}
|
||
fn hex(b: &[u8]) -> String {
|
||
b.iter().map(|x| format!("{x:02x}")).collect()
|
||
}
|
||
|
||
#[wasm_bindgen]
|
||
pub struct RearrangeDemo {
|
||
w: u32,
|
||
h: u32,
|
||
array: Array,
|
||
target: Vec<usize>,
|
||
plan: Plan,
|
||
success: bool,
|
||
tamper_success: bool,
|
||
receipt: RearrangeReceipt,
|
||
}
|
||
|
||
#[wasm_bindgen]
|
||
impl RearrangeDemo {
|
||
/// Load a `w × h` array at `fill_permille`/1000 occupancy and rearrange into a
|
||
/// centered `tw × th` defect-free target register.
|
||
#[wasm_bindgen(constructor)]
|
||
pub fn new(w: u32, h: u32, fill_permille: u32, tw: u32, th: u32, seed: f64) -> RearrangeDemo {
|
||
let array = Array::load(w, h, fill_permille, seed as u64);
|
||
let target = target_block(w, h, tw, th);
|
||
let (plan, success, receipt) = rearrange_and_seal(
|
||
&signer(), "did:key:demo-lab", &array, &target, crate::UNMETERED,
|
||
GrantRef::unbounded("quantum.rearrange"),
|
||
);
|
||
// tamper: drop the first real move → its target goes unfilled
|
||
let mut tampered = plan.clone();
|
||
if !tampered.moves.is_empty() {
|
||
tampered.moves.remove(0);
|
||
}
|
||
let tamper_success = verify(&array, &target, &tampered);
|
||
RearrangeDemo { w, h, array, target, plan, success, tamper_success, receipt }
|
||
}
|
||
|
||
pub fn w(&self) -> u32 {
|
||
self.w
|
||
}
|
||
pub fn h(&self) -> u32 {
|
||
self.h
|
||
}
|
||
pub fn atoms_loaded(&self) -> u32 {
|
||
self.array.count()
|
||
}
|
||
pub fn sites(&self) -> u32 {
|
||
self.w * self.h
|
||
}
|
||
pub fn target_size(&self) -> u32 {
|
||
self.target.len() as u32
|
||
}
|
||
pub fn feasible(&self) -> bool {
|
||
self.plan.feasible
|
||
}
|
||
pub fn success(&self) -> bool {
|
||
self.success
|
||
}
|
||
pub fn tamper_success(&self) -> bool {
|
||
self.tamper_success
|
||
}
|
||
pub fn atoms_moved(&self) -> u32 {
|
||
self.plan.atoms_moved
|
||
}
|
||
pub fn total_distance(&self) -> u32 {
|
||
self.plan.total_distance as u32
|
||
}
|
||
/// Indices of initially-occupied sites.
|
||
pub fn occupied_initial(&self) -> Vec<u32> {
|
||
self.array.atoms().into_iter().map(|i| i as u32).collect()
|
||
}
|
||
/// Target site indices.
|
||
pub fn target_sites(&self) -> Vec<u32> {
|
||
self.target.iter().map(|&i| i as u32).collect()
|
||
}
|
||
/// Moves flattened `[from0,to0,from1,to1,…]`.
|
||
pub fn moves_flat(&self) -> Vec<u32> {
|
||
let mut v = Vec::with_capacity(self.plan.moves.len() * 2);
|
||
for &(f, t) in &self.plan.moves {
|
||
v.push(f as u32);
|
||
v.push(t as u32);
|
||
}
|
||
v
|
||
}
|
||
/// Target sites already occupied in the raw load (the stochastic yield).
|
||
pub fn target_fill_before(&self) -> u32 {
|
||
self.target.iter().filter(|&&t| self.array.occ[t]).count() as u32
|
||
}
|
||
/// Target sites occupied after the plan (defect-free ⇒ = target_size).
|
||
pub fn target_fill_after(&self) -> u32 {
|
||
if self.success {
|
||
self.target.len() as u32
|
||
} else {
|
||
self.target_fill_before()
|
||
}
|
||
}
|
||
pub fn initial_hash_hex(&self) -> String {
|
||
hex(&wai::quantum_ops::content_hash(&self.array.bytes()))
|
||
}
|
||
pub fn plan_hash_hex(&self) -> String {
|
||
hex(&self.plan.plan_hash())
|
||
}
|
||
pub fn receipt_verifies(&self) -> bool {
|
||
self.receipt.verify()
|
||
}
|
||
pub fn receipt_json(&self) -> String {
|
||
self.receipt.to_json()
|
||
}
|
||
/// Discard the demo's solve and re-solve (identical) — exposes the pure solver
|
||
/// for a benchmark button if needed.
|
||
pub fn resolve_distance(&self) -> u32 {
|
||
solve(&self.array, &self.target).total_distance as u32
|
||
}
|
||
}
|