Skip to main content

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

exciting_environments-0.2.3.tar.gz (81.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exciting_environments-0.2.3-py3-none-any.whl (87.0 kB view details)

Uploaded Python 3

File details

Details for the file exciting_environments-0.2.3.tar.gz.

File metadata

  • Download URL: exciting_environments-0.2.3.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

Hashes for exciting_environments-0.2.3.tar.gz
Algorithm Hash digest
SHA256 a04f52642199b84f3fce11bac2b6c36752c213cf9b8726c264dc45ec45e67ce0
MD5 97a06f9e2b498c72a84157a4c4a61836
BLAKE2b-256 005c310266db56ec69ca82453972e99ca11f527ddad242cee5883644c43cf7a6

See more details on using hashes here.

File details

Details for the file exciting_environments-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for exciting_environments-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 62cdf0c566a6627268a8cfdfe3edd3791bccc695691a8fae9d05f49145615c3b
MD5 ecdcd9f9f1d65b06c8ccd93aa46ef172
BLAKE2b-256 058a05b6255224caff197c0bd25d93bf53aec004bab452832d6e96547b5f0fd8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page