rlightning.types.env_rets¶
Environment return data structures.
This module provides dataclasses for representing environment step/reset returns, supporting both single-agent and multi-agent scenarios.
- class rlightning.types.env_rets.EnvRet(env_id: str, observation: Any, last_reward: float = 0.0, last_terminated: bool = False, last_truncated: bool = False, info: Dict[str, ~typing.Any]=<factory>, _extra: Dict[str, ~typing.Any]=<factory>, ts_env_sent_ns: int = <factory>)[source]¶
Bases:
objectEnvironment return data structure for single-agent interactions.
Represents the return value from environment step() or reset() calls, containing observation, reward, termination status, and additional info.
- observation¶
Observation after environment step/reset.
- Type:
Any
- last_info¶
Additional info dictionary from the environment.
- compute_sent_latency(now_ns: int | None = None) float[source]¶
Compute latency in seconds from env-sent timestamp to now.
Use for env->policy or env->buffer transfer time (e.g. in policy _rollout_hook or in buffer add_transition).
- Parameters:
now_ns – Current time in nanoseconds. If None, uses time.time_ns().
- Returns:
Latency in seconds, or 0.0 if ts_env_sent_ns is missing or invalid.
- cuda(device: str | int | None = None) EnvRet[source]¶
Move all tensor attributes to CUDA.
- Parameters:
device – CUDA device index or string. Defaults to ‘cuda’.
- Returns:
Self with tensors moved to CUDA.
- classmethod fields() Tuple[source]¶
Get field names excluding internal fields.
- Returns:
Tuple of field names for serialization.
- classmethod get_defaults() Dict[str, Any][source]¶
Get default values for all serializable fields.
- Returns:
Dictionary mapping field names to default values.
- mark_env_sent() EnvRet[source]¶
Record the timestamp when the env return is sent.
- Returns:
Self for method chaining.
- numpy() EnvRet[source]¶
Convert all tensor attributes to numpy arrays.
- Returns:
Self with tensors converted to numpy arrays.
- class rlightning.types.env_rets.MultiAgentEnvRet(env_id: str, observation: Any, last_reward: Dict[str, float]=0.0, last_terminated: Dict[str, bool]=False, last_truncated: Dict[str, bool]=False, info: Dict[str, ~typing.Any]=<factory>, _extra: Dict[str, ~typing.Any]=<factory>, ts_env_sent_ns: int = <factory>)[source]¶
Bases:
EnvRetEnvironment return for multi-agent interactions.
Extends EnvRet with dictionary-based rewards and termination flags for multiple agents.