Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch gym dependency to gymnasium #486

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions brax/envs/wrappers/gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

from brax.envs.base import PipelineEnv
from brax.io import image
import gym
from gym import spaces
from gym.vector import utils

import gymnasium as gym
from gymnasium import spaces
from gymnasium.vector import utils

import jax
import numpy as np

Expand Down Expand Up @@ -72,7 +74,7 @@ def reset(self):
def step(self, action):
self._state, obs, reward, done, info = self._step(self._state, action)
# We return device arrays for pytorch users.
return obs, reward, done, info
return gym.utils.step_api_compatibility.convert_to_terminated_truncated_step_api((obs, reward, done, info))

def seed(self, seed: int = 0):
self._key = jax.random.PRNGKey(seed)
Expand Down Expand Up @@ -129,7 +131,7 @@ def reset(key):
def step(state, action):
state = self._env.step(state, action)
info = {**state.metrics, **state.info}
return state, state.obs, state.reward, state.done, info
return gym.utils.step_api_compatibility.convert_to_terminated_truncated_step_api((state, state.obs, state.reward, state.done, info), is_vector_env=True)

self._step = jax.jit(step, backend=self.backend)

Expand Down
5 changes: 2 additions & 3 deletions brax/v1/envs/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

from brax.v1 import jumpy as jp
from brax.v1.envs import env as brax_env
import dm_env
from dm_env import specs
import flax

import gym
from gym import spaces
from gym.vector import utils

import jax
import jax.numpy as jnp

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"flask_cors",
"flax",
# TODO: remove grpcio and gym after dropping legacy v1 code
"gymnasium",
"grpcio",
"gym",
"jax>=0.4.6",
"jaxlib>=0.4.6",
"jaxopt",
Expand Down