exciting-environments
Overview
The exciting-environments package is a toolbox for the simulation of physical differential equations wrapped into Gymnasium inspired environments using Jax. Due to the just-in-time compilation native to JAX, this type of implementation offers great advantages in terms of simulation speed.
Getting Started
A basic routine is as simple as:
import jax.numpy as jnp
import exciting_environments as excenvs
from exciting_environments.utils import MinMaxNormalization
env = excenvs.make(
"Pendulum-v0",
batch_size=5,
action_normalizations={"torque": MinMaxNormalization(min=-15,max=15)},
tau=2e-2
)
obs, state = env.vmap_reset()
actions = jnp.linspace(start=-1, stop=1, num=1000)[None, :, None]
actions = actions.repeat(env.batch_size, axis=0)
observations = []
observations.append(obs)
for idx in range(actions.shape[1]):
obs, state = env.vmap_step(
state, actions[:, idx, :]
)
observations.append(obs)
observations = jnp.stack(observations, axis=1)
print("actions shape:", actions.shape)
print("observations shape:", observations.shape)
which produces $5$ identical trajectories in parallel:
alternatively, simulate full trajectories:
import jax.numpy as jnp
import exciting_environments as excenvs
from exciting_environments.utils import MinMaxNormalization
import diffrax
env = excenvs.make(
"Pendulum-v0",
solver=diffrax.Tsit5(),
batch_size=5,
action_normalizations={"torque": MinMaxNormalization(min=-15,max=15)},
tau=2e-2
)
obs, state = env.vmap_reset()
actions = jnp.linspace(start=-1, stop=1, num=2000)[None, :, None]
actions = actions.repeat(env.batch_size, axis=0)
observations, states, last_state = env.vmap_sim_ahead(
init_state=state,
actions=actions,
obs_stepsize=env.tau,
action_stepsize=env.tau
)
print("actions shape:", actions.shape)
print("observations shape:", observations.shape)
which produces $5$ identical trajectories in parallel as well:
Note that in this case the Tsit5 ODE solver instead of the default explicit Euler is used. All solvers used here are from the diffrax library (https://docs.kidger.site/diffrax/).
Metadata
Release files for exciting-environments 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| exciting_environments-0.2.4.tar.gz | 81.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| exciting_environments-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 168.8 kB
Release files / exciting_environments-0.2.4.tar.gz
| Download URL | exciting_environments-0.2.4.tar.gz |
|---|---|
| Size | 81.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75638c9d456746445c73070b3c69d61305136c9b1c62a785d0fbd578bfe83a63
|
|
BLAKE2b-256 checksum How to use checksums |
08688573d018d7eff0607e056bb1609bae45d1ca0ae05a26f903d6f3f54f38b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / exciting_environments-0.2.4-py3-none-any.whl
| Download URL | exciting_environments-0.2.4-py3-none-any.whl |
|---|---|
| Size | 87.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84f5ad1dffca330897f3b0f576337719984a38fc3acccd50a9ed579c8098ba07
|
|
BLAKE2b-256 checksum How to use checksums |
611a2b6a27cb1078f97e8be4ab5c1787680841115d679f51d7e6e54cfc8d450d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|