skrl
cosmic_warp.rl.adapters.skrl
skrl adapter for :class:cosmic_warp.rl.VecEnv.
Wraps the neutral environment as a skrl torch environment wrapper so it can
be trained with any skrl agent (PPO, SAC, …). The mapping is near
pass-through: skrl already uses the split terminated / truncated
convention and torch tensors, so the adapter only reshapes rewards/flags to the
[N, 1] layout skrl expects and clones the observation (skrl retains
the reference across the next step; our buffer is single-buffered). The
terminal observations go in infos["terminal_observations"].
build_ppo_agent is a convenience that assembles a Gaussian-policy PPO agent
with sensible defaults; use it or build your own models/agent directly. It
returns a :class:TerminalObsPPO, which bootstraps truncated transitions from
the terminal observation: skrl's own PPO would evaluate the value of the
returned observation, which for a truncated environment is already the first
observation of its next episode.
Requires the skrl optional dependency (pip install "cosmic-warp[skrl]"),
which pulls in PyTorch. Tested against skrl 2.1.
SkrlVecEnv
SkrlVecEnv(env: VecEnv)
Bases: Wrapper
Present a :class:cosmic_warp.rl.VecEnv through the skrl wrapper interface.
step returns infos[TERMINAL_OBS_KEY], the observation of the state
each environment reached (pre-reset; meaningful only where the step
ended the episode), for :class:TerminalObsPPO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
VecEnv
|
The COSMIC WARP environment to wrap. |
required |
Source code in cosmic_warp/rl/adapters/skrl.py
vec_env
property
vec_env: VecEnv
The wrapped COSMIC WARP :class:~cosmic_warp.rl.VecEnv (for
evaluation loops outside the trainer).
TerminalObsPPO
Bases: PPO
skrl PPO that bootstraps truncated transitions from the terminal observation.
skrl's PPO, with time_limit_bootstrap, adds gamma * V(next_obs) to
the reward of a truncated transition. Under auto-reset next_obs is
the first observation of the next episode, so this agent substitutes
infos[TERMINAL_OBS_KEY] (from :class:SkrlVecEnv) on the truncated
rows before skrl evaluates it. Keep time_limit_bootstrap on: GAE also
uses it to stop at the truncation. Without the key in infos it
behaves as skrl's PPO.
build_ppo_agent
build_ppo_agent(
env: SkrlVecEnv,
rollouts: int = 24,
hidden=(128, 128),
learning_rate: float = 0.001,
entropy_loss_scale: float = 0.005,
)
Assemble a Gaussian-policy PPO agent for continuous control.
A convenience default, not a tuned recipe — build your own models/agent for
anything beyond a quick run (with :class:TerminalObsPPO to keep the
terminal-observation bootstrap). Returns a :class:TerminalObsPPO with
time_limit_bootstrap on.