wai-quantum 0.6.0

A deterministic quantum stack in pure Rust: byte-exact circuit simulation (statevector / stabilizer / tensor-network MPS / sparse-Pauli backends), sparse Pauli dynamics at utility scale (arbitrary angles, 1024 qubits), belief-propagation tensor networks on the hardware graph, error mitigation, qLDPC decoding, noise learning, circuit-equivalence proofs, a phasor interference-ML layer, information-theoretic limits, noisy channels and state tomography, and signed energy-accounted receipts. No QPU, no cloud, no system libraries in the default features — identical results native, in the browser, and as a WASI component at the edge; the opt-in WebGPU member reaches the platform's GPU interface.
Documentation
// wai-quantum fabric: the gate's rows on one compute core of a neural
// processor's tile array, compiled for the core by the array's open compiler.
//
// A transcription of `lanes::exact_row` in 64-bit integers: each
// fx(e, a) = (e·a + RND) >> SH is an exact 64-bit product of two 32-bit
// values (at most 2^62 in size), an add and an arithmetic shift, and each row
// is the sum of four such terms (at most 2^34 in size). The core writes the
// four rows whole; the host checks each row's range and keeps its low 32
// bits, as `lanes::apply_words` does. Nothing here is floating point or
// depends on the order anything runs in.
//
// RND, SH and LAST_ADD (whether row 0's last real term is added instead of
// subtracted, a mutant) are given by the build, so each variant of the kernel
// is its own compiled program.
//
// One line: a 16-word header (word 0 the mode, words 8..15 the gate's
// entries m0..m7), then `n` cases of four words. Mode 0: each case is a pair's
// columns (re a0, im a0, re a1, im a1), and its output the four rows
// (0r, 0i, 1r, 1i). Mode 1, the arithmetic probe: each case is (a, b, 0, 0),
// and its output a·b and fx(b, a), then two zeros. Every output value is 64
// bits, written as two words, the low one first.
#include <stdint.h>

#if !defined(RND) || !defined(SH) || !defined(LAST_ADD)
#error "RND, SH and LAST_ADD are given by the build"
#endif

static inline int64_t fx(int32_t e, int32_t a) {
  return ((int64_t)e * (int64_t)a + (int64_t)RND) >> SH;
}

static inline void put(int32_t *o, int64_t v) {
  uint64_t u = (uint64_t)v;
  o[0] = (int32_t)(uint32_t)u;
  o[1] = (int32_t)(uint32_t)(u >> 32);
}

extern "C" void wq_line(const int32_t *in, int32_t *out, int32_t n) {
  const int32_t mode = in[0];
  const int32_t *m = in + 8;
  const int32_t *p = in + 16;
  if (mode == 1) {
    for (int32_t k = 0; k < n; k++) {
      const int32_t a = p[4 * k], b = p[4 * k + 1];
      put(out + 8 * k + 0, (int64_t)a * (int64_t)b);
      put(out + 8 * k + 2, fx(b, a));
      put(out + 8 * k + 4, 0);
      put(out + 8 * k + 6, 0);
    }
    return;
  }
  const int32_t m0 = m[0], m1 = m[1], m2 = m[2], m3 = m[3], m4 = m[4], m5 = m[5], m6 = m[6], m7 = m[7];
  for (int32_t k = 0; k < n; k++) {
    const int32_t a0r = p[4 * k], a0i = p[4 * k + 1], a1r = p[4 * k + 2], a1i = p[4 * k + 3];
    int64_t r0r = fx(m0, a0r) - fx(m1, a0i) + fx(m2, a1r);
    r0r = LAST_ADD ? r0r + fx(m3, a1i) : r0r - fx(m3, a1i);
    const int64_t r0i = fx(m0, a0i) + fx(m1, a0r) + fx(m2, a1i) + fx(m3, a1r);
    const int64_t r1r = fx(m4, a0r) - fx(m5, a0i) + fx(m6, a1r) - fx(m7, a1i);
    const int64_t r1i = fx(m4, a0i) + fx(m5, a0r) + fx(m6, a1i) + fx(m7, a1r);
    put(out + 8 * k + 0, r0r);
    put(out + 8 * k + 2, r0i);
    put(out + 8 * k + 4, r1r);
    put(out + 8 * k + 6, r1i);
  }
}