Skip to content

Commit

Permalink
CI for Mujoco (#1585)
Browse files Browse the repository at this point in the history
* add uv run ruff check to CI

* make tests pass

* add test to CI

* format pyproject tomls

* use alpine image

* use example github actions from uv website

* also check lock file

* persist uv cache

* fix lints
  • Loading branch information
oleflb authored Jan 25, 2025
1 parent a6ca667 commit e33e6be
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 18 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions tools/machine-learning/mujoco/packages/common_types/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class Side(Enum):
LEFT = 0
RIGHT = 1
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,7 +17,6 @@
isometry_from_translation,
rotation_from_axisangle,
)
from walking_engine.walking_types import Side

from .inverse_kinematics import LegJoints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -16,11 +16,6 @@ class Parameters:
foot_offset_right: float


class Side(Enum):
LEFT = 0
RIGHT = 1


@dataclass
class Feet:
support_sole: Pose2
Expand Down
4 changes: 4 additions & 0 deletions tools/machine-learning/mujoco/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies = [
"tensorboard>=2.18.0",
"wandb>=0.19.1",
# Project dependencies
"common_types",
"kinematics",
"nao-env",
"nao-interface",
Expand All @@ -27,6 +28,7 @@ dependencies = [
]

[tool.uv.sources]
common_types = { workspace = true }
kinematics = { workspace = true }
nao_env = { workspace = true }
nao_interface = { workspace = true }
Expand Down Expand Up @@ -98,6 +100,8 @@ ignore = [
"E731",
# any-type
"ANN401",
# flake8-trailing-comma (handled by formatter)
"COM812",
]

[tool.ruff.lint.per-file-ignores]
Expand Down
14 changes: 14 additions & 0 deletions tools/machine-learning/mujoco/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e33e6be

Please sign in to comment.