Experimental¶
Utilities in gymnax.experimental may change between releases.
RolloutWrapper ¶
RolloutWrapper(model_forward=None, env_name: str | None = None, num_env_steps: int | None = None, env_kwargs: Any | None = None, env_params: Any | None = None, env: Any | None = None)
Roll out a policy in an environment with jax.lax.scan.
single_rollout runs one rollout, batch_rollout maps it over a batch of PRNG
keys and population_rollout additionally maps it over a batch of policy
parameters. All three return the same tuple, with one leading axis per mapped
quantity.
Parameters:
-
model_forward(Callable | None, default:None) –Policy function
(policy_params, obs, key) -> action. IfNone, actions are sampled uniformly from the action space. -
env_name(str | None, default:None) –Registered Gymnax environment ID. Defaults to
Pendulum-v1. -
num_env_steps(int | None, default:None) –Number of transitions in each rollout. Defaults to
max_steps_in_episodeof the environment parameters. -
env_kwargs(Any | None, default:None) –Constructor keyword arguments for
env_name. -
env_params(Any | None, default:None) –Parameter overrides as a mapping of field names to values, or a complete parameter object.
-
env(Any | None, default:None) –Pre-constructed environment, bypassing
gymnax.make. Cannot be combined withenv_nameorenv_kwargs.
population_rollout ¶
Roll out a population of policies, each on the same batch of keys.
Parameters:
-
key_eval(Array) –Batch of PRNG keys, one per rollout of each policy.
-
policy_params(Any) –Policy parameters with a leading population axis.
Returns:
-
tuple–The tuple described in
single_rollout, with leading axes(population, keys).
batch_rollout ¶
Roll out one policy once per key.
Parameters:
-
key_eval(Array) –Batch of PRNG keys, one per rollout.
-
policy_params(Any) –Parameters of a single policy.
Returns:
-
tuple–The tuple described in
single_rollout, with a leading key axis.
single_rollout ¶
Roll out one policy for num_env_steps transitions.
The environment resets automatically, so a rollout can span several episodes. Only rewards of the first episode count towards the return.
Parameters:
-
key_input(Array) –PRNG key.
-
policy_params(Any) –Parameters of a single policy.
Returns:
-
tuple–A tuple
(obs, action, reward, next_obs, done, cum_return). The first five entries have a leading time axis of lengthnum_env_steps;cum_returnhas shape(1,)and holds the return of the first episode.