Playground environments¶
Overview¶
The repository https://github.com/google-deepmind/mujoco_playground provides the MuJoCo Playground environments.
These environments can be easily loaded and configured by calling a single function provided with this library. Such function also makes it possible to configure the environment from the command line arguments or from its parameters.
Note
The command line arguments has priority over the function parameters.
Run the following command to list all the available MuJoCo Playground environments:
python -c "import mujoco_playground; print(mujoco_playground.registry.ALL_ENVS)"
Usage¶
The following snippets show how to load MuJoCo Playground environments:
# import the environment loader
from skrl.envs.loaders.torch import load_playground_env
# load environment
env = load_playground_env(task_name="CartpoleBalance", num_envs=1024, episode_length=300)
# import the environment loader
from skrl.envs.loaders.jax import load_playground_env
# load environment
env = load_playground_env(task_name="CartpoleBalance", num_envs=1024, episode_length=300)
# import the environment loader
from skrl.envs.loaders.warp import load_playground_env
# load environment
env = load_playground_env(task_name="CartpoleBalance", num_envs=1024, episode_length=300)
# import the environment loader
from skrl.envs.loaders.torch import load_playground_env
# load environment
env = load_playground_env()
# import the environment loader
from skrl.envs.loaders.jax import load_playground_env
# load environment
env = load_playground_env()
# import the environment loader
from skrl.envs.loaders.warp import load_playground_env
# load environment
env = load_playground_env()
Run the main script passing the configuration as command line arguments. For example:
python script.py --task CartpoleBalance --num_envs 1024 --episode_length 300
API¶
PyTorch¶
- skrl.envs.loaders.torch.load_playground_env(*, task_name: str = '', num_envs: int | None = None, episode_length: int | None = None, action_repeat: int | None = None, full_reset: bool = False, randomization: bool = False, cfg_overrides: dict | None = None, show_cfg: bool = True, parser: ArgumentParser | None = None)[source]¶
Load a MuJoCo Playground environment.
MuJoCo Playground: https://playground.mujoco.org
This function includes the definition and parsing of the following command line arguments:
--task: Name of the task.--num_envs: Number of environments to simulate.--seed: Random seed.--episode_length: Length of the episode.--action_repeat: Number of times to repeat the given action per step.--full_reset: Whether to perform a full reset of the environment on each step, rather than resetting to an initial cached state.--randomization: Whether to use randomization.
- Parameters:
task_name – The name of the task. If not specified, the task name is taken from the command line argument (
--task TASK_NAME). Command line argument has priority over function parameter if both are specified.num_envs – Number of parallel environments to create. If not specified, the number of environments is taken from the command line argument (
--num_envs N). Command line argument has priority over function parameter if both are specified.episode_length – Length of the episode. If neither the function parameter nor the command line argument is specified, the default configuration for the task will be used. Command line argument has priority over function parameter if both are specified.
action_repeat – Number of times to repeat the given action per step. If neither the function parameter nor the command line argument is specified, the default configuration for the task will be used. Command line argument has priority over function parameter if both are specified.
full_reset – Whether to perform a full reset of the environment on each step, rather than resetting to an initial cached state. Enabling this option may increase wall clock time because it forces full resets to random states. Command line argument has priority over function parameter if both are specified.
randomization – Whether to use randomization. If the environment does not provide a randomization function, the randomization flag is ignored. Command line argument has priority over function parameter if both are specified.
cfg_overrides – Configuration overrides for the environment.
show_cfg – Whether to print the configuration.
parser – The argument parser to use. If not specified, a new argument parser will be created.
- Returns:
MuJoCo Playground environment.
- Raises:
ValueError – The task name has not been defined, neither by the function parameter nor by the command line arguments, or the task name is invalid.
ValueError – The number of environments has not been defined, neither by the function parameter nor by the command line arguments.
ValueError – The episode length has not been defined, neither by the function parameter nor by the command line arguments. The task configuration does not provide a default episode length.
JAX¶
- skrl.envs.loaders.jax.load_playground_env(*, task_name: str = '', num_envs: int | None = None, episode_length: int | None = None, action_repeat: int | None = None, full_reset: bool = False, randomization: bool = False, cfg_overrides: dict | None = None, show_cfg: bool = True, parser: ArgumentParser | None = None)[source]¶
Load a MuJoCo Playground environment.
MuJoCo Playground: https://playground.mujoco.org
This function includes the definition and parsing of the following command line arguments:
--task: Name of the task.--num_envs: Number of environments to simulate.--seed: Random seed.--episode_length: Length of the episode.--action_repeat: Number of times to repeat the given action per step.--full_reset: Whether to perform a full reset of the environment on each step, rather than resetting to an initial cached state.--randomization: Whether to use randomization.
- Parameters:
task_name – The name of the task. If not specified, the task name is taken from the command line argument (
--task TASK_NAME). Command line argument has priority over function parameter if both are specified.num_envs – Number of parallel environments to create. If not specified, the number of environments is taken from the command line argument (
--num_envs N). Command line argument has priority over function parameter if both are specified.episode_length – Length of the episode. If neither the function parameter nor the command line argument is specified, the default configuration for the task will be used. Command line argument has priority over function parameter if both are specified.
action_repeat – Number of times to repeat the given action per step. If neither the function parameter nor the command line argument is specified, the default configuration for the task will be used. Command line argument has priority over function parameter if both are specified.
full_reset – Whether to perform a full reset of the environment on each step, rather than resetting to an initial cached state. Enabling this option may increase wall clock time because it forces full resets to random states. Command line argument has priority over function parameter if both are specified.
randomization – Whether to use randomization. If the environment does not provide a randomization function, the randomization flag is ignored. Command line argument has priority over function parameter if both are specified.
cfg_overrides – Configuration overrides for the environment.
show_cfg – Whether to print the configuration.
parser – The argument parser to use. If not specified, a new argument parser will be created.
- Returns:
MuJoCo Playground environment.
- Raises:
ValueError – The task name has not been defined, neither by the function parameter nor by the command line arguments, or the task name is invalid.
ValueError – The number of environments has not been defined, neither by the function parameter nor by the command line arguments.
ValueError – The episode length has not been defined, neither by the function parameter nor by the command line arguments. The task configuration does not provide a default episode length.
Warp¶
- skrl.envs.loaders.warp.load_playground_env(*, task_name: str = '', num_envs: int | None = None, episode_length: int | None = None, action_repeat: int | None = None, full_reset: bool = False, randomization: bool = False, cfg_overrides: dict | None = None, show_cfg: bool = True, parser: ArgumentParser | None = None)[source]¶
Load a MuJoCo Playground environment.
MuJoCo Playground: https://playground.mujoco.org
This function includes the definition and parsing of the following command line arguments:
--task: Name of the task.--num_envs: Number of environments to simulate.--seed: Random seed.--episode_length: Length of the episode.--action_repeat: Number of times to repeat the given action per step.--full_reset: Whether to perform a full reset of the environment on each step, rather than resetting to an initial cached state.--randomization: Whether to use randomization.
- Parameters:
task_name – The name of the task. If not specified, the task name is taken from the command line argument (
--task TASK_NAME). Command line argument has priority over function parameter if both are specified.num_envs – Number of parallel environments to create. If not specified, the number of environments is taken from the command line argument (
--num_envs N). Command line argument has priority over function parameter if both are specified.episode_length – Length of the episode. If neither the function parameter nor the command line argument is specified, the default configuration for the task will be used. Command line argument has priority over function parameter if both are specified.
action_repeat – Number of times to repeat the given action per step. If neither the function parameter nor the command line argument is specified, the default configuration for the task will be used. Command line argument has priority over function parameter if both are specified.
full_reset – Whether to perform a full reset of the environment on each step, rather than resetting to an initial cached state. Enabling this option may increase wall clock time because it forces full resets to random states. Command line argument has priority over function parameter if both are specified.
randomization – Whether to use randomization. If the environment does not provide a randomization function, the randomization flag is ignored. Command line argument has priority over function parameter if both are specified.
cfg_overrides – Configuration overrides for the environment.
show_cfg – Whether to print the configuration.
parser – The argument parser to use. If not specified, a new argument parser will be created.
- Returns:
MuJoCo Playground environment.
- Raises:
ValueError – The task name has not been defined, neither by the function parameter nor by the command line arguments, or the task name is invalid.
ValueError – The number of environments has not been defined, neither by the function parameter nor by the command line arguments.
ValueError – The episode length has not been defined, neither by the function parameter nor by the command line arguments. The task configuration does not provide a default episode length.