General Utils¶
- agilerl.utils.utils.make_vect_envs(env_name: str | None = None, num_envs=1, *, make_env: Callable | None = None, should_async_vector: bool = True, **env_kwargs)¶
Returns async-vectorized gym environments.
- Parameters:
env_name (str) – Gym environment name
num_envs (int, optional) – Number of vectorized environments, defaults to 1
make_env (Callable, optional) – Function that creates a gym environment, defaults use gym.make(env_name)
should_async_vector (bool, optional) – Whether to asynchronous vectorized environments, defaults to True
- agilerl.utils.utils.make_multi_agent_vect_envs(env, num_envs=1, **env_kwargs)¶
Returns async-vectorized PettingZoo parallel environments.
- Parameters:
env (pettingzoo.utils.env.ParallelEnv) – PettingZoo parallel environment object
num_envs (int, optional) – Number of vectorized environments, defaults to 1
- agilerl.utils.utils.make_skill_vect_envs(env_name, skill, num_envs=1)¶
Returns async-vectorized gym environments.
- Parameters:
env_name (str) – Gym environment name
skill (agilerl.wrappers.learning.Skill) – Skill wrapper to apply to environment
num_envs (int, optional) – Number of vectorized environments, defaults to 1
- agilerl.utils.utils.create_population(algo, state_dim, action_dim, one_hot, net_config, INIT_HP, actor_network=None, critic_network=None, population_size=1, num_envs=1, device='cpu', accelerator=None, torch_compiler=None)¶
Returns population of identical agents.
- Parameters:
algo (str) – RL algorithm
state_dim (int) – State observation dimension
action_dim (int) – Action dimension
one_hot (bool) – One-hot encoding
net_config (dict or None) – Network configuration
INIT_HP (dict) – Initial hyperparameters
actor_network (nn.Module, optional) – Custom actor network, defaults to None
critic_network (nn.Module, optional) – Custom critic network, defaults to None
population_size (int, optional) – Number of agents in population, defaults to 1
num_envs (int, optional) – Number of vectorized environments, defaults to 1
device (str, optional) – Device for accelerated computing, ‘cpu’ or ‘cuda’, defaults to ‘cpu’
accelerator (accelerate.Accelerator(), optional) – Accelerator for distributed computing, defaults to None
torch_compiler
- agilerl.utils.utils.print_hyperparams(pop)¶
Prints current hyperparameters of agents in a population and their fitnesses.