Skip to content

Commit

Permalink
Merge pull request #156 from JuliaPOMDP/0_6
Browse files Browse the repository at this point in the history
Upgrade for julia 0.6
  • Loading branch information
MaximeBouton authored Jul 17, 2017
2 parents e0f4195 + f197175 commit ea49722
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
notifications:
email: false
before_script:
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.5 0.6
julia 0.6
Distributions
10 changes: 4 additions & 6 deletions src/belief.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
"""
Abstract type for an object that defines how the belief should be updated
B: belief type that parametrizes the updater
A belief is a general construct that represents the knowledge an agent has
about the state of the system. This can be a probability distribution, an
action observation history or a more general representation.
action observation history or a more general representation.
"""
abstract Updater{B}
abstract type Updater end

# TODO(max): should this be moved to pomdp.jl?
"""
Expand All @@ -31,7 +29,7 @@ Returns a new instance of an updated belief given `belief_old` and the latest ac
function update end

"""
initialize_belief{B}(updater::Updater{B},
initialize_belief{B}(updater::Updater{B},
state_distribution::Any)
initialize_belief{B}(updater::Updater{B}, belief::Any)
Expand All @@ -45,4 +43,4 @@ correct type: `initialize_belief{B}(updater::Updater{B}, belief::B) = belief`
function initialize_belief end

# default implementation if the input is the same type as the output
initialize_belief{B}(updater::Updater{B}, belief::B) = belief
initialize_belief{B}(updater::Updater, belief::B) = belief
8 changes: 3 additions & 5 deletions src/policy.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#################################################################
# The policy is a mapping from a belief to an action in a POMDP,
# and it maps states to actions in an MDP.
# and it maps states to actions in an MDP.
# The policy is extracted through calls to the action() function.
#################################################################

"""
Base type for a policy (a map from every possible belief, or more abstract policy state, to an optimal or suboptimal action)
B: a belief (or policy state) that represents the knowledge an agent has about the state of the system
"""
abstract Policy{B}
abstract type Policy end

"""
action{B}(policy::Policy, x::B)
Fills and returns action based on the current state or belief, given the policy.
`B` is a generalized information state - can be a state in an MDP, a distribution in POMDP,
or any other representation needed to make a decision using the given policy.
or any other representation needed to make a decision using the given policy.
"""
function action end

Expand Down
6 changes: 3 additions & 3 deletions src/pomdp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Abstract base type for a partially observable Markov decision process.
A: action type
O: observation type
"""
abstract POMDP{S,A,O}
abstract type POMDP{S,A,O} end

"""
Abstract base type for a fully observable Markov decision process.
S: state type
A: action type
"""
abstract MDP{S,A}
abstract type MDP{S,A} end

"""
n_states(problem::POMDP)
Expand Down Expand Up @@ -76,7 +76,7 @@ observation{S,A,O}(problem::POMDP{S,A,O}, a::A, sp::S) = observation(problem, sp
Return the observation distribution for the s-a-s' tuple (state, action, and next state)
"""
observation{S,A,O}(problem::POMDP{S,A,O}, s::S, a::A, sp::S) = observation(problem, a, sp)
observation{S,A,O}(problem::POMDP{S,A,O}, s::S, a::A, sp::S) = observation(problem, a, sp)
@impl_dep {P<:POMDP,S,A} observation(::P,::S,::A,::S) observation(::P,::A,::S)

"""
Expand Down
12 changes: 6 additions & 6 deletions src/requirements_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ macro POMDP_require(typedcall, block)
tconstr = Expr[:($(Symbol(:T,i))<:$(esc(C))) for (i,C) in enumerate(types)] # oh snap
ts = Symbol[Symbol(:T,i) for i in 1:length(types)]
req_spec = :(($fname, Tuple{$(types...)}))
fimpl = quote
function get_requirements{$(tconstr...)}(f::typeof($(esc(fname))), # dang
fimpl = quote
function POMDPs.get_requirements{$(tconstr...)}(f::typeof($(esc(fname))), # dang
args::Tuple{$(ts...)})
($([esc(a) for a in args]...),) = args # whoah
return $(pomdp_requirements(req_spec, block))
Expand Down Expand Up @@ -114,7 +114,7 @@ end
"""
@requirements_info ASolver() [YourPOMDP()]
Print information about the requirements for a solver.
Print information about the requirements for a solver.
"""
macro requirements_info(exprs...)
quote
Expand Down Expand Up @@ -155,7 +155,7 @@ end
"""
@subreq f(arg1, arg2)
In a `@POMDP_requirements` or `@POMDP_require` block, include the requirements for `f(arg1, arg2) as a child argument set.
In a `@POMDP_requirements` or `@POMDP_require` block, include the requirements for `f(arg1, arg2)` as a child argument set.
"""
macro subreq(ex)
return quote
Expand Down Expand Up @@ -190,13 +190,13 @@ function show_requirements(r::AbstractRequirementSet)

# all printing to the screen happens here at once
println()
print(takebuf_string(buf))
print(String(take!(buf)))
println()
if !allthere
println("Note: Missing methods are often due to incorrect importing. Consider using `importall POMDPs`.")
println()
end

if !isnull(first_exception)
print("Throwing the first exception (from processing ")
print_with_color(:blue, handle_method(get(first_exception).requirer))
Expand Down
22 changes: 11 additions & 11 deletions src/requirements_internals.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
typealias TupleType Type # should be Tuple{T1,T2,...}
typealias Req Tuple{Function, TupleType}
const TupleType = Type # should be Tuple{T1,T2,...}
const Req = Tuple{Function, TupleType}

abstract AbstractRequirementSet
abstract type AbstractRequirementSet end

type Unspecified <: AbstractRequirementSet
mutable struct Unspecified <: AbstractRequirementSet
requirer
parent::Nullable{Any}
end

Unspecified(requirer) = Unspecified(requirer, Nullable{Any}())

type RequirementSet <: AbstractRequirementSet
mutable struct RequirementSet <: AbstractRequirementSet
requirer
reqs::Vector{Req} # not actually a set - to preserve intuitive ordering
deps::Vector{AbstractRequirementSet}
Expand Down Expand Up @@ -57,7 +57,7 @@ function pomdp_requirements(name::Union{Expr,String}, block::Expr)
return newblock
end

typealias CheckedList Vector{Tuple{Bool, Function, TupleType}}
const CheckedList = Vector{Tuple{Bool, Function, TupleType}}


"""
Expand All @@ -83,7 +83,7 @@ function convert_req(ex::Expr)
break
end
end
else
else
malformed = true
end
if malformed # throw error at parse time so solver writers will have to deal with this
Expand Down Expand Up @@ -133,7 +133,7 @@ function recursively_show(io::IO,
show_incomplete(io, r)
first_exception = Nullable{RequirementSet}(r)
end

for dep in r.deps
depcomplete, depexception = recursively_show(io, dep, analyzed, reported)
allthere = allthere && depcomplete
Expand Down Expand Up @@ -239,7 +239,7 @@ function convert_call(call::Expr)
push!(args, a)
end
end
else
else
malformed = true
end
if malformed # throw error at parse time so solver writers will have to deal with this
Expand All @@ -262,7 +262,7 @@ Replace any @req calls with `push!(\$reqs_name, <requirement>)`
Returns true if there was a requirement in there and so should not be escaped.
"""
function handle_reqs!(node::Expr, reqs_name::Symbol)

if node.head == :macrocall && node.args[1] == Symbol("@req")
macro_node = copy(node)
node.head = :call
Expand Down Expand Up @@ -312,7 +312,7 @@ In the example above, `@implemented reward(::P,::S,::A,::S)` will return true if
THIS IS ONLY INTENDED FOR USE INSIDE POMDPs AND MAY NOT FUNCTION CORRECTLY ELSEWHERE
"""
macro impl_dep(curly, signature, dependency)
# this is kinda hacky and fragile with the cell1d - email Zach if it breaks
# this is kinda hacky and fragile with the cell1d - email Zach if it breaks
@assert curly.head == :cell1d
implemented_curly = :(implemented{$(curly.args...)})
tplex = convert_req(signature)
Expand Down
14 changes: 11 additions & 3 deletions src/requirements_printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ function format_method(f::Function, argtypes::TupleType; module_names=false)
if !module_names
# begin
fname = typeof(f).name.mt.name
mless_typenames = []
mless_typenames = []
for t in argtypes.parameters
# if isa(t, Union)
# str = "Union{"
# for (i, tt) in enumerate(t.types)
# str = string(str, tt.name.name, i<length(t.types)?',':'}')
# end
# push!(mless_typenames, str)
if isa(t, Union)
str = "Union{"
for (i, tt) in enumerate(t.types)
str = string(str, tt.name.name, i<length(t.types)?',':'}')
for (i, tt) in enumerate(fieldnames(t))
str = string(str, getfield(t, tt), i<length(fieldnames(t))?',':'}')
end
push!(mless_typenames, str)
elseif isa(t, UnionAll)
push!(mless_typenames, string(t))
else
push!(mless_typenames, t.name.name)
end
Expand Down
6 changes: 3 additions & 3 deletions src/simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"""
Base type for an object defining how simulations should be carried out.
"""
abstract Simulator
abstract type Simulator end

"""
simulate{S,A,O,B}(simulator::Simulator, problem::POMDP{S,A,O}, policy::Policy{B}, updater::Updater{B}, initial_belief::B)
simulate{S,A}(simulator::Simulator, problem::MDP{S,A}, policy::Policy, initial_state::S)
simulate{S,A,O,B}(simulator::Simulator, problem::POMDP{S,A,O}, policy::Policy{B}, updater::Updater{B}, initial_belief::B)
simulate{S,A}(simulator::Simulator, problem::MDP{S,A}, policy::Policy, initial_state::S)
Run a simulation using the specified policy.
Expand Down
4 changes: 2 additions & 2 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"""
Base type for an MDP/POMDP solver
"""
abstract Solver
abstract type Solver end

"""
solve(solver::Solver, problem::POMDP)
Solves the POMDP using method associated with solver, and returns a policy.
Solves the POMDP using method associated with solver, and returns a policy.
"""
function solve end
6 changes: 3 additions & 3 deletions src/space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function states end
Returns a subset of the state space reachable from `state`.
"""
states{S,A}(problem::Union{POMDP{S,A},MDP{S,A}}, s::S) = states(problem)
states(problem::Union{POMDP,MDP}, s) = states(problem)
@impl_dep {P<:Union{POMDP,MDP},S} states(::P,::S) states(::P)

"""
Expand All @@ -40,7 +40,7 @@ function actions end
Return the action space accessible from the given state.
"""
actions{S,A}(problem::Union{MDP{S,A},POMDP{S,A}}, state::S) = actions(problem)
actions(problem::Union{MDP,POMDP}, state) = actions(problem)
@impl_dep {P<:Union{POMDP,MDP},S} actions(::P,::S) actions(::P)

"""
Expand All @@ -62,5 +62,5 @@ function observations end
Return the observation space accessible from the given state and returns it.
"""
observations{S,A,O}(problem::POMDP{S,A,O}, state::S) = observations(problem)
observations(problem::POMDP, state) = observations(problem)
@impl_dep {P<:POMDP,S} observations(::P,::S) observations(::P)
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Base.Test

using POMDPs
type A <: POMDP{Int,Bool,Bool} end
mutable struct A <: POMDP{Int,Bool,Bool} end
@test_throws MethodError n_states(A())
@test_throws MethodError state_index(A(), 1)

Expand All @@ -18,7 +18,7 @@ POMDPs.observation(::A,::Bool,::Int) = [true, false]
@test @implemented observation(::A,::Int,::Bool,::Int)
@test @implemented observation(::A,::Bool,::Int)

type D end
mutable struct D end
POMDPs.sampletype(::Type{D}) = Int
@test @implemented sampletype(::D)
@test sampletype(D()) == Int
Expand Down
4 changes: 2 additions & 2 deletions test/test_generative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ println("Warning expected:")
println("Warning expected:")
@test_throws MethodError generate_s(A(), 1, true, Base.GLOBAL_RNG)

type B <: POMDP{Int, Bool, Bool} end
mutable struct B <: POMDP{Int, Bool, Bool} end

transition(b::B, s::Int, a::Bool) = Int[s+a]
@test implemented(generate_s, Tuple{B, Int, Bool, MersenneTwister})
Expand All @@ -28,7 +28,7 @@ initial_state_distribution(b::B) = Int[1,2,3]
@test initial_state(B(), Base.GLOBAL_RNG) in initial_state_distribution(B())


type C <: POMDP{Void, Void, Void} end
mutable struct C <: POMDP{Void, Void, Void} end
generate_sr(c::C, s::Void, a::Void, rng::AbstractRNG) = nothing, 0.0
generate_o(c::C, s::Void, a::Void, sp::Void, rng::AbstractRNG) = nothing
@test @implemented generate_sor(::C, ::Void, ::Void, ::MersenneTwister)
Expand Down
6 changes: 3 additions & 3 deletions test/test_inferrence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ using Base.Test

using POMDPs

type X <: POMDP{Float64,Bool,Int} end
abstract Z <: POMDP{Float64,Bool,Int}
type Y <: Z end
mutable struct X <: POMDP{Float64,Bool,Int} end
abstract type Z <: POMDP{Float64,Bool,Int} end
mutable struct Y <: Z end

@test_throws ErrorException state_type(Int)
@test_throws ErrorException action_type(Int)
Expand Down
10 changes: 5 additions & 5 deletions test/test_requirements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ end

module MyModule
using POMDPs

export CoolSolver, solve

type CoolSolver <: Solver end
mutable struct CoolSolver <: Solver end

p = nothing # to test hygeine
@POMDP_require solve(s::CoolSolver, p::POMDP) begin
Expand All @@ -41,7 +41,7 @@ module MyModule

util1(x) = abs(x)

util2(p::POMDP) = observations(p)
util2(p::POMDP) = observations(p)
@POMDP_require util2(p::POMDP) begin
P = typeof(p)
@req observations(::P)
Expand All @@ -51,7 +51,7 @@ end
using POMDPs
using MyModule

type SimplePOMDP <: POMDP{Float64, Bool, Int} end
mutable struct SimplePOMDP <: POMDP{Float64, Bool, Int} end
POMDPs.actions(SimplePOMDP) = [true, false]

POMDPs.discount(::SimplePOMDP) = 0.9
Expand All @@ -71,7 +71,7 @@ end))
@test_throws MethodError solve(CoolSolver(), SimplePOMDP())

POMDPs.states(::SimplePOMDP) = [1.4, 3.2, 5.8]
immutable SimpleDistribution
struct SimpleDistribution
ss::Vector{Float64}
b::Vector{Float64}
end
Expand Down

0 comments on commit ea49722

Please sign in to comment.