Physical differential equations wrapped into Gymnasium environments
Project description
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/).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exciting_environments-0.2.4.tar.gz.
File metadata
- Download URL: exciting_environments-0.2.4.tar.gz
- Upload date:
- Size: 81.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75638c9d456746445c73070b3c69d61305136c9b1c62a785d0fbd578bfe83a63
|
|
| MD5 |
d9c5ed5728e1ae16cb05da2f1ab9c56c
|
|
| BLAKE2b-256 |
08688573d018d7eff0607e056bb1609bae45d1ca0ae05a26f903d6f3f54f38b2
|
File details
Details for the file exciting_environments-0.2.4-py3-none-any.whl.
File metadata
- Download URL: exciting_environments-0.2.4-py3-none-any.whl
- Upload date:
- Size: 87.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84f5ad1dffca330897f3b0f576337719984a38fc3acccd50a9ed579c8098ba07
|
|
| MD5 |
096b28feff42005fb3af2cd99198f95b
|
|
| BLAKE2b-256 |
611a2b6a27cb1078f97e8be4ab5c1787680841115d679f51d7e6e54cfc8d450d
|