Speed lanes
Progressive “how do I go faster?” helpers and the single-run array model. See also the user guide Going faster (lanes).
For a view-API model on GPU, prefer
MyModel(...).gpu().run() with step_vectorized() (0.4.4) rather than
rewriting the step as an ArrayKernelModel. Use
ArrayKernelModel when the state is naturally a pure array dict and you do
not need the Polars view API.
Status & recommendations
Array kernel model
- class ambr.lanes.ArrayKernelModel(parameters: Dict[str, Any] | None = None)[source]
Bases:
objectEasiest single-run CPU/GPU array model (no Polars step required).
Subclass and implement:
init_state(xp, n, rng, p) -> dictof arraysstep_state(xp, state, rng, p) -> stateoptional
metrics(xp, state) -> dictof Python scalars each step
xpis CuPy when a GPU is available, else NumPy — same code path.Example:
class Drift(am.ArrayKernelModel): def init_state(self, xp, n, rng, p): return {"x": rng.random(n, dtype=xp.float32)} def step_state(self, xp, state, rng, p): state["x"] = state["x"] + 0.01 return state def metrics(self, xp, state): return {"mean_x": float(am.to_host(state["x"].mean()))} res = Drift({"n": 100_000, "steps": 50, "seed": 0}).run() print(res.model) # per-step metrics if metrics() defined
- metrics(xp, state: Dict[str, Any]) Dict[str, Any][source]
Optional per-step scalars (host floats). Default: none.