bordax.environments
bordax.environments.utils
EnvAdapter
Bases: ABC
Unified interface over Gymnax and Gymnasium environments.
All environments are treated as vectorised: reset and step
operate on a batch of num_envs parallel episodes.
Attributes:
| Name | Type | Description |
|---|---|---|
is_jittable |
bool
|
Whether the environment can be used inside
|
num_envs |
int
|
Number of parallel environment instances. |
env |
Any
|
The underlying environment object. |
env_params |
Any
|
Static environment parameters (e.g. episode length). |
Source code in bordax/environments/utils.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
action_space()
abstractmethod
Return the single-environment action space.
Source code in bordax/environments/utils.py
81 82 83 84 | |
obs_space()
abstractmethod
Return the single-environment observation space.
Source code in bordax/environments/utils.py
86 87 88 89 | |
reset(key)
abstractmethod
Reset all environments and return initial observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKey
|
JAX random key used to seed the reset. |
required |
Returns:
| Type | Description |
|---|---|
EnvObs
|
Tuple of |
EnvState
|
|
Source code in bordax/environments/utils.py
52 53 54 55 56 57 58 59 60 61 62 63 | |
step(key, state, action)
abstractmethod
Step all environments forward by one timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKey
|
JAX random key for stochastic transitions. |
required |
state
|
EnvState
|
Current environment state (batch of |
required |
action
|
Any
|
Actions to apply, shape |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Any, EnvState, float, bool, Mapping[str, Any]]
|
Tuple of |
Source code in bordax/environments/utils.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
EnvGymnasiumAdapter
Bases: EnvAdapter
Adapter for standard Gymnasium environments (non-JIT).
Wraps a vectorised Gymnasium environment (gymnasium.make_vec).
Only the gradient update step can be JIT-compiled; environment
stepping runs in Python.
Source code in bordax/environments/utils.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
EnvGymnaxAdapter
Bases: EnvAdapter
Adapter for Gymnax environments (fully JIT-compilable).
Wraps a Gymnax environment with jax.vmap across num_envs
parallel instances. Both reset and step are JIT-compiled.
The entire training loop can be compiled end-to-end when using this
adapter with an on-policy algorithm.
Source code in bordax/environments/utils.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
make_env(env_name, env_config, num_envs=1)
Create a vectorised environment adapter by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_name
|
str
|
Environment identifier with a backend prefix, e.g.
|
required |
env_config
|
Backend-specific config dict. For Gymnax, pass
|
required | |
num_envs
|
int
|
Number of parallel environment instances. |
1
|
Returns:
| Type | Description |
|---|---|
EnvAdapter
|
An |
EnvAdapter
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the prefix is unknown or if no prefix is given. |
Source code in bordax/environments/utils.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |