Skip to content
Open
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
4 changes: 4 additions & 0 deletions python/mujoco/sysid/_src/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def _resolve_signals(
)

canon_name, sig_type, width = resolved
if canon_name in result:
raise ValueError(f"Duplicate signal name '{canon_name}'.")
result[canon_name] = (sig_type, np.arange(idx, idx + width))
idx += width

Expand Down Expand Up @@ -343,6 +345,8 @@ def from_custom_map(
f"Signal '{name}' must have positive width, got {width}."
)

if name in signal_mapping_dict:
raise ValueError(f"Duplicate signal name '{name}'.")
indices = np.arange(current_index, current_index + width)
signal_mapping_dict[name] = (sig_type, indices)
current_index += width
Expand Down
13 changes: 13 additions & 0 deletions python/mujoco/sysid/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ def test_from_model_controls_explicit_names():
assert ts.signal_mapping is not None
assert "m1_ctrl" in ts.signal_mapping

with pytest.raises(ValueError, match="Duplicate signal name"):
TimeSeries.from_control_names(
times, np.zeros((10, 2)), model, names=["m1", "m1_ctrl"]
)

with pytest.raises(ValueError, match="Could not resolve signal"):
TimeSeries.from_control_names(times, data, model, names=["invalid"])

Expand Down Expand Up @@ -326,6 +331,14 @@ def test_from_model_state_resolution():
assert "j2_qpos" in ts.signal_mapping


def test_duplicate_custom_signal_names():
"""Duplicated names must not silently discard a data column."""
with pytest.raises(ValueError, match="Duplicate signal name"):
TimeSeries.from_custom_map(
np.array([0.0, 1.0]), np.zeros((2, 2)), ["a", "a"]
)


def test_from_custom():
"""Custom signal definitions (name strings and dimension tuples) are mapped correctly."""
times = np.linspace(0, 1, 10)
Expand Down
Loading