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
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
"""Tests for CurriculumManager."""
|
|
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
import torch
|
|
|
|
from mjlab.managers.curriculum_manager import CurriculumManager, CurriculumTermCfg
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_env():
|
|
env = Mock()
|
|
env.num_envs = 2
|
|
return env
|
|
|
|
|
|
def test_get_active_iterable_terms_handles_dict_and_scalar_state(mock_env):
|
|
"""Dict- and scalar-shaped curriculum states both yield flat value lists.
|
|
|
|
Regression: the dict branch previously indexed `terms` (a list) by term
|
|
name, raising TypeError. Only observable through callers that invoke
|
|
get_active_iterable_terms, which no in-tree caller currently does.
|
|
"""
|
|
|
|
def dict_state_func(env, env_ids):
|
|
return {"a": torch.tensor(1.5), "b": 2.0}
|
|
|
|
def scalar_state_func(env, env_ids):
|
|
return torch.tensor(7.0)
|
|
|
|
cfg = {
|
|
"dict_term": CurriculumTermCfg(func=dict_state_func, params={}),
|
|
"scalar_term": CurriculumTermCfg(func=scalar_state_func, params={}),
|
|
}
|
|
manager = CurriculumManager(cfg, mock_env)
|
|
manager.compute()
|
|
|
|
terms = dict(manager.get_active_iterable_terms(0))
|
|
assert terms["dict_term"] == [1.5, 2.0]
|
|
assert terms["scalar_term"] == [7.0]
|