Closed Jammf closed 4 months ago
@Jammf can you make a PR https://github.com/Farama-Foundation/Gymnasium/blob/main/gymnasium/spaces/box.py#L55
My intuition is to raise an error within __init__
if either the low or high are outside of the dtype
's possible values.
@RedTachyon @Jammf Do you agree? If so, could we make a PR that adds this?
Sure, I can make a PR. I think raising an error makes sense, but it'd also mean that integer boxes could no longer be unbounded (since ints can't be inf). Is that what we'd want?
Also, is that case, it seems like it'd have a lot of overlap with a MultiDiscrete space, so I'd wonder what the benefit of having both integer Box and MultiDiscrete would be (and the same with binary Box and MultiBinary). But, Box does also have a nice way to specify identical limits for every axis, so it has that going for it.
We could treat inf
as a special case to ignore as the max value to test are within the dtype
's bound I think is the simplest approach to perverse backward compatibility
Fixed in #774
Describe the bug
During init, Box bounds are captured before casting to the destination dtype, but aren't checked again after the cast.
When Box casts to a lower-precision float with a range smaller than the source dtype, for example
Box(0, 80000, dtype=np.float16)
, this can causehigh
andlow
to containnp.inf
values without the correspondingbounded_above
orbounded_below
being False. This leads to an error when callingsample()
.When Box casts
np.inf
from a float to an int, for exampleBox(255, np.inf, dtype=np.uint8)
, samples can under/overflow and be outside the Box bounds -- #328 seems to be related to this one.Code example
System info
gymnasium.__version__ == '0.29.1'
Additional context
No response
Checklist