You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am currently trying to implement an example of the POMDPStressTesting.jl with the environment of AutomotiveSimulator.jl. Unfortunately, I am very new to Julia, and I am struggling to find my mistake.
I tried to guide my attempts along the Walk1D.jl example.
What I wanted to achieve is a simple scenario with two vehicles where the adversarial tries to modify the initial speed of the vehicle and the distance metric is literally the distance between the two vehicles on the straight roadway.
This is the code I want to execute:
using POMDPStressTesting # this packageusing Distributions # for the Normal distributionusing Parameters # for @with_kw default struct parametersusing AutomotiveSimulator
using AutomotiveVisualization
# initialize the simulation based on https://sisl.github.io/AutomotiveSimulator.jl/dev/tutorials/straight_roadway/# * GrayBox Environment Setup# https://nbviewer.jupyter.org/github/sisl/POMDPStressTesting.jl/blob/master/notebooks/Walk1D.ipynb#GrayBox.Simulation@with_kwmutable struct AutoSimSetup
roadway:Roadway =gen_straight_roadway(1, 2000.0)
scene::Scene=Scene([
Entity(VehicleState(VecSE2(10.0,0.0,0.0), roadway, 8.0), VehicleDef(), 1),
Entity(VehicleState(VecSE2(50.0,0.0,0.0), roadway, 12.5), VehicleDef(), 2),
])
models::Dict{Int, LaneFollowingDriver}=Dict{Int, LaneFollowingDriver}(
1=>StaticLaneFollowingDriver(0.0), # always produce zero acceleration2=>IntelligentDriverModel(v_des=12.0), # default IDM with a desired speed of 12 m/s
)
timestep::Float64=0.1# typical time step of the simulation
nticks::Int64=100
endtime::Float64= timestep * nticks
eventdistance::Float64=30.0end# stores simulation-related values@with_kwmutable struct AutoSim <:GrayBox.Simulation
params::AutoSimSetup=AutoSimSetup() # Setup Parameters
distance_to::Float64=1000# distance between the two vehicles
init_velocity2::Float64=12.5
scene::Scene=Scene([
Entity(VehicleState(VecSE2(10.0,0.0,0.0), params.roadway, 8.0), VehicleDef(), 1),
Entity(VehicleState(VecSE2(50.0,0.0,0.0), params.roadway, init_velocity2), VehicleDef(), 2),
])
time::Float64=0.0# current time
distribution::Distribution=Normal(12.5, 1)
end
GrayBox.environment(sim::AutoSim) = GrayBox.Environment(:init_velocity2=> sim.distribution)
function GrayBox.transition!(sim::AutoSim, sample::GrayBox.EnvironmentSample)
sim.time += sim.params.timestep
sim.init_velocity2 = sample[init_velocity2].value
sim.scene =simulate(sim.scene, sim.params.roadway, sim.params.models, 1, sim.params.timestep)
returnlogpdf(sample)::Realend# * BlackBox System Setup: https://nbviewer.jupyter.org/github/sisl/POMDPStressTesting.jl/blob/master/notebooks/Walk1D.ipynb#Black-box-Systemfunction BlackBox.initialize!(sim::AutoSim)
sim.params.roadway =gen_straight_roadway(1, 2000.0)
sim.params.scene =Scene([
Entity(VehicleState(VecSE2(10.0,0.0,0.0), sim.params.roadway, 8.0), VehicleDef(), 1),
Entity(VehicleState(VecSE2(50.0,0.0,0.0), sim.params.roadway, 12.5), VehicleDef(), 2),
])
sim.params.models =Dict{Int, LaneFollowingDriver}(
1=>StaticLaneFollowingDriver(0.0), # always produce zero acceleration2=>IntelligentDriverModel(v_des=12.0), # default IDM with a desired speed of 12 m/s
)
sim.params.timestep =0.1
sim.params.endtime =10.0endfunction BlackBox.distance(sim::AutoSim)
return40.0end
BlackBox.isevent(sim::AutoSim) =false#extract_featuresdistance_to(2, sim.params.roadway, sim.params.scene, [1]) <= sim.params.eventdistance
BlackBox.isterminal(sim::AutoSim) = BlackBox.isevent(sim) || sim.time >= sim.params.endtime
function BlackBox.evaluate!(sim::AutoSim, sample::GrayBox.EnvironmentSample)
logprob::Real= GrayBox.transition!(sim)
d::real= BlackBox.distance(sim)
event::Bool= BlackBox.isevent(sim)
return (logprob::Real, d::Real, event::Bool)
end# * AST Setup and Running: https://nbviewer.jupyter.org/github/sisl/POMDPStressTesting.jl/blob/master/notebooks/Walk1D.ipynb#AST-Setup-and-Runningfunctionsetup_ast(seed=0)
# Create gray-box simulation object
sim::GrayBox.Simulation=AutoSim()
# AST MDP formulation object
mdp::ASTMDP=ASTMDP{ASTSampleAction}(sim)
mdp.params.debug =true# record metrics
mdp.params.top_k =10# record top k best trajectories
mdp.params.seed = seed # set RNG seed for determinism# Hyperparameters for MCTS-PW as the solver
solver =MCTSPWSolver(n_iterations=1000, # number of algorithm iterations
exploration_constant=1.0, # UCT exploration
k_action=1.0, # action widening
alpha_action=0.5, # action widening
depth=sim.params.nticks) # tree depth# Get online planner (no work done, yet)
planner =solve(solver, mdp)
return planner
end
planner =setup_ast();
action_trace =search!(planner)
final_state =playback(planner, action_trace, sim->sim.x)
failure_rate =print_metrics(planner)
d3tree =visualize(planner) # re-runs the search to output the tree, then visualizes it
I am using the following packages with Julia 1.6.1 in Ubuntu 20.04
Nice to see you're combining this package with AutomotiveSimulator.jl (so am I at the moment 😁)
The bug you're running into is actually quite simple:
Change this (inside the function BlackBox.evaluate! definition):
logprob::Real = GrayBox.transition!(sim)
To this:
logprob::Real = GrayBox.transition!(sim, sample)
i.e., actually pass the sample into the GrayBox.transition! function you've defined. You're getting the conversion error because the transition! function without the sample as input is not defined, so it's using the stubbed-out empty interface function that returns nothing.
Hello, I am currently trying to implement an example of the POMDPStressTesting.jl with the environment of AutomotiveSimulator.jl. Unfortunately, I am very new to Julia, and I am struggling to find my mistake.
I tried to guide my attempts along the Walk1D.jl example.
What I wanted to achieve is a simple scenario with two vehicles where the adversarial tries to modify the initial speed of the vehicle and the distance metric is literally the distance between the two vehicles on the straight roadway.
This is the code I want to execute:
I am using the following packages with Julia 1.6.1 in Ubuntu 20.04
I have the following bug, where I don't quite understand how to solve the bug.
In the
default_action.jl
of theMCTS
package is the exception thrown on line 3:I get the following expressions for
s
andmdp
.I assume that the error is that
parent
,action
andstate
are allnothing
ins
default_action
is called in thedpw.jl
file in theaction_info
function.s:ASTState
goes into the function and is originally passed as
initstate
in themcts.jl
file of thePOMDPStressTesting
package.initstate = AST.initialstate(mdp)
So something must be wrong in the initstate definition, but I don't know how to find out what.
Any help or idea is really appreciated.
Thanks and kind regards
The text was updated successfully, but these errors were encountered: