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

Properly hide additional requirements between separate imports #323

Merged
merged 3 commits into from
Feb 14, 2023
Merged
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
3 changes: 1 addition & 2 deletions gymnasium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
pprint_registry,
make_vec,
)
from gymnasium import envs, spaces, utils, vector, wrappers, error, logger, experimental
from gymnasium import envs, spaces, utils, vector, wrappers, error, logger


__all__ = [
Expand All @@ -43,7 +43,6 @@
"wrappers",
"error",
"logger",
"experimental",
]
__version__ = "0.27.1"

Expand Down
3 changes: 2 additions & 1 deletion gymnasium/envs/classic_control/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from gymnasium import logger, spaces
from gymnasium.envs.classic_control import utils
from gymnasium.error import DependencyNotInstalled
from gymnasium.experimental.vector import VectorEnv
from gymnasium.vector.utils import batch_space


Expand Down Expand Up @@ -315,7 +316,7 @@ def close(self):
self.isopen = False


class CartPoleVectorEnv(gym.experimental.VectorEnv):
class CartPoleVectorEnv(VectorEnv):
metadata = {
"render_modes": ["human", "rgb_array"],
"render_fps": 50,
Expand Down
10 changes: 5 additions & 5 deletions gymnasium/envs/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from dataclasses import dataclass, field
from typing import Any, Callable, Iterable, Sequence

import gymnasium as gym
from gymnasium import Env, Wrapper, error, logger
from gymnasium.experimental.vector import AsyncVectorEnv, SyncVectorEnv, VectorEnv
from gymnasium.wrappers import (
AutoResetWrapper,
HumanRendering,
Expand Down Expand Up @@ -63,7 +63,7 @@ def __call__(self, **kwargs: Any) -> Env:
class VectorEnvCreator(Protocol):
"""Function type expected for an environment."""

def __call__(self, **kwargs: Any) -> gym.experimental.VectorEnv:
def __call__(self, **kwargs: Any) -> VectorEnv:
...


Expand Down Expand Up @@ -695,7 +695,7 @@ def make_vec(
vector_kwargs: dict[str, Any] | None = None,
wrappers: Sequence[Callable[[Env], Wrapper]] | None = None,
**kwargs,
) -> gym.experimental.VectorEnv:
) -> VectorEnv:
"""Create a vector environment according to the given ID.

Note:
Expand Down Expand Up @@ -778,12 +778,12 @@ def _create_env():
return _env

if vectorization_mode == "sync":
env = gym.experimental.SyncVectorEnv(
env = SyncVectorEnv(
env_fns=[_create_env for _ in range(num_envs)],
**vector_kwargs,
)
elif vectorization_mode == "async":
env = gym.experimental.AsyncVectorEnv(
env = AsyncVectorEnv(
env_fns=[_create_env for _ in range(num_envs)],
**vector_kwargs,
)
Expand Down
5 changes: 1 addition & 4 deletions gymnasium/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Root __init__ of the gym experimental wrappers."""


from gymnasium.experimental import functional, wrappers
from gymnasium.experimental import functional
from gymnasium.experimental.functional import FuncEnv
from gymnasium.experimental.vector.async_vector_env import AsyncVectorEnv
from gymnasium.experimental.vector.sync_vector_env import SyncVectorEnv
Expand All @@ -12,12 +12,9 @@
# Functional
"FuncEnv",
"functional",
# Wrappers
"wrappers",
# Vector
"VectorEnv",
"VectorWrapper",
"SyncVectorEnv",
"AsyncVectorEnv",
# "vector",
]
2 changes: 1 addition & 1 deletion gymnasium/experimental/functional_jax_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import gymnasium as gym
from gymnasium.envs.registration import EnvSpec
from gymnasium.experimental.functional import ActType, FuncEnv, StateType
from gymnasium.experimental.wrappers.jax_to_numpy import jax_to_numpy
from gymnasium.experimental.wrappers.conversion.jax_to_numpy import jax_to_numpy
from gymnasium.utils import seeding
from gymnasium.vector.utils import batch_space

Expand Down
7 changes: 0 additions & 7 deletions gymnasium/experimental/wrappers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
LambdaRewardV0,
NormalizeRewardV0,
)
from gymnasium.experimental.wrappers.jax_to_numpy import JaxToNumpyV0
from gymnasium.experimental.wrappers.jax_to_torch import JaxToTorchV0
from gymnasium.experimental.wrappers.numpy_to_torch import NumpyToTorchV0
from gymnasium.experimental.wrappers.stateful_action import StickyActionV0
from gymnasium.experimental.wrappers.stateful_observation import (
TimeAwareObservationV0,
Expand Down Expand Up @@ -85,10 +82,6 @@
"RenderCollectionV0",
"RecordVideoV0",
"HumanRenderingV0",
# --- Data Conversion ---
"JaxToNumpyV0",
"JaxToTorchV0",
"NumpyToTorchV0",
# --- Vector ---
"VectorRecordEpisodeStatistics",
"VectorListInfo",
Expand Down
1 change: 1 addition & 0 deletions gymnasium/experimental/wrappers/conversion/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""This is deliberately empty to avoid introducing redundant imports -- import each submodule individually."""
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from gymnasium import Env, Wrapper
from gymnasium.core import RenderFrame, WrapperActType, WrapperObsType
from gymnasium.error import DependencyNotInstalled
from gymnasium.experimental.wrappers.jax_to_numpy import jax_to_numpy
from gymnasium.experimental.wrappers.conversion.jax_to_numpy import jax_to_numpy


try:
Expand Down
7 changes: 5 additions & 2 deletions tests/experimental/wrappers/test_jax_to_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import numpy as np
import pytest

from gymnasium.experimental.wrappers import JaxToNumpyV0
from gymnasium.experimental.wrappers.jax_to_numpy import jax_to_numpy, numpy_to_jax
from gymnasium.experimental.wrappers.conversion.jax_to_numpy import (
JaxToNumpyV0,
jax_to_numpy,
numpy_to_jax,
)
from gymnasium.utils.env_checker import data_equivalence
from tests.testing_env import GenericTestEnv

Expand Down
7 changes: 5 additions & 2 deletions tests/experimental/wrappers/test_jax_to_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import pytest
import torch

from gymnasium.experimental.wrappers import JaxToTorchV0
from gymnasium.experimental.wrappers.jax_to_torch import jax_to_torch, torch_to_jax
from gymnasium.experimental.wrappers.conversion.jax_to_torch import (
JaxToTorchV0,
jax_to_torch,
torch_to_jax,
)
from tests.testing_env import GenericTestEnv


Expand Down