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

POMDPs v0.8 Compatibility #26

Merged
merged 10 commits into from
Sep 20, 2019
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "POMDPModelTools"
uuid = "08074719-1b2a-587c-a292-00f91cc44415"
authors = ["JuliaPOMDP Contributors"]
version = "0.1.7"
version = "0.2.0"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
10 changes: 3 additions & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
push!(LOAD_PATH, "../src/")

using Documenter, POMDPModelTools

makedocs(
modules = [POMDPModelTools],
format = :html,
format = Documenter.HTML(),
sitename = "POMDPModelTools.jl"
)

deploydocs(
repo = "github.com/JuliaPOMDP/POMDPModelTools.jl.git",
julia = "1.0",
osname = "linux",
target = "build",
deps = nothing,
make = nothing
)

23 changes: 0 additions & 23 deletions docs/mkdocs.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About

POMDPModelTools is a collection of interface extensions and tools to make writing models and solvers for [POMDPs.jl](github.com/JuliaPOMDP/POMDPs.jl) easier.
POMDPModelTools is a collection of interface extensions and tools to make writing models and solvers for [POMDPs.jl](https://github.com/JuliaPOMDP/POMDPs.jl) easier.

```@contents
```
10 changes: 8 additions & 2 deletions docs/src/interface_extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ ordered_observations

It is often the case that useful information besides the belief, state, action, etc is generated by a function in POMDPs.jl. This information can be useful for debugging or understanding the behavior of a solver, updater, or problem. The info interface provides a standard way for problems, policies, solvers or updaters to output this information. The recording simulators from [POMDPSimulators.jl](https://github.com/JuliaPOMDP/POMDPSimulators.jl) automatically record this information.

To specify info for a problem (in POMDPs v0.8 and above), one should modify the problem's DDN with the `add_infonode` function, then return the info in `gen`. There is an example of this pattern in the docstring below:

```@docs
add_infonode
```

To specify info from policies, solvers, or updaters, implement the following functions:

```@docs
generate_sri
generate_sori
action_info
solve_info
update_info
Expand Down
33 changes: 31 additions & 2 deletions src/info.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,42 @@ function update_info(up::Updater, b, a, o)
return update(up, b, a, o), nothing
end

# once POMDPs v0.8 is released, this should be a jldoctest
"""
add_infonode(ddn::DDNStructure)

Create a new DDNStructure object with a new node labeled :info with parents :s and :a
Create a new DDNStructure object with a new node labeled :info for returning miscellaneous informationabout a simulation step.

Typically, the object in info is associative (i.e. a `Dict` or `NamedTuple`) with keys corresponding to different pieces of information.

# Example (using POMDPs v0.8)

```julia
using POMDPs, POMDPModelTools, POMDPPolicies, POMDPSimulators, Random

struct MyMDP <: MDP{Int, Int} end

# add the info node to the DDN
POMDPs.DDNStructure(::Type{MyMDP}) = mdp_ddn() |> add_infonode

# the dynamics involve two random numbers - here we record the values for each in info
function POMDPs.gen(m::MyMDP, s, a, rng)
r1 = rand(rng)
r2 = randn(rng)
return (sp=s+a+r1+r2, r=s^2, info=(r1=r1, r2=r2))
end

m = MyMDP()
@show nodenames(DDNStructure(m))
p = FunctionPolicy(s->1)
for (s,info) in stepthrough(m, p, 1, "s,info", max_steps=5, rng=MersenneTwister(2))
@show s
@show info
end
```
"""
function add_infonode(ddn) # for DDNStructure, but it is not declared in v0.7.3, so there is not annotation
add_node(ddn, :info, ConstantDDNNode(nothing), (:s, :a))
add_node(ddn, :info, ConstantDDNNode(nothing), nodenames(ddn))
end

function add_infonode(ddn::POMDPs.DDNStructureV7{nodenames}) where nodenames
Expand Down
2 changes: 1 addition & 1 deletion test/test_underlying_mdp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let

solver = ValueIterationSolver(max_iterations = 100)
mdp_policy = solve(solver, mdp)
pomdp_policy = solve(solver, pomdp)
pomdp_policy = solve(solver, UnderlyingMDP(pomdp))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not make sense anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it doesn't hurt anything. At least it exercises a lot of the functions. I think it is fine

@test mdp_policy.util == pomdp_policy.util

actionindex(mdp, 1)
Expand Down