E-IG0101 — Range hint with a step other than 1
Error Type |
|
|---|---|
Phase |
configuring random instance generation (the |
Python exception |
|
Message
A Python `range` used as a {kind} range hint must have step 1, but this one has step `{step}`.
Possible fix: rewrite it as `range(start, stop)`.
({kind} is size or value, depending on which hint entry the range was given for; {step} is the offending step)
Cause
A Python range object with a step other than 1 was used as the size or value entry of a random-generation hint — for example range(0, 10, 2) or a decreasing range(10, 0, -1).
A range hint only describes the interval from its start to its stop; the step is not honored when sampling, so any step other than 1 is rejected outright.
Fix
Rewrite the hint as range(start, stop) with the default step of 1:
problem.generate_random_dataset(
options={"N": {"size": range(1, 11)}}, # not range(10, 0, -1)
)
If the range was decreasing, swap the endpoints so that the smaller one comes first.
If you intended the step to restrict the sampled values (for example, only even numbers), note that random generation cannot honor a stride; choose an interval covering the values you accept, or generate the data yourself and pass it to Problem.eval directly.