1
Fork 0

fix: explicit arms length check

This commit is contained in:
Tibo De Peuter 2026-04-15 19:26:33 +02:00
parent 6ed4ad8060
commit 143dbbc710
Signed by: tdpeuter
SSH key fingerprint: SHA256:u/h/LVoqKF1Iz02uOyxe6hcjmoZASCGV2HM0TG9ZMoU
4 changed files with 18 additions and 3 deletions

View file

@ -4,6 +4,7 @@
# Default values are defined in CentralizedConfig dataclass.
# Use this configuration for standard PPO experiments.
name: "centralized"
sensor:
hidden_dims: [64, 64]
activation: "tanh"

View file

@ -4,6 +4,7 @@
# Default values are defined in DecentralizedConfig dataclass.
# Use this configuration for decentralized execution experiments.
name: "decentralized"
sensor:
hidden_dims: [64, 64]
activation: "tanh"

View file

@ -42,10 +42,22 @@ def compute_padding_masks(
Returns:
A dict containing 1D boolean masks and target sizes.
"""
if len(segments_per_arm) != len(reference_segments_per_arm):
raise ValueError(
f"Morphology mismatch: current has {len(segments_per_arm)} arms, "
f"but reference requires {len(reference_segments_per_arm)} arms."
)
mask_1x = []
mask_2x = []
for actual, ref in zip(segments_per_arm, reference_segments_per_arm):
for arm_idx, (actual, ref) in enumerate(zip(segments_per_arm, reference_segments_per_arm)):
if not (0 <= actual <= ref):
raise ValueError(
f"Invalid amputation at arm {arm_idx}: "
f"actual segments ({actual}) must be between 0 and reference ({ref})."
)
# 1x scaling (e.g., contacts: 1 value per segment)
# 1x scaling (e.g., contacts: 1 value per segment)
mask_1x.extend([True] * actual + [False] * (ref - actual))
# 2x scaling (e.g., joints: 2 values per segment)

View file

@ -18,7 +18,8 @@ def test_config_composition_centralized():
structured_cfg = OmegaConf.to_object(OmegaConf.merge(BrittleStarConfig, cfg))
# Basic assertions
assert "CentralizedConfig" in str(type(structured_cfg.architecture))
assert structured_cfg.architecture.name == "centralized"
assert structured_cfg.architecture.propagator is None
assert isinstance(structured_cfg.ppo.learning_rate, float)
assert structured_cfg.ppo.learning_rate > 0
@ -32,7 +33,7 @@ def test_config_composition_decentralized():
structured_cfg = OmegaConf.to_object(OmegaConf.merge(BrittleStarConfig, cfg))
# Basic assertions
assert "DecentralizedConfig" in str(type(structured_cfg.architecture))
assert structured_cfg.architecture.name == "decentralized"
assert isinstance(structured_cfg.ppo.learning_rate, float)
assert structured_cfg.ppo.learning_rate > 0