Skip to content
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
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand All @@ -49,7 +49,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand All @@ -67,7 +67,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand Down Expand Up @@ -292,7 +292,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}

- name: Install uv
uses: astral-sh/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tensor-runtime-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || format('refs/pull/{0}/merge', github.event.pull_request.number) }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
persist-credentials: false
- name: Install uv
uses: astral-sh/[email protected]
Expand Down
16 changes: 16 additions & 0 deletions docs/sphinx/source/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ PyPI 版本变更与未发布变更;发布日期采用 PyPI 上传日期。完
捕获期间挂起循环垃圾回收器
([#2668](https://github.com/Motphys/UniLab/issues/2668))。

- Pull-request workflows now check out the immutable PR head commit instead of
the ephemeral `refs/pull/<number>/merge` ref, so merging a PR cannot make its
in-flight jobs fail during checkout
([#2669](https://github.com/Motphys/UniLab/pull/2669)).
PR 工作流现在 checkout 不可变的 PR head 提交,不再使用临时的
`refs/pull/<number>/merge` ref,避免 PR 合并导致运行中的任务在 checkout 时失败
([#2669](https://github.com/Motphys/UniLab/pull/2669))。

### Changed / 变更

- Updated the `unisim-core` pin from 2.9.0 to 2.9.1 in the default and ROCm
Expand Down Expand Up @@ -79,6 +87,14 @@ PyPI 版本变更与未发布变更;发布日期采用 PyPI 上传日期。完

### Fixed / 修复

- Non-composed entities now resolve declared joint position limits by joint name
on backends with named range queries, preventing qpos offsets introduced by
non-root free joints from selecting the wrong row or raising an out-of-bounds
error ([#2679](https://github.com/Motphys/UniLab/issues/2679)).
非 composed 实体现在在支持按名称查询限位的后端上按关节名称解析声明的关节位置限位,
避免非 root freejoint 引入的 qpos 偏移导致选取错误行或下标越界
([#2679](https://github.com/Motphys/UniLab/issues/2679))。

- Manager-based MuJoCo and MJWarp scenes now resolve declared sites from authored
models before backend construction, tracking only their dynamic parent bodies
instead of every named body when resolution is available. Scene and physical-entity
Expand Down
10 changes: 10 additions & 0 deletions src/unilab/base/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,16 @@ def _materialize_soft_joint_pos_limits(
result = np.asarray(backend.get_joint_range(names=self._joint_names)).copy()
result.setflags(write=False)
return result
try:
named_ranges = backend.get_joint_range(names=self._joint_names)
except NotImplementedError:
pass
else:
if named_ranges is None:
return None
result = np.asarray(named_ranges).copy()
result.setflags(write=False)
return result
try:
raw_ranges = backend.get_joint_range()
except (AttributeError, NotImplementedError) as exc:
Expand Down
6 changes: 4 additions & 2 deletions tests/base/test_entity_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ def get_default_dof_pos(self) -> np.ndarray:
self._check("default joint position")
return np.arange(5, dtype=np.float32) + 10.0

def get_joint_range(self) -> np.ndarray:
def get_joint_range(self, *, names=None) -> np.ndarray:
self._check("joint position limits")
return self.joint_range
if names is None:
return self.joint_range
return self.joint_range[[self.joint_ids[name] for name in names]]

def get_tracked_body_views(self, body_names, device=None) -> TrackedBodyStateViews:
capability = {
Expand Down
46 changes: 46 additions & 0 deletions tests/base/test_sim_backend_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)

from unilab.assets import ASSETS_ROOT_PATH
from unilab.base.entity import EntityCfg, EntityScene
from unilab.base.scene import SceneCfg

pytest.importorskip("mujoco", reason="mujoco not installed")
Expand Down Expand Up @@ -150,6 +151,51 @@ def test_mujoco_backend_smoke_contract(robot):
assert caps.supports_interval_term(INTERVAL_TERM_BODY_TORQUE)


def test_entity_joint_limits_follow_non_root_freejoint_qpos_offset(tmp_path):
from unilab.base.backend_factory import create_backend

model_file = tmp_path / "free_object_with_hinge.xml"
model_file.write_text(
"""
<mujoco>
<compiler angle="radian"/>
<worldbody>
<body name="robot">
<joint name="slide" type="slide" axis="1 0 0" range="-1 1"/>
<geom size="0.05"/>
</body>
<body name="lid_base" pos="0 0 1">
<freejoint name="object_root"/>
<geom size="0.05"/>
<body name="lid" pos="0.1 0 0">
<joint name="hinge" axis="0 0 1" range="-0.5 0.5"/>
<geom size="0.05"/>
</body>
</body>
</worldbody>
<actuator><position name="slide_ctrl" joint="slide" kp="10"/></actuator>
</mujoco>
""".strip()
)
backend = create_backend(
"mujoco", SceneCfg(model_file=str(model_file)), num_envs=1, sim_dt=SIM_DT
)
np.testing.assert_array_equal(backend.get_joint_dof_pos_indices(["hinge"]), [8])

scene = EntityScene(
{
"robot": EntityCfg(joint_names=("slide",), actuator_names=("slide_ctrl",)),
"object": EntityCfg(root_body_name="lid_base", joint_names=("hinge",)),
},
backend,
)

robot_limits = scene["robot"].data.soft_joint_pos_limits(torch.device("cpu"))
object_limits = scene["object"].data.soft_joint_pos_limits(torch.device("cpu"))
torch.testing.assert_close(robot_limits, torch.tensor([[-1.0, 1.0]]))
torch.testing.assert_close(object_limits, torch.tensor([[-0.5, 0.5]]))


def test_mujoco_interval_root_velocity_kick_is_row_selective_and_refreshes_sensors():
from unisim.backend.mujoco.backend import MuJoCoBackend

Expand Down
5 changes: 3 additions & 2 deletions tests/envs/mdp/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ def get_dof_vel(self) -> np.ndarray:
def get_default_dof_pos(self) -> np.ndarray:
return np.zeros(3)

def get_joint_range(self) -> np.ndarray:
return np.tile([-1.0, 1.0], (3, 1))
def get_joint_range(self, *, names=None) -> np.ndarray:
count = len(names) if names is not None else 3
return np.tile([-1.0, 1.0], (count, 1))

def get_joint_dof_indices(self, names) -> np.ndarray:
table = {"j0": 6, "j1": 7, "j2": 8}
Expand Down
5 changes: 3 additions & 2 deletions tests/envs/mdp/test_joint_position_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ def get_dof_vel(self) -> np.ndarray:
def get_default_dof_pos(self) -> np.ndarray:
return np.asarray([0.1, 0.2, 0.3], dtype=np.float32)

def get_joint_range(self) -> np.ndarray:
return np.tile(np.asarray([[-1.0, 1.0]], dtype=np.float32), (3, 1))
def get_joint_range(self, *, names=None) -> np.ndarray:
count = len(names) if names is not None else 3
return np.tile(np.asarray([[-1.0, 1.0]], dtype=np.float32), (count, 1))

def get_joint_state_qpos_indices(self, names) -> np.ndarray:
return np.asarray([self.joint_index[name] for name in names], dtype=np.int32)
Expand Down
5 changes: 3 additions & 2 deletions tests/envs/mdp/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ def get_dof_vel(self) -> np.ndarray:
def get_default_dof_pos(self) -> np.ndarray:
return np.asarray([0.1, 0.2, 0.3], dtype=np.float32)

def get_joint_range(self) -> np.ndarray:
return np.tile(np.asarray([[-1.0, 1.0]], dtype=np.float32), (3, 1))
def get_joint_range(self, *, names=None) -> np.ndarray:
count = len(names) if names is not None else 3
return np.tile(np.asarray([[-1.0, 1.0]], dtype=np.float32), (count, 1))

def get_body_pos_w(self, ids: np.ndarray) -> np.ndarray:
return self.body_pos[:, ids]
Expand Down
5 changes: 3 additions & 2 deletions tests/envs/test_manager_based_rl_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ def get_state_views(self, fields, device=None) -> dict[str, torch.Tensor]:
views["qvel"] = self.qvel.detach().clone().to(target)
return views

def get_joint_range(self) -> np.ndarray:
return np.array([[-1.0, 1.0]], dtype=np.float32)
def get_joint_range(self, *, names=None) -> np.ndarray:
count = len(names) if names is not None else 1
return np.tile(np.asarray([[-1.0, 1.0]], dtype=np.float32), (count, 1))

def set_state_tensor(self, env_indices, qpos, qvel, randomization=None) -> None:
assert self.materialize_calls == 1
Expand Down
5 changes: 3 additions & 2 deletions tests/managers/test_device_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ def get_dof_vel(self) -> np.ndarray:
def get_default_dof_pos(self) -> np.ndarray:
return np.asarray([0.1, 0.2, 0.3], dtype=np.float32)

def get_joint_range(self) -> np.ndarray:
return np.tile(np.asarray([[-1.0, 1.0]], dtype=np.float32), (3, 1))
def get_joint_range(self, *, names=None) -> np.ndarray:
count = len(names) if names is not None else 3
return np.tile(np.asarray([[-1.0, 1.0]], dtype=np.float32), (count, 1))

def get_root_state_layout(self, root_body_name: str) -> RootStateLayout:
if root_body_name != "base":
Expand Down
11 changes: 11 additions & 0 deletions tests/scripts/test_ci_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ def test_ci_installs_only_scoped_backend_extras() -> None:
if extra.lower() in SHELVED_BACKENDS:
offenders.append(f"{workflow.name}:--extra={extra}")
assert offenders == [], f"CI installs shelved backend extras: {offenders}"


def test_pull_request_workflows_check_out_immutable_head_commits() -> None:
offenders: list[str] = []
for workflow in sorted(WORKFLOWS.glob("*.yml")):
text = workflow.read_text(encoding="utf-8")
if "pull_request:" not in text:
continue
if "refs/pull/" in text or "github.event.pull_request.head.sha" not in text:
offenders.append(workflow.name)
assert offenders == [], f"PR workflows use ephemeral merge refs: {offenders}"
Loading