rlmesh.adapters.State

classfrom rlmesh.adapters import State[source]

A single-part numeric state input expected by a model.

State(
    role: str,
    encoding: RotationEncoding | Sequence[RotationEncoding] | CustomEncoding | None = None,
    dim: int | None = None,
    index: int | None = None,
    optional: bool = False,
    range: tuple[float, float] | None = None,
    pad_to: int | None = None,
    dtype: str = 'float32',
    reshape: tuple[int, ...] | None = None,
    container: Literal['array', 'list'] = 'array',
    *,
    fill: float = 0.0,
    post_rotate: Rotation | None = None,
    scale: float | Sequence[float] | None = None,
    offset: float | Sequence[float] | None = None,
    frame: Frame | None = None,
    provenance: Provenance | Sequence[Provenance] | None = None,
    part: str | None = None,
    labels: Sequence[str] | None = None,
    source: Literal['observation', 'action'] = 'observation',
    clip: tuple[float, float] | None = None,
)

The 1-part case: one role packed into the value, sourced from an env state feature. Use Concat to pack several roles into one tensor. A State is also a valid Concat part (its part fields – role, encoding, dim, index, optional, range, fill, post_rotate, scale, offset, frame, provenance, part, labels, source – are taken; its container fields must stay default when used as a part).

There is no key – placement in the input tree is the payload position.

Attributes

role

attribute[source]
role: str

Semantic role matched against env state features.

encoding

attribute[source]
encoding: RotationEncoding | Sequence[RotationEncoding] | CustomEncoding | None

Rotation encoding the model expects for this part. A single encoding, or a sequence of them in preference order (most-preferred first) — the resolver picks the env’s native encoding when it appears here (no conversion), else converts into the first entry. A CustomEncoding is a single host-side packing (not a set). "gravity_xyz" reads any env rotation as the gravity direction in the body frame (projected gravity, 3 wide); an env that publishes gravity_xyz itself binds only a part that wants it.

dim

attribute[source]
dim: int | None

Optional number of leading elements to keep from the source.

index

attribute[source]
index: int | None

Optional single element to select after any conversion.

optional

attribute[source]
optional: bool

Zero-fill this part when the env does not declare the role, instead of failing resolution. The fill width comes from index (one), dim, or encoding; one of them must be set so the width is known without an env feature.

range

attribute[source]
range: tuple[float, float] | None

Optional (low, high) the model expects this part in; when the env declares its own (derived or tagged) range, the value is affinely mapped from the env range to this one (symmetric to action ranges). With no env source range there is nothing to map from, so it is a no-op – it does not clamp or rescale on its own.

fill

attribute[source]
fill: float

Value this part contributes when optional is set and the env lacks the role (zeros by default). A non-zero fill requires optional, matching Actuator.fill.

post_rotate

attribute[source]
post_rotate: Rotation | None

A fixed Rotation right-multiplied onto the env’s rotation (R_out = R_in @ R(post_rotate)) before it is re-encoded into encoding. Needs a rotation encoding; not combinable with a CustomEncoding.

scale

attribute[source]
scale: float | Sequence[float] | None

Model-side multiplier applied after the range map: one float for every axis, or a sequence with one value per axis in this part’s own labels order (its resolved width otherwise), serialized as axis_scale.

offset

attribute[source]
offset: float | Sequence[float] | None

Model-side addend applied after scale (value * scale + offset) – e.g. a 1 - 2g gripper is scale=-2, offset=1, a stand pose is offset=tuple(-q for q in DEFAULT_POSE). A float or a per-axis sequence like scale.

frame

attribute[source]
frame: Frame | None

Coordinate frame the checkpoint was trained to read this part in, when the role is an absolute pose (proprio/eef_*). Keyword-only and omitted from the wire when unset. A frame the env contradicts fails resolution; a frame the env does not declare draws a caution (the model states a requirement nothing can confirm).

provenance

attribute[source]
provenance: Provenance | Sequence[Provenance] | None

Where the checkpoint expects this part’s numbers to come from: "sensed", "estimated" or "privileged", or a sequence of the ones it accepts. Against an env that publishes the role under several provenances the declaration picks the leaf (an env publishing several and a model naming none is an error); a value the env contradicts fails resolution, and one the env does not declare draws a caution. Keyword-only and omitted from the wire when unset.

part

attribute[source]
part: str | None

The body part this part reads, when the role repeats across a body (LEFT_ARM, RIGHT_ARM, or any identifier both sides agree on): an identity key the resolver matches on. Naming one binds only that env leaf (a missing one fills if optional, else fails); naming none binds the env’s only leaf of the role under any part (with an info) and fails when there are several, naming them. Keyword-only and omitted from the wire when unset.

labels

attribute[source]
labels: Sequence[str] | None

The axis names this part reads, in the order the checkpoint was trained on. Fixes the width. The env leaf must label its axes with the same set; the values are gathered by name, so a differing order is a permutation, and a label either side lacks (or an env leaf with no labels) is a resolve error. Keyword-only and omitted from the wire when unset; not combinable with index. On an action-source part the names reorder the actuator’s labels.

source

attribute[source]
source: Literal['observation', 'action']

Where the value comes from: "observation" (the default, an env state feature matched by role) or "action" (the model’s own output actuator of the same role and part, read back as the raw action executed at the previous step, in model order, before the actuator’s scale/offset; fill before the episode’s first action). Previous() is the sugar. An action-source part carries only part, labels, dim and fill. Keyword-only and omitted from the wire when default.

pad_to

attribute[source]
pad_to: int | None

Zero-pad the resulting vector to this length. Padding is the last step: every part is converted, ranged and scaled, the parts are concatenated in order, and only then is the result padded.

dtype

attribute[source]
dtype: str

NumPy dtype name of the resulting value.

reshape

attribute[source]
reshape: tuple[int, ...] | None

Optional target shape for the resulting value.

container

attribute[source]
container: Literal['array', 'list']

Emit a NumPy array or a plain Python list.

clip

attribute[source]
clip: tuple[float, float] | None

Clamp the assembled vector to (low, high) after every part’s own transforms and before pad_to (legged_gym’s clip_obs). Keyword-only and omitted from the wire when unset.