Skip to content
Draft
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
10 changes: 4 additions & 6 deletions whynot/gym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import sys
import warnings

from gym import error
from gym.core import Env
from gym import logger
from gymnasium import error
from gymnasium.core import Env
from gymnasium import logger

from whynot.gym.envs import make, spec, register

__all__ = ["Env", "make", "spec", "register"]
__all__ = ["Env"]
1 change: 0 additions & 1 deletion whynot/gym/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""Environments based on WhyNot simulators."""

from whynot.gym.envs.registration import registry, register, make, spec
from whynot.gym.envs.ode_env import ODEEnvBuilder
28 changes: 0 additions & 28 deletions whynot/gym/envs/registration.py

This file was deleted.

22 changes: 11 additions & 11 deletions whynot/gym/spaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Ensure gym spaces are accessible if you import whynot.gym as gym."""
from gym.spaces.space import Space
from gym.spaces.box import Box
from gym.spaces.discrete import Discrete
from gym.spaces.multi_discrete import MultiDiscrete
from gym.spaces.multi_binary import MultiBinary
from gym.spaces.tuple import Tuple
from gym.spaces.dict import Dict
"""Ensure gymnasium spaces are accessible if you import whynot.gym as gym."""
from gymnasium.spaces.space import Space
from gymnasium.spaces.box import Box
from gymnasium.spaces.discrete import Discrete
from gymnasium.spaces.multi_discrete import MultiDiscrete
from gymnasium.spaces.multi_binary import MultiBinary
from gymnasium.spaces.tuple import Tuple
from gymnasium.spaces.dict import Dict

from gym.spaces.utils import flatdim
from gym.spaces.utils import flatten
from gym.spaces.utils import unflatten
from gymnasium.spaces.utils import flatdim
from gymnasium.spaces.utils import flatten
from gymnasium.spaces.utils import unflatten

__all__ = [
"Space",
Expand Down
2 changes: 1 addition & 1 deletion whynot/gym/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Ensure gym utils are accessible if you import whynot.gym as gym."""
from gym.utils import seeding
from gymnasium.utils import seeding
6 changes: 4 additions & 2 deletions whynot/simulators/credit/environments.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Interactive environment for the credit simulator."""
import copy
import gymnasium

import numpy as np

from whynot.gym import spaces
from whynot.gym.envs import ODEEnvBuilder, register
from whynot.gym.envs import ODEEnvBuilder
from whynot.simulators.credit import (
Config,
Intervention,
Expand Down Expand Up @@ -93,9 +94,10 @@ def build_credit_env(config=None, initial_state=None):
)


register(
gymnasium.register(
id="Credit-v0",
entry_point=build_credit_env,
apply_api_compatibility=True,
max_episode_steps=100,
reward_threshold=0,
)
9 changes: 6 additions & 3 deletions whynot/simulators/hiv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

https://pdfs.semanticscholar.org/c030/127238b1dbad2263fba6b64b5dec7c3ffa20.pdf
"""
import gymnasium
import numpy as np

from whynot.gym import spaces
from whynot.gym.envs import ODEEnvBuilder, register
from whynot.gym.envs import ODEEnvBuilder
from whynot.simulators.hiv import Config, Intervention, simulate, State


Expand Down Expand Up @@ -59,6 +60,8 @@ def observation_space():
reward_fn=get_reward,
)

register(
id="HIV-v0", entry_point=HivEnv, max_episode_steps=400, reward_threshold=1e10,
gymnasium.register(
id="HIV-v0", entry_point=HivEnv, apply_api_compatibility=True, max_episode_steps=400, reward_threshold=1e10,
)

env = gymnasium.make("HIV-v0", apply_api_compatibility=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line I have to add so gymansium understands the environment was defined.
As mentioned in the PR body I'm not sure how to register new environments with the gymnasium API. It's a next step.

7 changes: 5 additions & 2 deletions whynot/simulators/opioid/environments.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Reinforcement learning environments for the opioid epidemic simulator."""
import gymnasium

import numpy as np

from whynot.gym import spaces
from whynot.gym.envs import ODEEnvBuilder, register
from whynot.gym.envs import ODEEnvBuilder
from whynot.simulators.opioid import Config, Intervention, simulate, State


Expand Down Expand Up @@ -58,9 +60,10 @@ def observation_space():
reward_fn=get_reward,
)

register(
gymnasium.register(
id="opioid-v0",
entry_point=OpioidEnv,
apply_api_compatibility=True,
# The simulator starts in 2002 and ends in 2030.
max_episode_steps=28,
reward_threshold=0,
Expand Down
8 changes: 5 additions & 3 deletions whynot/simulators/world3/environments.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Reinforcment learning for world3."""
import gymnasium

from itertools import product

import numpy as np

from whynot.gym import spaces
from whynot.gym.envs import ODEEnvBuilder, register
from whynot.gym.envs import ODEEnvBuilder
from whynot.simulators.world3 import Config, Intervention, simulate, State


Expand Down Expand Up @@ -63,6 +65,6 @@ def observation_space():
reward_fn=get_reward,
)

register(
id="world3-v0", entry_point=World3Env, max_episode_steps=400, reward_threshold=1e5,
gymnasium.register(
id="world3-v0", entry_point=World3Env, apply_api_compatibility=True, max_episode_steps=400, reward_threshold=1e5,
)
8 changes: 5 additions & 3 deletions whynot/simulators/zika/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

https://www.sciencedirect.com/science/article/pii/S2211692316301084#!
"""
import gymnasium

import numpy as np

from whynot.gym import spaces
from whynot.gym.envs import ODEEnvBuilder, register
from whynot.gym.envs import ODEEnvBuilder
from whynot.simulators.zika import Config, Intervention, simulate, State


Expand Down Expand Up @@ -78,6 +80,6 @@ def action_space():
reward_fn=get_reward,
)

register(
id="Zika-v0", entry_point=ZikaEnv, max_episode_steps=200, reward_threshold=1e10,
gymnasium.register(
id="Zika-v0", entry_point=ZikaEnv, apply_api_compatibility=True, max_episode_steps=200, reward_threshold=1e10,
)