Skip to main content

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/).

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.4.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.4-py3-none-any.whl (87.0 kB view details)

Uploaded Python 3

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

Hashes for exciting_environments-0.2.4.tar.gz
Algorithm Hash digest
SHA256 75638c9d456746445c73070b3c69d61305136c9b1c62a785d0fbd578bfe83a63
MD5 d9c5ed5728e1ae16cb05da2f1ab9c56c
BLAKE2b-256 08688573d018d7eff0607e056bb1609bae45d1ca0ae05a26f903d6f3f54f38b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for exciting_environments-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 84f5ad1dffca330897f3b0f576337719984a38fc3acccd50a9ed579c8098ba07
MD5 096b28feff42005fb3af2cd99198f95b
BLAKE2b-256 611a2b6a27cb1078f97e8be4ab5c1787680841115d679f51d7e6e54cfc8d450d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 files

0.2.3

2 files

0.2.1

2 files

0.1.1

2 files

Supported by

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