Skip to content

[Bug]: from_config.py Floating point modulo bug in RangeParameter step_size validation #4599

@wizardlyrocket8

Description

@wizardlyrocket8

What happened?

I am sorry this is my first time writing a bug report (At least I think it is a bug).
But I was trying to make a sum constraint from a list of RangeParameterConfig, so because the SumConstraint only takes RangeParameters, I decided to convert RangeParameterConfigs to RangeParameters.

        def get_client_constraints(parameters):
            param_range_list = [parameter_from_config(parameter) for parameter in parameters if parameter.name in ['[Fe3+] (g/L)','[Co2+] (g/L)', '[Cu2+] (g/L)','[K+] (g/L)']]
            sum_constraint = SumConstraint(param_range_list, is_upper_bound= True, bound = 100.0)
            return sum_constraint

This is where the problem occurred: "ax.exceptions.core.UserInputError: The range of the parameter must be evenly divisible by the step size."
I went to explore and found that because the bounds for parameters are [0.0, 100.0] and the step size is 0.1, I get the error from this if statement:

        if (upper - lower) % step_size != 0:
            raise UserInputError(
                "The range of the parameter must be evenly divisible by the "
                "step size."
            )

Please provide a minimal, reproducible example of the unexpected behavior.

print((100.0 - 0.0)%0.1)
0.09999999999999445

Please paste any relevant traceback/logs produced by the example provided.

Ax Version

1.2.1

Python Version

3.13.9

Operating System

MAC

(Optional) Describe any potential fixes you've considered to the issue outlined above.

No response

Pull Request

None

Code of Conduct

  • I agree to follow Ax's Code of Conduct

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions