{"record":{"id":"0655a99b9bcc4e49","repo":"Unity-Technologies/ml-agents","slug":"minimum-value-is-greater-than-maximum-value-in-uni","errorCode":null,"errorMessage":"Minimum value is greater than maximum value in uniform sampler.","messagePattern":"Minimum value is greater than maximum value in uniform sampler\\.","errorType":"validation","errorClass":"TrainerConfigError","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/settings.py","lineNumber":376,"sourceCode":"@attr.s(auto_attribs=True)\nclass UniformSettings(ParameterRandomizationSettings):\n    min_value: float = attr.ib()\n    max_value: float = 1.0\n\n    def __str__(self) -> str:\n        \"\"\"\n        Helper method to output sampler stats to console.\n        \"\"\"\n        return f\"Uniform sampler: min={self.min_value}, max={self.max_value}\"\n\n    @min_value.default\n    def _min_value_default(self):\n        return 0.0\n\n    @min_value.validator\n    def _check_min_value(self, attribute, value):\n        if self.min_value > self.max_value:\n            raise TrainerConfigError(\n                \"Minimum value is greater than maximum value in uniform sampler.\"\n            )\n\n    def apply(self, key: str, env_channel: EnvironmentParametersChannel) -> None:\n        \"\"\"\n        Helper method to send sampler settings over EnvironmentParametersChannel\n        Calls the uniform sampler type set method.\n        :param key: environment parameter to be sampled\n        :param env_channel: The EnvironmentParametersChannel to communicate sampler settings to environment\n        \"\"\"\n        env_channel.set_uniform_sampler_parameters(\n            key, self.min_value, self.max_value, self.seed\n        )\n\n\n@attr.s(auto_attribs=True)\nclass GaussianSettings(ParameterRandomizationSettings):\n    mean: float = 1.0","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/settings.py#L358-L394","documentation":"UniformSamplerSettings is validated by an attrs validator that rejects configurations where min_value exceeds max_value, since a uniform distribution over an inverted range is undefined. The check runs whenever the settings object is constructed from the YAML config.","triggerScenarios":"Configuring a uniform sampler with `min_value` larger than `max_value`, e.g. {min_value: 5.0, max_value: 1.0}, in environment_parameters randomization.","commonSituations":"Swapping the two values when hand-editing, or changing max_value downward without updating min_value.","solutions":["Swap min_value and max_value so min <= max.","Lower min_value or raise max_value to restore a valid range.","Add a pre-load config check that asserts min_value <= max_value for every uniform sampler."],"exampleFix":"# before\nsampler_parameters:\n  min_value: 5.0\n  max_value: 1.0\n\n# after\nsampler_parameters:\n  min_value: 1.0\n  max_value: 5.0","handlingStrategy":"validation","validationCode":"sp = spec['sampler_parameters']\nif sp['min_value'] > sp['max_value']:\n    raise ValueError('uniform sampler min_value must be <= max_value')","typeGuard":"def is_valid_uniform_params(sp) -> bool:\n    return sp.get('min_value', 0) <= sp.get('max_value', 0)","tryCatchPattern":"try:\n    sampler = UniformSamplerSettings(**sp)\nexcept TrainerConfigError as e:\n    print(f'Fix sampler range: {e}')\n    sp['min_value'], sp['max_value'] = sorted([sp['min_value'], sp['max_value']])","preventionTips":["Sanity-check all numeric ranges when editing configs","Auto-swap min/max in a config preprocessing step","Unit-test curriculum/sampler configs with a range assertion"],"tags":["config","validation","sampler","parameter-randomization"],"backgroundTag":"invalid-range","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}