Skip to content

Commit

Permalink
Update to gymnasium (#82)
Browse files Browse the repository at this point in the history
* update install_requires

* §

* fix imports: gym → gymnasium

* fix step function

* fix step

* gym->gymnasium

* §

* fix

* fix

* fix

* fix

* fix

* fix render

* .

* fix all step returns

* Delete build/lib/carl directory

* Delete myenv directory

* Update README.md

Fix documentation link.

* make pre-commit and format

* rename every occurrence of trunched to truncated

* @Arman717

* change trunched to truncated

* Fix gymnasium version with box2d

---------

Co-authored-by: C. Benjamins <75323339+benjamc@users.noreply.github.com>
  • Loading branch information
2 people authored and TheEimer committed Jul 17, 2023
1 parent 7793cd9 commit a9845ec
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion carl/envs/rna/carl_rna_definitions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from gym import spaces
from gymnasium import spaces

DEFAULT_CONTEXT = {
"mutation_threshold": 5,
Expand Down
4 changes: 2 additions & 2 deletions examples/demo_carracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Any
import numpy as np
import gym
import gymnasium as gym
import time
import pygame
from carl.envs.box2d.carl_vehicle_racing import CARLVehicleRacingEnv, VEHICLE_NAMES
Expand Down Expand Up @@ -44,7 +44,7 @@ def register_input():
env.render()
record_video = False
if record_video:
from gym.wrappers.record_video import RecordVideo
from gymnasium.wrappers.record_video import RecordVideo

env = RecordVideo(
env=env, video_folder="/tmp/video-test", name_prefix="CARLVehicleRacing"
Expand Down
26 changes: 15 additions & 11 deletions examples/demo_heuristic_lunarlander.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Union, Optional

from gym.envs.box2d.lunar_lander import heuristic
import gym.envs.box2d.lunar_lander as lunar_lander

from gymnasium.envs.box2d.lunar_lander import heuristic
import gymnasium.envs.box2d.lunar_lander as lunar_lander
from gymnasium.utils.step_api_compatibility import step_api_compatibility
from carl.envs import CARLLunarLanderEnv


Expand All @@ -16,22 +16,26 @@ def demo_heuristic_lander(
"""
Copied from LunarLander
"""
env.seed(seed)

total_reward = 0
steps = 0
env.render()
s = env.reset()
if render:
env.render()
s = env.reset(
seed=seed,
)

while True:
a = heuristic(env, s)
s, r, done, info = env.step(a)

s, r, done, truncated, info = env.step(a)

total_reward += r

if render:
if render and steps % 20 == 0:
still_open = env.render()
if not still_open:
break

if done: # or steps % 20 == 0:
if done or truncated: # or steps % 20 == 0:
# print("observations:", " ".join(["{:+0.2f}".format(x) for x in s]))
print("step {} total_reward {:+0.2f}".format(steps, total_reward))
steps += 1
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read_file(filepath: str) -> str:

extras_require = {
"box2d": [
"gym[box2d]==0.24.1",
"gymnasium[box2d]>=0.27.1",
],
"brax": [
"brax>=0.0.10,<=0.0.16",
Expand Down Expand Up @@ -77,7 +77,7 @@ def read_file(filepath: str) -> str:
include_package_data=True,
python_requires=">=3.9",
install_requires=[
"gym==0.24.1",
"gymnasium>=0.27.1",
"scipy>=1.7.0",
"ConfigArgParse>=1.5.1",
"numpy>=1.19.5",
Expand Down

0 comments on commit a9845ec

Please sign in to comment.