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

Add Beartype as partial replacement of PyRight #1211

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
62 changes: 39 additions & 23 deletions .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,54 @@ permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build-all:
# build-all:
# runs-on: ubuntu-latest
# strategy:
# fail-fast: true
# matrix:
# python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
# numpy-version: ['>=1.21,<2.0', '>=2.0']
# exclude:
# - python-version: '3.8' # numpy>=2.0 requires Python>=3.9
# numpy-version: '>=2.0'
# steps:
# - uses: actions/checkout@v4
# - run: |
# docker build -f bin/all-py.Dockerfile \
# --build-arg PYTHON_VERSION="${{ matrix.python-version }}" \
# --build-arg NUMPY_VERSION="${{ matrix.numpy-version }}" \
# --tag gymnasium-all-docker .
# - name: Run tests
# run: docker run gymnasium-all-docker pytest tests/*
# - name: Run doctests
# if: ${{ matrix.python-version != '3.8' }}
# run: docker run gymnasium-all-docker pytest --doctest-modules gymnasium/
#
# build-necessary:
# runs-on:
# ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - run: |
# docker build -f bin/necessary-py.Dockerfile \
# --build-arg PYTHON_VERSION='3.10' \
# --tag gymnasium-necessary-docker .
# - name: Run tests
# run: |
# docker run gymnasium-necessary-docker pytest tests/test_core.py tests/envs/test_envs.py tests/spaces
#
build-type-testing:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
numpy-version: ['>=1.21,<2.0', '>=2.0']
exclude:
- python-version: '3.8' # numpy>=2.0 requires Python>=3.9
numpy-version: '>=2.0'
steps:
- uses: actions/checkout@v4
- run: |
docker build -f bin/all-py.Dockerfile \
--build-arg PYTHON_VERSION="${{ matrix.python-version }}" \
--build-arg PYTHON_VERSION="3.12" \
pseudo-rnd-thoughts marked this conversation as resolved.
Show resolved Hide resolved
--build-arg NUMPY_VERSION="${{ matrix.numpy-version }}" \
--tag gymnasium-all-docker .
- name: Run tests
run: docker run gymnasium-all-docker pytest tests/*
- name: Run doctests
if: ${{ matrix.python-version != '3.8' }}
run: docker run gymnasium-all-docker pytest --doctest-modules gymnasium/

build-necessary:
runs-on:
ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
docker build -f bin/necessary-py.Dockerfile \
--build-arg PYTHON_VERSION='3.10' \
--tag gymnasium-necessary-docker .
- name: Run tests
run: |
docker run gymnasium-necessary-docker pytest tests/test_core.py tests/envs/test_envs.py tests/spaces
run: docker run gymnasium-all-docker pytest --beartype-packages='gymnasium' tests/*
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-symlinks
- id: destroyed-symlinks
Expand Down Expand Up @@ -35,16 +35,16 @@ repos:
- --show-source
- --statistics
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.18.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
args: ["--py39-plus"]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/python/black
rev: 24.8.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/pydocstyle
Expand Down
8 changes: 4 additions & 4 deletions gymnasium/envs/box2d/bipedal_walker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__credits__ = ["Andrea PIERRÉ"]

import math
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional

import numpy as np

Expand Down Expand Up @@ -179,7 +179,7 @@ def __init__(self, render_mode: Optional[str] = None, hardcore: bool = False):
self.isopen = True

self.world = Box2D.b2World()
self.terrain: List[Box2D.b2Body] = []
self.terrain: list[Box2D.b2Body] = []
self.hull: Optional[Box2D.b2Body] = None

self.prev_shaping = None
Expand Down Expand Up @@ -458,8 +458,8 @@ def reset(
(self.np_random.uniform(-INITIAL_RANDOM, INITIAL_RANDOM), 0), True
)

self.legs: List[Box2D.b2Body] = []
self.joints: List[Box2D.b2RevoluteJoint] = []
self.legs: list[Box2D.b2Body] = []
self.joints: list[Box2D.b2RevoluteJoint] = []
for i in [-1, +1]:
leg = self.world.CreateDynamicBody(
position=(init_x, init_y - LEG_H / 2 - LEG_DOWN),
Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/classic_control/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import math
from typing import Optional, Tuple, Union
from typing import Optional, Union

import numpy as np

Expand Down Expand Up @@ -418,7 +418,7 @@ def __init__(

def step(
self, action: np.ndarray
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, dict]:
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, dict]:
assert self.action_space.contains(
action
), f"{action!r} ({type(action)}) invalid"
Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/classic_control/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Utility functions used for classic control environments.
"""

from typing import Optional, SupportsFloat, Tuple
from typing import Optional, SupportsFloat


def verify_number_and_cast(x: SupportsFloat) -> float:
Expand All @@ -16,7 +16,7 @@ def verify_number_and_cast(x: SupportsFloat) -> float:

def maybe_parse_reset_bounds(
options: Optional[dict], default_low: float, default_high: float
) -> Tuple[float, float]:
) -> tuple[float, float]:
"""
This function can be called during a reset() to customize the sampling
ranges for setting the initial state distributions.
Expand Down
8 changes: 4 additions & 4 deletions gymnasium/envs/mujoco/ant_v5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__credits__ = ["Kallinteris-Andreas"]

from typing import Dict, Tuple, Union
from typing import Union

import numpy as np

Expand Down Expand Up @@ -231,15 +231,15 @@ def __init__(
self,
xml_file: str = "ant.xml",
frame_skip: int = 5,
default_camera_config: Dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
default_camera_config: dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
forward_reward_weight: float = 1,
ctrl_cost_weight: float = 0.5,
contact_cost_weight: float = 5e-4,
healthy_reward: float = 1.0,
main_body: Union[int, str] = 1,
terminate_when_unhealthy: bool = True,
healthy_z_range: Tuple[float, float] = (0.2, 1.0),
contact_force_range: Tuple[float, float] = (-1.0, 1.0),
healthy_z_range: tuple[float, float] = (0.2, 1.0),
contact_force_range: tuple[float, float] = (-1.0, 1.0),
reset_noise_scale: float = 0.1,
exclude_current_positions_from_observation: bool = True,
include_cfrc_ext_in_observation: bool = True,
Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/mujoco/half_cheetah_v5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__credits__ = ["Kallinteris-Andreas", "Rushiv Arora"]

from typing import Dict, Union
from typing import Union

import numpy as np

Expand Down Expand Up @@ -156,7 +156,7 @@ def __init__(
self,
xml_file: str = "half_cheetah.xml",
frame_skip: int = 5,
default_camera_config: Dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
default_camera_config: dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
forward_reward_weight: float = 1.0,
ctrl_cost_weight: float = 0.1,
reset_noise_scale: float = 0.1,
Expand Down
10 changes: 5 additions & 5 deletions gymnasium/envs/mujoco/hopper_v5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__credits__ = ["Kallinteris-Andreas"]

from typing import Dict, Tuple, Union
from typing import Union

import numpy as np

Expand Down Expand Up @@ -166,14 +166,14 @@ def __init__(
self,
xml_file: str = "hopper.xml",
frame_skip: int = 4,
default_camera_config: Dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
default_camera_config: dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
forward_reward_weight: float = 1.0,
ctrl_cost_weight: float = 1e-3,
healthy_reward: float = 1.0,
terminate_when_unhealthy: bool = True,
healthy_state_range: Tuple[float, float] = (-100.0, 100.0),
healthy_z_range: Tuple[float, float] = (0.7, float("inf")),
healthy_angle_range: Tuple[float, float] = (-0.2, 0.2),
healthy_state_range: tuple[float, float] = (-100.0, 100.0),
healthy_z_range: tuple[float, float] = (0.7, float("inf")),
healthy_angle_range: tuple[float, float] = (-0.2, 0.2),
reset_noise_scale: float = 5e-3,
exclude_current_positions_from_observation: bool = True,
**kwargs,
Expand Down
8 changes: 4 additions & 4 deletions gymnasium/envs/mujoco/humanoid_v5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__credits__ = ["Kallinteris-Andreas"]

from typing import Dict, Tuple, Union
from typing import Union

import numpy as np

Expand Down Expand Up @@ -309,14 +309,14 @@ def __init__(
self,
xml_file: str = "humanoid.xml",
frame_skip: int = 5,
default_camera_config: Dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
default_camera_config: dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
forward_reward_weight: float = 1.25,
ctrl_cost_weight: float = 0.1,
contact_cost_weight: float = 5e-7,
contact_cost_range: Tuple[float, float] = (-np.inf, 10.0),
contact_cost_range: tuple[float, float] = (-np.inf, 10.0),
healthy_reward: float = 5.0,
terminate_when_unhealthy: bool = True,
healthy_z_range: Tuple[float, float] = (1.0, 2.0),
healthy_z_range: tuple[float, float] = (1.0, 2.0),
reset_noise_scale: float = 1e-2,
exclude_current_positions_from_observation: bool = True,
include_cinert_in_observation: bool = True,
Expand Down
6 changes: 3 additions & 3 deletions gymnasium/envs/mujoco/humanoidstandup_v5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__credits__ = ["Kallinteris-Andreas"]

from typing import Dict, Tuple, Union
from typing import Union

import numpy as np

Expand Down Expand Up @@ -289,11 +289,11 @@ def __init__(
self,
xml_file: str = "humanoidstandup.xml",
frame_skip: int = 5,
default_camera_config: Dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
default_camera_config: dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
uph_cost_weight: float = 1,
ctrl_cost_weight: float = 0.1,
impact_cost_weight: float = 0.5e-6,
impact_cost_range: Tuple[float, float] = (-np.inf, 10.0),
impact_cost_range: tuple[float, float] = (-np.inf, 10.0),
reset_noise_scale: float = 1e-2,
exclude_current_positions_from_observation: bool = True,
include_cinert_in_observation: bool = True,
Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/mujoco/inverted_double_pendulum_v5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__credits__ = ["Kallinteris-Andreas"]

from typing import Dict, Union
from typing import Union

import numpy as np

Expand Down Expand Up @@ -148,7 +148,7 @@ def __init__(
self,
xml_file: str = "inverted_double_pendulum.xml",
frame_skip: int = 5,
default_camera_config: Dict[str, Union[float, int]] = {},
default_camera_config: dict[str, Union[float, int]] = {},
healthy_reward: float = 10.0,
reset_noise_scale: float = 0.1,
**kwargs,
Expand Down
4 changes: 2 additions & 2 deletions gymnasium/envs/mujoco/inverted_pendulum_v5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__credits__ = ["Kallinteris-Andreas"]

from typing import Dict, Union
from typing import Union

import numpy as np

Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(
self,
xml_file: str = "inverted_pendulum.xml",
frame_skip: int = 2,
default_camera_config: Dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
default_camera_config: dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
reset_noise_scale: float = 0.01,
**kwargs,
):
Expand Down
12 changes: 6 additions & 6 deletions gymnasium/envs/mujoco/mujoco_env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os import path
from typing import Dict, Optional, Tuple, Union
from typing import Optional, Union

import numpy as np
from numpy.typing import NDArray
Expand Down Expand Up @@ -47,9 +47,9 @@ def __init__(
height: int = DEFAULT_SIZE,
camera_id: Optional[int] = None,
camera_name: Optional[str] = None,
default_camera_config: Optional[Dict[str, Union[float, int]]] = None,
default_camera_config: Optional[dict[str, Union[float, int]]] = None,
max_geom: int = 1000,
visual_options: Dict[int, bool] = {},
visual_options: dict[int, bool] = {},
):
"""Base abstract class for mujoco based environments.

Expand Down Expand Up @@ -121,7 +121,7 @@ def _set_action_space(self):

def _initialize_simulation(
self,
) -> Tuple["mujoco.MjModel", "mujoco.MjData"]:
) -> tuple["mujoco.MjModel", "mujoco.MjData"]:
"""
Initialize MuJoCo simulation data structures `mjModel` and `mjData`.
"""
Expand Down Expand Up @@ -215,7 +215,7 @@ def state_vector(self) -> NDArray[np.float64]:
# ----------------------------
def step(
self, action: NDArray[np.float32]
) -> Tuple[NDArray[np.float64], np.float64, bool, bool, Dict[str, np.float64]]:
) -> tuple[NDArray[np.float64], np.float64, bool, bool, dict[str, np.float64]]:
raise NotImplementedError

def reset_model(self) -> NDArray[np.float64]:
Expand All @@ -225,7 +225,7 @@ def reset_model(self) -> NDArray[np.float64]:
"""
raise NotImplementedError

def _get_reset_info(self) -> Dict[str, float]:
def _get_reset_info(self) -> dict[str, float]:
"""Function that generates the `info` that is returned during a `reset()`."""
return {}

Expand Down
Loading
Loading