Skip to main content

Module policy

Module policy 

Source
Expand description

The policy shell’s ONNX contract, version 1: how a trained policy’s model must look so one generic program runs it in every arena.

  • Inputs: one per declared observation, named exactly as declared, shape [1, *shape], f32. A u8 value is fed as f32 / 255. A policy may use a subset of the observations.
  • Memory: an optional state_in: f32[1, S] → state_out: f32[1, S] pair, S at most MAX_STATE. Zeros at the start; each turn’s state_out is the next turn’s state_in.
  • Continuous actions (declared f32): one output per declared action, named as declared, shape [1, *shape], in [-1, 1]. The shell maps each element with to_bounds: clamp to [-1, 1] (NaN is 0, the midpoint), then affinely onto the element’s declared bounds.
  • Discrete actions (declared u8): one output per declared action, named as declared, of logits shaped [1, *shape, n], where every element shares one range [min, max] and n = max - min + 1. The shell takes the argmax of each element’s logits (argmax) and adds min.
  • Metadata: META_CONTRACT, META_ARENA, META_PAYLOAD_SCHEMA, META_TRAIN_VERSION and META_OPSET, checked against the manifest.
  • An input named NOISE is reserved.

botstadia-train implements the same map; the shared golden file (policy-golden.json, beside this crate’s tests) pins both.

Constants§

CONTRACT_VERSION
This contract’s version, as the botstadia.contract metadata states it.
EXPORT_OPSET
The opset the export helper writes.
GOLDEN
The golden cases pinning to_bounds, feed_u8 and argmax, which botstadia-train checks its own implementation against.
MAX_STATE
The largest memory, in floats.
META_ARENA
META_CONTRACT
META_OPSET
META_PAYLOAD_SCHEMA
META_TRAIN_VERSION
NOISE
Reserved for sampled actions later.
STATE_IN
The memory pair’s names.
STATE_OUT

Functions§

argmax
The index of the largest logit; NaN never wins, and ties go to the first.
feed_u8
An observation element as the policy sees it.
from_bounds
The inverse of to_bounds, for training: a declared value as the policy’s [-1, 1].
to_bounds
One element of a continuous action: a policy output in [-1, 1] mapped onto the declared [min, max]. Out-of-range outputs are clamped and NaN is the midpoint, so the result is always valid.