Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] Box contains treats float(inf) unexpectedly #493

Closed
1 task done
mzat-msft opened this issue May 8, 2023 · 5 comments · Fixed by #495
Closed
1 task done

[Bug Report] Box contains treats float(inf) unexpectedly #493

mzat-msft opened this issue May 8, 2023 · 5 comments · Fixed by #495
Labels
bug Something isn't working

Comments

@mzat-msft
Copy link

Describe the bug

When checking if a number is contained in a Box I get True but I expect it to be False.

Code example

Python 3.10.11 (main, May  4 2023, 15:26:51) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gymnasium.spaces import Box
>>> Box(low=float("inf"), high=float("inf")).contains([-10])
True
>>> Box(low=-float("-inf"), high=float("inf")).contains([-10])
True

System info

gymnasium.version
'0.26.3'

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@Kallinteris-Andreas
Copy link
Collaborator

does this happen only with inf>

@pseudo-rnd-thoughts
Copy link
Member

Ok, this is a really weird bug from the outlook

In short, Box internally changes the inf to -inf which is why contains([-10]) is true.

In particular, the get_inf function ignores the actual value passed just knowing that it was an infinite (ignoring that you passed a positive infinity as the lower bound) and returns a positive or negative infinity depending on if it is for the lower and upper bound.

I agree that this is a hidden behaviour that you don't expected from the outside.
@mzat-msft Would you be interested in making a PR that raise a warning or error to users that they are doing something silly and should update to -inf

@jjshoots
Copy link
Member

jjshoots commented May 8, 2023

@mzat-msft This is actually a very interesting case.

What are you exactly trying to achieve with using equal sign infinites as bounds for the Box space?
I ask this because this behaviour (in theory) should produce a degenerate space:

  • what values belong in the space?
  • what should is_bounded("above") return on a space of Box(-inf, -inf)?

Fixing this issue is possible (though I'm more keen to just make the space throw an error to disallow this behaviour).
If you could let us know what use case this is for, perhaps it would allow us to make more informed decisions when fixing this "bug".

@mzat-msft
Copy link
Author

mzat-msft commented May 9, 2023

There's no use case per se. There was this typo in our code and just thought it would be useful for you to know about it.
I agree that raising a ValueError is probably the right thing to do. Would that apply to Box(x, x) too?

@pseudo-rnd-thoughts
Copy link
Member

Would that apply to Box(x, x) too?

I think it would be reasonable to do so but np.random.uniform(low=x, high=x) works therefore, I don't think we should disable it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants