Some checks failed
nightly / Test against latest dependencies (py3.10) (push) Has been cancelled
nightly / Test against latest dependencies (py3.13) (push) Has been cancelled
tests / tests (3.13, locked) (push) Has been cancelled
tests / tests (3.13, unlocked) (push) Has been cancelled
tests / pyright (3.10) (push) Has been cancelled
tests / lint-format (push) Has been cancelled
tests / tests (3.10, locked) (push) Has been cancelled
tests / tests (3.11, locked) (push) Has been cancelled
tests / tests (3.12, locked) (push) Has been cancelled
tests / pyright (3.11) (push) Has been cancelled
tests / pyright (3.12) (push) Has been cancelled
tests / pyright (3.13) (push) Has been cancelled
tests / ty-check (3.10) (push) Has been cancelled
tests / ty-check (3.11) (push) Has been cancelled
tests / ty-check (3.12) (push) Has been cancelled
tests / ty-check (3.13) (push) Has been cancelled
tests / stubs (push) Has been cancelled
tests / smoke-test (push) Has been cancelled
Docker / check_paths (push) Has been cancelled
docs / build (push) Has been cancelled
Docker / build (push) Has been cancelled
Upstream: https://github.com/michaelgillett/mjlab Upstream-Commit: c19f713c415a699a79d71cd96aa13c3104a05047 Upstream-Branch: main
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
"""Tests for ObservationManager behavior."""
|
|
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
import torch
|
|
from conftest import get_test_device
|
|
|
|
from mjlab.managers.observation_manager import (
|
|
ObservationGroupCfg,
|
|
ObservationManager,
|
|
ObservationTermCfg,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_env():
|
|
env = Mock()
|
|
env.num_envs = 4
|
|
env.device = get_test_device()
|
|
env.step_dt = 0.02
|
|
return env
|
|
|
|
|
|
def _dummy_term(mock_env):
|
|
def func(_env, **_kwargs):
|
|
return torch.zeros(mock_env.num_envs, 3, device=mock_env.device)
|
|
|
|
return ObservationTermCfg(func=func)
|
|
|
|
|
|
def test_empty_terms_dict_skipped(mock_env):
|
|
"""A group declared with no terms is skipped rather than raising."""
|
|
cfg = {"actor": ObservationGroupCfg(terms={})}
|
|
mgr = ObservationManager(cfg, mock_env)
|
|
|
|
assert "actor" not in mgr.active_terms
|
|
assert "actor" not in mgr.group_obs_dim
|
|
|
|
|
|
def test_all_terms_none_skipped(mock_env):
|
|
"""A group whose every term is None is skipped rather than raising."""
|
|
cfg = {
|
|
"actor": ObservationGroupCfg(
|
|
terms={"a": None, "b": None}, # type: ignore[dict-item]
|
|
),
|
|
}
|
|
mgr = ObservationManager(cfg, mock_env)
|
|
|
|
assert "actor" not in mgr.active_terms
|
|
assert "actor" not in mgr.group_obs_dim
|
|
|
|
|
|
def test_empty_group_skipped_alongside_active_group(mock_env):
|
|
"""Active groups coexist with empty ones; only the empty group is dropped."""
|
|
cfg = {
|
|
"actor": ObservationGroupCfg(terms={"a": _dummy_term(mock_env)}),
|
|
"critic": ObservationGroupCfg(terms={}),
|
|
}
|
|
mgr = ObservationManager(cfg, mock_env)
|
|
|
|
assert "actor" in mgr.active_terms
|
|
assert "critic" not in mgr.active_terms
|