Unity-Technologies/ml-agents · error · TrainerConfigError
The sampling interval {interval} must contain exactly two va
Error message
The sampling interval {interval} must contain exactly two values. What it means
MultiRangeUniformSamplerSettings validates its `intervals` via an attrs validator requiring every interval to be exactly a two-element [min, max] pair. An interval with any other length cannot be interpreted as a range and raises this error.
Source
Thrown at ml-agents/mlagents/trainers/settings.py:433
@attr.s(auto_attribs=True)
class MultiRangeUniformSettings(ParameterRandomizationSettings):
intervals: List[Tuple[float, float]] = attr.ib()
def __str__(self) -> str:
"""
Helper method to output sampler stats to console.
"""
return f"MultiRangeUniform sampler: intervals={self.intervals}"
@intervals.default
def _intervals_default(self):
return [[0.0, 1.0]]
@intervals.validator
def _check_intervals(self, attribute, value):
for interval in self.intervals:
if len(interval) != 2:
raise TrainerConfigError(
f"The sampling interval {interval} must contain exactly two values."
)
min_value, max_value = interval
if min_value > max_value:
raise TrainerConfigError(
f"Minimum value is greater than maximum value in interval {interval}."
)
def apply(self, key: str, env_channel: EnvironmentParametersChannel) -> None:
"""
Helper method to send sampler settings over EnvironmentParametersChannel
Calls the multirangeuniform sampler type set method.
:param key: environment parameter to be sampled
:param env_channel: The EnvironmentParametersChannel to communicate sampler settings to environment
"""
env_channel.set_multirangeuniform_sampler_parameters(
key, self.intervals, self.seed
)View on GitHub (pinned to 3ecb446f75)
Solutions
- Ensure each interval has exactly two numbers: [min_value, max_value].
- Remove extra elements or split multi-point entries into separate intervals.
- Print/parse the YAML to confirm the intervals structure is a list of 2-element lists.
Example fix
# before intervals: [[0.0, 1.0, 2.0]] # after intervals: [[0.0, 1.0], [1.5, 2.0]]
Defensive patterns
Strategy: validation
Validate before calling
for iv in spec['sampler_parameters']['intervals']:
if len(iv) != 2:
raise ValueError(f'interval {iv} must contain exactly two values') Type guard
def are_valid_intervals(intervals) -> bool:
return isinstance(intervals, list) and all(isinstance(i, (list, tuple)) and len(i) == 2 for i in intervals) Try / catch
try:
sampler = MultiRangeUniformSamplerSettings(**sp)
except TrainerConfigError as e:
print(f'Fix intervals: {e}')
raise Prevention
- Represent intervals strictly as [min, max] pairs
- Lint YAML lists for accidental extra elements
- Keep multi-range definitions in separate interval entries
When it happens
Trigger: Providing intervals like [[0.0, 1.0, 2.0]] or [[1.0]] in a multirangeuniform sampler configuration.
Common situations: Adding a third element (e.g. a weight or step) to an interval, or a YAML list accidentally flattened/nested incorrectly.
Related errors
- Minimum value is greater than maximum value in uniform sampl
- Minimum value is greater than maximum value in interval {int
- Unsupported parameter randomization configuration {d}.
- When using a recurrent network, memory size must be divisibl
- Unsupported reward signal configuration {d}.
AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02).
Data as JSON: /api/errors/0c800b6359446207.
Report an issue: GitHub.