diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 28dee0278e..79119c9ff5 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -170,3 +170,107 @@ jobs: run: pip install mkdocs-material - name: Build docs run: mkdocs build --strict + + check-mujoco: + name: Check Mujoco + runs-on: + - self-hosted + - v3 + container: + image: ghcr.io/hulks/hulk-ci:1.81.0 + options: --user=1000:1000 + defaults: + run: + working-directory: tools/machine-learning/mujoco + shell: bash + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + version: "0.5.21" + enable-cache: true + cache-local-path: "/__w/hulk/.uv-cache" + - name: Check + run: | + uv run ruff check --no-fix + + test-mujoco: + name: Test Mujoco + runs-on: + - self-hosted + - v3 + container: + image: ghcr.io/hulks/hulk-ci:1.81.0 + options: --user=1000:1000 + defaults: + run: + working-directory: tools/machine-learning/mujoco + shell: bash + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + version: "0.5.21" + enable-cache: true + cache-local-path: "/__w/hulk/.uv-cache" + - name: Test + run: | + uv run pytest + + format-mujoco: + name: Format Mujoco + runs-on: + - self-hosted + - v3 + container: + image: ghcr.io/hulks/hulk-ci:1.81.0 + options: --user=1000:1000 + defaults: + run: + working-directory: tools/machine-learning/mujoco + shell: bash + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + version: "0.5.21" + enable-cache: true + cache-local-path: "/__w/hulk/.uv-cache" + - name: Format + run: | + uv run ruff format --check + + check-mujoco-lock: + name: Check Mujoco uv.lock + runs-on: + - self-hosted + - v3 + container: + image: ghcr.io/hulks/hulk-ci:1.81.0 + options: --user=1000:1000 + defaults: + run: + working-directory: tools/machine-learning/mujoco + shell: bash + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + version: "0.5.21" + enable-cache: true + cache-local-path: "/__w/hulk/.uv-cache" + - name: Check Lockfile + run: | + uv sync --locked diff --git a/tools/machine-learning/mujoco/packages/common_types/pyproject.toml b/tools/machine-learning/mujoco/packages/common_types/pyproject.toml new file mode 100644 index 0000000000..01ccaae709 --- /dev/null +++ b/tools/machine-learning/mujoco/packages/common_types/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "common_types" +version = "0.1.0" +description = "Add your description here" +requires-python = ">=3.13" +dependencies = [] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/tools/machine-learning/mujoco/packages/common_types/src/common_types/__init__.py b/tools/machine-learning/mujoco/packages/common_types/src/common_types/__init__.py new file mode 100644 index 0000000000..23a5fb80db --- /dev/null +++ b/tools/machine-learning/mujoco/packages/common_types/src/common_types/__init__.py @@ -0,0 +1,6 @@ +from enum import Enum + + +class Side(Enum): + LEFT = 0 + RIGHT = 1 diff --git a/tools/machine-learning/mujoco/packages/kinematics/pyproject.toml b/tools/machine-learning/mujoco/packages/kinematics/pyproject.toml index db1d4c7338..e44bc171f4 100644 --- a/tools/machine-learning/mujoco/packages/kinematics/pyproject.toml +++ b/tools/machine-learning/mujoco/packages/kinematics/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "Add your description here" requires-python = ">=3.10" -dependencies = ["numpy>=1.2", "robot-dimensions", "transforms"] +dependencies = ["common-types", "numpy>=1.2", "robot-dimensions", "transforms"] [build-system] requires = ["hatchling"] diff --git a/tools/machine-learning/mujoco/packages/kinematics/src/kinematics/forward_kinematics.py b/tools/machine-learning/mujoco/packages/kinematics/src/kinematics/forward_kinematics.py index 3f33d0c77f..566a584278 100644 --- a/tools/machine-learning/mujoco/packages/kinematics/src/kinematics/forward_kinematics.py +++ b/tools/machine-learning/mujoco/packages/kinematics/src/kinematics/forward_kinematics.py @@ -3,6 +3,7 @@ from dataclasses import dataclass import numpy as np +from common_types import Side from numpy.typing import NDArray from robot_dimensions import ( ANKLE_TO_SOLE, @@ -16,7 +17,6 @@ isometry_from_translation, rotation_from_axisangle, ) -from walking_engine.walking_types import Side from .inverse_kinematics import LegJoints diff --git a/tools/machine-learning/mujoco/packages/kinematics/tests/test_inverse_kinematics.py b/tools/machine-learning/mujoco/packages/kinematics/tests/test_inverse_kinematics.py index 20193243ec..416fa8b3d4 100644 --- a/tools/machine-learning/mujoco/packages/kinematics/tests/test_inverse_kinematics.py +++ b/tools/machine-learning/mujoco/packages/kinematics/tests/test_inverse_kinematics.py @@ -19,18 +19,18 @@ def test_fuzz() -> None: left_leg = LegJoints(**frame["joints"]["left_leg"]) right_leg = LegJoints(**frame["joints"]["right_leg"]) - computed_left_leg, computed_right_leg = leg_angles( + lower_body_joints = leg_angles( left_foot, right_foot, ) np.testing.assert_allclose( - computed_left_leg.to_numpy(), + lower_body_joints.left.to_numpy(), left_leg.to_numpy(), atol=1e-4, ) np.testing.assert_allclose( - computed_right_leg.to_numpy(), + lower_body_joints.right.to_numpy(), right_leg.to_numpy(), atol=1e-4, ) diff --git a/tools/machine-learning/mujoco/packages/transforms/tests/test_transforms.py b/tools/machine-learning/mujoco/packages/transforms/tests/test_transforms.py index 8708b49459..d195224864 100644 --- a/tools/machine-learning/mujoco/packages/transforms/tests/test_transforms.py +++ b/tools/machine-learning/mujoco/packages/transforms/tests/test_transforms.py @@ -1,6 +1,6 @@ import numpy as np from transforms import ( - isometry_from_rotation, + isometry_from_euler, isometry_from_translation, rotation_from_isometry, translation_from_isometry, @@ -9,7 +9,7 @@ def test_rotation_from_euler() -> None: vector = np.array([1.0, 0.0, 0.0, 0.0]) - rotation = isometry_from_rotation(0.0, 0.0, np.pi / 2) + rotation = isometry_from_euler(0.0, 0.0, np.pi / 2) np.testing.assert_allclose( rotation @ vector, @@ -38,9 +38,8 @@ def test_translation_from_vector() -> None: def test_isometry_from_parts() -> None: position = isometry_from_translation(np.array([1.0, -1.0, 1.0])) - rotation = isometry_from_rotation(0.0, 0.0, np.pi / 2) + rotation = isometry_from_euler(0.0, 0.0, np.pi / 2) - print(position) pose = position @ rotation np.testing.assert_allclose( @@ -50,7 +49,7 @@ def test_isometry_from_parts() -> None: ) translation = isometry_from_translation(np.array([1.0, 2.0, 3.0])) - rotation = isometry_from_rotation(0.0, 0.0, np.pi / 2) + rotation = isometry_from_euler(0.0, 0.0, np.pi / 2) transform = translation @ rotation result = transform @ pose @@ -65,6 +64,6 @@ def test_isometry_from_parts() -> None: ) np.testing.assert_allclose( result_rotation, - rotation_from_isometry(isometry_from_rotation(0.0, 0.0, np.pi)), + rotation_from_isometry(isometry_from_euler(0.0, 0.0, np.pi)), atol=1e-11, ) diff --git a/tools/machine-learning/mujoco/packages/walking_engine/pyproject.toml b/tools/machine-learning/mujoco/packages/walking_engine/pyproject.toml index f3539315e4..87e96a2170 100644 --- a/tools/machine-learning/mujoco/packages/walking_engine/pyproject.toml +++ b/tools/machine-learning/mujoco/packages/walking_engine/pyproject.toml @@ -3,7 +3,12 @@ name = "walking-engine" version = "0.1.0" description = "Add your description here" requires-python = ">=3.10" -dependencies = ["numpy>=1.2.0", "robot-dimensions"] +dependencies = [ + "common-types", + "kinematics", + "numpy>=1.2.0", + "robot-dimensions", +] [build-system] requires = ["hatchling"] diff --git a/tools/machine-learning/mujoco/packages/walking_engine/src/walking_engine/walking_types.py b/tools/machine-learning/mujoco/packages/walking_engine/src/walking_engine/walking_types.py index a500bed1a8..bca348f4a2 100644 --- a/tools/machine-learning/mujoco/packages/walking_engine/src/walking_engine/walking_types.py +++ b/tools/machine-learning/mujoco/packages/walking_engine/src/walking_engine/walking_types.py @@ -1,7 +1,7 @@ from dataclasses import dataclass -from enum import Enum from typing import Self +from common_types import Side from transforms import Pose2 @@ -16,11 +16,6 @@ class Parameters: foot_offset_right: float -class Side(Enum): - LEFT = 0 - RIGHT = 1 - - @dataclass class Feet: support_sole: Pose2 diff --git a/tools/machine-learning/mujoco/pyproject.toml b/tools/machine-learning/mujoco/pyproject.toml index 2172b73d0d..6dcd558828 100644 --- a/tools/machine-learning/mujoco/pyproject.toml +++ b/tools/machine-learning/mujoco/pyproject.toml @@ -16,6 +16,7 @@ dependencies = [ "tensorboard>=2.18.0", "wandb>=0.19.1", # Project dependencies + "common_types", "kinematics", "nao-env", "nao-interface", @@ -27,6 +28,7 @@ dependencies = [ ] [tool.uv.sources] +common_types = { workspace = true } kinematics = { workspace = true } nao_env = { workspace = true } nao_interface = { workspace = true } @@ -98,6 +100,8 @@ ignore = [ "E731", # any-type "ANN401", + # flake8-trailing-comma (handled by formatter) + "COM812", ] [tool.ruff.lint.per-file-ignores] diff --git a/tools/machine-learning/mujoco/uv.lock b/tools/machine-learning/mujoco/uv.lock index 5205bcde5f..ba8802f7e9 100644 --- a/tools/machine-learning/mujoco/uv.lock +++ b/tools/machine-learning/mujoco/uv.lock @@ -11,6 +11,7 @@ resolution-markers = [ [manifest] members = [ + "common-types", "kinematics", "mujoco-env", "nao-env", @@ -125,6 +126,11 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335 }, ] +[[package]] +name = "common-types" +version = "0.1.0" +source = { editable = "packages/common_types" } + [[package]] name = "contourpy" version = "1.3.1" @@ -463,6 +469,7 @@ name = "kinematics" version = "0.1.0" source = { editable = "packages/kinematics" } dependencies = [ + { name = "common-types", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "numpy", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "robot-dimensions", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "transforms", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, @@ -470,6 +477,7 @@ dependencies = [ [package.metadata] requires-dist = [ + { name = "common-types", editable = "packages/common_types" }, { name = "numpy", specifier = ">=1.2" }, { name = "robot-dimensions", editable = "packages/robot_dimensions" }, { name = "transforms", editable = "packages/transforms" }, @@ -699,6 +707,7 @@ version = "0.1.0" source = { virtual = "." } dependencies = [ { name = "click", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, + { name = "common-types", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "gymnasium", extra = ["mujoco"], marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "kinematics", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "mediapy", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, @@ -728,6 +737,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "click", specifier = ">=8.1.7" }, + { name = "common-types", editable = "packages/common_types" }, { name = "gymnasium", extras = ["mujoco"], specifier = ">=1.0.0" }, { name = "kinematics", editable = "packages/kinematics" }, { name = "mediapy", specifier = ">=1.2.2" }, @@ -1634,12 +1644,16 @@ name = "walking-engine" version = "0.1.0" source = { editable = "packages/walking_engine" } dependencies = [ + { name = "common-types", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, + { name = "kinematics", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "numpy", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, { name = "robot-dimensions", marker = "(platform_machine != 'aarch64' and python_full_version >= '3.13') or (platform_system != 'Linux' and python_full_version >= '3.13') or platform_system == 'Darwin' or (platform_machine == 'aarch64' and platform_system == 'Linux')" }, ] [package.metadata] requires-dist = [ + { name = "common-types", editable = "packages/common_types" }, + { name = "kinematics", editable = "packages/kinematics" }, { name = "numpy", specifier = ">=1.2.0" }, { name = "robot-dimensions", editable = "packages/robot_dimensions" }, ]