Download rl/v2d_rl/algorithms/ppo.py from hk239/v2d: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/datasets/hk239/v2d/resolve/main/rl/v2d_rl/algorithms/ppo.py
- Command line
-
hf download hf://datasets/hk239/v2d/rl/v2d_rl/algorithms/ppo.py
-
curl -L -o ppo.py https://huggingface.co/datasets/hk239/v2d/resolve/main/rl/v2d_rl/algorithms/ppo.py
1.24 kB
| """RSL-RL PPO trainer stub (Isaac Lab ``OnPolicyRunner``). | |
| Hyperparameters come from the Gym task's ``rsl_rl_cfg_entry_point``. | |
| Swap this class when we lock the algorithm (plain PPO vs joint residual, etc.). | |
| """ | |
| from __future__ import annotations | |
| from typing import Any | |
| from .base import Algorithm | |
| class RslRlPpoTrainer(Algorithm): | |
| def __init__(self, agent_cfg: Any): | |
| self.agent_cfg = agent_cfg | |
| self._runner = None | |
| def train(self, env: Any, log_dir: str) -> None: | |
| from isaaclab.utils import class_to_dict | |
| from rsl_rl.runners import OnPolicyRunner | |
| self._runner = OnPolicyRunner( | |
| env, class_to_dict(self.agent_cfg), log_dir=log_dir, device=str(env.unwrapped.device) | |
| ) | |
| self._runner.learn( | |
| num_learning_iterations=self.agent_cfg.max_iterations, | |
| init_at_random_ep_len=True, | |
| ) | |
| def load(self, checkpoint: str) -> None: | |
| if self._runner is None: | |
| raise RuntimeError("call train() or construct a runner before load()") | |
| self._runner.load(checkpoint) | |
| def act(self, obs: Any) -> Any: | |
| if self._runner is None: | |
| raise RuntimeError("no runner") | |
| return self._runner.alg.act(obs) | |