open-standards/wai/extensions/ternary-tt.md
Transaction Science 2baae4269b wai: the reference meters seal what their reader is — ModelBased from a reported power, never OnChipCounter
The meters sampled the processor power a non-privileged reader reports and
sealed it OnChipCounter, but they never read the channel it comes from: on
macOS 27 the processor channels of IOReport's Energy Model group read zero for
an unprivileged reader, and the reader takes its power from another report it
selects. The liveness rule (energy-measurement §3.1) passed on the reported
samples, which move, while no counter was ever put to it.

energy_burst::PowerSource says what a reader's samples are. A Counter's
differences can seal OnChipCounter under §3.1, §4 and §2.3; a Reported power
is refused as OnChipCounter whatever its brackets show (Bracket::on_chip_figure,
on_chip_refusal) and seals ModelBased under the same bracket rules
(Bracket::figure). wai_meter, wai_video_meter, wai_world_meter,
wai_quantum_meter, wai_prov and wai_stage_measure --energy macmon now seal
ModelBased, naming the reader as the method; rapl:<domain> stays a counter.

energy-measurement §3.1 (the test is run on the counter), §2.9 and §7 say so,
and the extensions that described the meters' figures as on-chip readings are
corrected. No committed record changes class: the provenance vector's figures
are unlabelled and keep their bytes.

Also: the relay's powercap tests module after its impl, and platform-decode's
test helper uses is_multiple_of.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 507f4cd9e1)
2026-10-26 08:31:35 -04:00

141 lines
7.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# WAI Extension: Balanced-Ternary MPS Transform (`wai.ternary.tt`)
Status: **Draft / reference prototype.** Engine: `wai-rs/src/ternary.rs`
(feature `ternary`), receipt `wai-rs/src/ternary_receipt.rs` (feature
`ternary_receipt`). A **quantum-inspired** (tensor-network), classical,
deterministic transform.
## 0. What this is — and what it is not (read first)
`wai.ternary.tt` is a **provenance** capability; rate reduction is not its purpose.
It exists to demonstrate, and make usable, one property: a quantum-inspired
ternary/tensor-network transform whose reconstruction is **byte-exact, portable,
and receiptable**.
It is **not** a good general media codec, and this document says so up front with
numbers (§5). If you need compression ratio, use the zeroth menu (JPEG-XL, AVIF,
Opus). Reach for `wai.ternary.tt` only when *determinism and provenance of the
reconstruction outrank the ratio* — an auditable, energy-accounted transform for
high-throughput edge streams where "what exactly did the sink reconstruct, and
what did it cost?" must be answerable and signable.
## 1. Lineage (ported, not invented)
The two ingredients are established, working techniques — this extension does not
reinvent them:
- **Balanced-ternary weights** ({−1,0,+1}, BitNet-b1.58 style; five trits per
byte, `3^5 = 243 < 256`, the 1.58-bit regime).
- **Matrix-product-state (MPS / tensor-train) compression** — a signal reshaped
into a chain of small cores with bounded bond dimension.
Both already live as real code in the wider portfolio (ternary fabrics, MPS/MPO
indices). Every such implementation shares one property that makes it **not**
WAI-conformant: a **float scale** (`α·(trit·x)`, `α : f32`). A float scale
desyncs across machines exactly as a float σ desyncs a learned entropy coder.
**The one change that is the whole contribution:** the scale is an **integer**
(per output column: a shared exponent + a `u16` mantissa, dequantized by a pure
integer shift). So the entire *decode* path is `i64`/`i128` with no float, and a
reconstruction is byte-identical on every machine. Encoder-side float (the SVD,
the optimal per-column scale) runs once at encode and never at decode — the same
posture as `wai.neural.int_hyper`, whose float model is quantised once, after
training, and never runs in float at decode.
## 2. Container (`WQTT`)
```
"WQTT" | u8 version | u32 n_signal | u8 n_layers | layer*
layer := u8 n_sites | u8 n_cores | core*
core := u16 left | u16 phys | u16 right | u8 scale_exp
| scale_mant[right] (u16 each) | packed_trits(left*phys*right)
```
Little-endian; trits base-3-packed (five per byte). The container is
self-describing and bounds-checked on parse (`from_wqtt`). This byte string is
the canonical payload a receipt's identity hashes.
## 3. Transform
A left-canonical MPS per layer: sites `0..n-1` are orthonormal isometries (the
`U` of a thin SVD), the **last** core absorbs the magnitude (the remaining
`S·Vᵀ`). Per-column integer scales keep the isometries unit-scaled so magnitude
never drifts multiplicatively; the last core carries the amplitude.
**Fidelity knob — residual layers (`TernaryStack`).** RVQ over ternary-MPS: each
layer ternary-MPS-encodes the residual of the sum so far. Decode **sums** the
layers. A sum of byte-exact deterministic integer decodes is itself byte-exact
deterministic, so fidelity climbs with depth while the reconstruction stays
portable. `phys = 2` is the binary reshape; **`phys = 3` is the qutrit/base-3
site reshape** (a ternary *site* dimension, distinct from the ternary *weights*).
## 4. Conformance — reconstruction-equivalence
A sink conforms iff, given a `WQTT` payload, it produces a decoded signal whose
BLAKE3 (`reconstruction_hash`) matches — byte for byte, on every machine. This is
the deterministic-floor `*-equivalence` criterion the other WAI extensions use,
here over the integer decode. The registry classes it accordingly:
`capability_tier = Lossy` (fidelity to *source* is lossy), `replicate_class =
StandardDefined` (the reconstruction is fixed by WAI's deterministic floor, not a
float neural decode), `license = RoyaltyFree`.
## 5. Rate–distortion verdict (measured)
Measured on a realistic 256-sample multi-tone + noise stream (raw 2048 B, bond
≤ 4), reconstruction SNR vs on-wire bytes as residual layers accumulate:
| layers | SNR | payload (entropy-coded) |
|---|---|---|
| K=1 | 3.6 dB | 104 B (19.7×) |
| K=2 | 5.7 dB | 194 B (10.6×) |
| K=3 | 7.6 dB | 280 B (7.3×) |
| K=4 | 10.1 dB | 370 B (5.5×) |
| K=6 | 13.3 dB | 546 B (3.8×) |
Two limits, both recorded so the scope is stated plainly:
- **Low rate–distortion.** 13.3 dB at 3.8× with six layers (the table above); the
noise floor is incompressible and multi-tone content out-ranks bond-4. On a toy
sinusoid it reaches ~20 dB @ 2×, but that is a flattering input.
- **Entropy coding of the trits is break-even.** The trit stream is ~54% zeros
(≈1.45 bits vs the base-3 packing's 1.6, ~9% headroom), most of which the rANS
header/state overhead eats; it is even a small loss at low layer counts. The
five-trits-per-byte packing is already near-optimal.
Consistent with WAI's own charter (SPEC Appendix B: *don't reinvent codecs*). The
value is **not** the ratio — it is that the reconstruction and its cost are
byte-exact and auditable.
## 6. Receipt (JWP profile)
The provenance payoff (`ternary_receipt.rs`). A [`TernaryReceipt`] separates the
two costs so each is trusted honestly:
| field | what | trust |
|---|---|---|
| `payload_hash` | BLAKE3 of the `WQTT` bytes | re-checkable (tamper-evidence) |
| `reconstruction_hash` | BLAKE3 of the decoded signal | **re-checkable** (re-decode) |
| `trit_macs` | Σ trit-tensor sizes — the decode work | **verified** by recomputation |
| `joules_micro` | measured marginal energy | **attested** by signature |
`seal` decodes the stack (so `reconstruction_hash` is always the true
reconstruction); `verify` checks the Merkle root + Ed25519 (as SPEC §7 *Signatures*
requires); `verify_reconstruction`
recovers the stack from the `WQTT` payload and confirms hash, shape, work, and
reconstruction independently. Chains via `parent_receipt_hash`. The JWP Merkle +
Ed25519 are reused verbatim — the same shape as `QuantumReceipt`
([quantum-sim](quantum-sim.md)) and the world/provenance receipts. Its energy
comes from the same bracket as `wai_quantum_meter`'s, `ModelBased` over a
reported power ([energy-measurement](energy-measurement.md) §3.1); never fabricated.
The figure's acquisition class rides beside it as an optional signed label
([energy-measurement](energy-measurement.md) §2.8): absent, the receipt keeps
its legacy bytes and the figure is unlabelled; present, it is inside the
signature. `with_energy_class` labels and re-signs a sealed receipt.
## 7. Productionize only with a use case
This capability is registered and receipt-backed, but its RD verdict means it
earns a place in a deployment **only** where a concrete auditable-edge-stream
requirement makes provenance outrank ratio. Absent that, it is a proven reference
prototype — do not tune the RD further; that ceiling is not the interesting
question, and it has been measured.