pub struct Ledger<R, N> { /* private fields */ }Expand description
The threaded state of a run: what was spent on the device, and what was only computed.
Device time is the scarce resource. Context is read-only and cannot accumulate, the log is a record rather than a running total, and the value is the answer rather than the meter, so state is the only channel both writable and threaded, and this is what rides it.
Counts are ℕ on N: NaturalNumber, whose width a program names once with NumberType;
widening it buys headroom and moves no threshold. Real quantities are on R. Copy, with no
Vec and no String, and a hand-written Default from the two zeros, because the causal
monad requires State: Default and a derived one would demand R: Default.
§Three invariants
observe is the only stage that touches shots, experiments and device_time; predict
touches predictions and nothing on the device side. fork is the pipeline’s, above core, by
cloning. Forked ledgers are compared, never joined under ∇: at a counterfactual fork exactly one
branch was factual, and a monoid that summed them would typecheck and be wrong.
Implementations§
Source§impl<R: RealField, N: NaturalNumber> Ledger<R, N>
impl<R: RealField, N: NaturalNumber> Ledger<R, N>
Sourcepub fn experiments(&self) -> N
pub fn experiments(&self) -> N
Experiments executed on hardware.
Sourcepub fn predictions(&self) -> N
pub fn predictions(&self) -> N
Model evaluations: tracked, never billed.
Sourcepub fn device_time(&self) -> R
pub fn device_time(&self) -> R
Accumulated device time.
Sourcepub fn draw_down(budget: N, request: N) -> Result<N, QuantumError>where
N: Debug,
pub fn draw_down(budget: N, request: N) -> Result<N, QuantumError>where
N: Debug,
The remainder of budget after drawing request from it, in checked ℕ arithmetic.
§Errors
QuantumError::CalculationError naming the shortfall when request exceeds budget:
checked_difference returned None, and monus says by how much.