JuliaPOMDP / POMDPs.jl

MDPs and POMDPs in Julia - An interface for defining, solving, and simulating fully and partially observable Markov decision processes on discrete and continuous spaces.
http://juliapomdp.github.io/POMDPs.jl/latest/
Other
657 stars 100 forks source link

Function convert_s error #452

Closed yangyou95 closed 1 year ago

yangyou95 commented 1 year ago

I'm learning how to use this POMDPs.jl framework (which is amazing!) and I'm really new to Julia, maybe this is a stupid question.

According to the documentation (https://juliapomdp.github.io/POMDPs.jl/latest/api/#POMDPs.convert_s), This convert_s(::Type{V}, s, POMDP) function should output a vector, which corresponds to the state s in the given POMDP. For example, like "vector\<double>" in c++.

However, I run the following codes, it seems this transformation is not allowed?

# -- RockSample (15, 15) ---
pomdp = RockSamplePOMDP(15, 15)
b0 = initialstate(pomdp)
s = rand(b0)
println(s)
convert_s(Vector{Float64}, s, pomdp)

### output ###
ERROR: MethodError: no method matching convert_s(::Type{Vector{Float64}}, ::RSState{15}, ::RockSamplePOMDP{15})
Closest candidates are:
  convert_s(::Type{A1}, ::A2, ::Union{MDP, POMDP}) where {A1<:AbstractArray, A2<:AbstractArray} at C:\Users\Yang\.julia\packages\POMDPs\XBTe5\src\pomdp.jl:153
  convert_s(::Type{V}, ::Any, ::FullyObservablePOMDP) where V<:AbstractArray at C:\Users\Yang\.julia\packages\POMDPTools\i3nmI\src\ModelTools\fully_observable_pomdp.j
l:39
  convert_s(::Type{A}, ::Number, ::Union{MDP, POMDP}) where A<:AbstractArray at 
  ...
Stacktrace:

Did I miss something? I just would like to transform any given state s in any (PO)MDP into a vector\<double>, so that the solver could be generic to handle different problems.

Thanks for your help.

zsunberg commented 1 year ago

Hi @yangyou95 , you are understanding the usage correctly. The issue is that RockSample does not implement convert_s at the moment. The problems in POMDPs.jl have varying levels of completeness in implementing the entire interface, and this one just doesn't have convert_s.

The implementation should look something like:

POMDPs.convert_s(T::Type{<:AbstractArray}, s::RSState, m::RockSamplePOMDP) = convert(T, vcat(s.pos, s.rocks))

If you want to submit a PR to RockSample.jl to add it and test it, that would be really helpful. Otherwise I might be able to get around to it sometime soon

yangyou95 commented 1 year ago

Thanks for the explanation! I will work on that.