pub trait State<const R: usize>:
Debug
+ Clone
+ Send
+ Sync {
type Observation: Observation<R>;
const RANK: usize = R;
// Required methods
fn shape() -> [usize; R];
fn observe(&self) -> Self::Observation;
fn is_valid(&self) -> bool;
// Provided method
fn numel(&self) -> usize { ... }
}Expand description
The complete state of an environment (Markov property)
Provided Associated Constants§
Sourceconst RANK: usize = R
const RANK: usize = R
The rank of this state space — i.e. the number of axes (tensor order), not the size of any axis.
“Rank” here means the count of indices needed to address an element
(NumPy ndim, Burn’s Tensor<B, R>), not matrix rank or CP-decomposition
rank. This is automatically set to match the const generic parameter R.
Required Associated Types§
type Observation: Observation<R>
Required Methods§
Sourcefn shape() -> [usize; R]
fn shape() -> [usize; R]
Returns the size of each axis in this state space.
The returned array has length R (the rank), where each element is the
cardinality of that axis — the number of possible values along it. All
values must be greater than zero.
Sourcefn observe(&self) -> Self::Observation
fn observe(&self) -> Self::Observation
Generate an observation from this state (may be partial)
Sourcefn is_valid(&self) -> bool
fn is_valid(&self) -> bool
Validates whether this state satisfies all constraints.
This method checks if the state is legal according to its type’s invariants. It does not check environment-specific legality - that’s the environment’s responsibility.
§Returns
Returns true if the state satisfies all structural constraints, false otherwise.
Provided Methods§
Sourcefn numel(&self) -> usize
fn numel(&self) -> usize
Returns the total number of scalar elements in this state’s representation.
This value is critical for:
- Allocating buffers for state serialization
- Determining neural network input layer dimensions
- Validating state transformations (e.g., flattening/unflattening)
§Relationship to Shape
For consistency, numel() must equal the product of all dimensions returned by
shape(). The default implementation enforces this by computing
the product directly. Override only if the state uses a non-product layout.
§Returns
The total number of scalar elements needed to represent this state.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".