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

Infinite-recursion bug in function is_discrete_space when an object of type ClosedInterval is passed #566

Closed
bhatiaabhinav opened this issue Dec 25, 2021 · 3 comments · Fixed by #567

Comments

@bhatiaabhinav
Copy link
Contributor

The following simple code throws StackOverflowError:

julia> using ReinforcementLearning
julia> env = MountainCarEnv(continuous=true);
julia> action_space(env)
-1.0..1.0
julia> is_discrete_space(action_space(env))
ERROR: StackOverflowError:
Stacktrace:
 [1] is_discrete_space(x::Type) (repeats 79977 times)
   @ ReinforcementLearningEnvironments C:\Users\abhin\.julia\packages\ReinforcementLearningEnvironments\UhI2A\src\converters.jl:3
@bhatiaabhinav
Copy link
Contributor Author

bhatiaabhinav commented Dec 25, 2021

This is happening because there is no function is_discrete_space(::AbstractInterval) defined in ReinforcementLearningEnvironments\src\converters.jl among all the following definition of the function:

is_discrete_space(x) = is_discrete_space(typeof(x))  # <- leads to infinite recursion when x isa ClosedInterval

is_discrete_space(::Type{<:AbstractVector}) = true
is_discrete_space(::Type{<:Tuple}) = true
is_discrete_space(::Type{<:NamedTuple}) = true

is_discrete_space(::Type{<:Space}) = false

Adding the following code would solve the problem:

using IntervalSets
is_discrete_space(::AbstractInterval) = false

@findmyway
Copy link
Member

Or maybe we can simply set the default value to false?

Like

is_discrete_space(::Type) = false

@bhatiaabhinav
Copy link
Contributor Author

Yeah, whatever works. I like the simplicity/generality of your suggestion.

findmyway added a commit to findmyway/ReinforcementLearning.jl that referenced this issue Dec 25, 2021
@findmyway findmyway linked a pull request Dec 25, 2021 that will close this issue
1 task
findmyway added a commit that referenced this issue Dec 25, 2021
* make bc gpu compatable

* bump version

* fix #566
harwiltz pushed a commit to harwiltz/ReinforcementLearning.jl that referenced this issue Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants