mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-11-08 22:21:08 +00:00
Save env_helper every some episodes
This commit is contained in:
parent
b55ef91d2d
commit
9e80c22bdb
3 changed files with 14 additions and 9 deletions
|
@ -18,7 +18,7 @@ function gen_verlet_and_cell_lists_graphics()
|
||||||
R_particle = 4.2
|
R_particle = 4.2
|
||||||
σ = 2 * R_particle * 2^(-1 / 6)
|
σ = 2 * R_particle * 2^(-1 / 6)
|
||||||
R_interaction = 2^(1 / 6) * σ
|
R_interaction = 2^(1 / 6) * σ
|
||||||
R_skin = 2 * R_interaction
|
R_skin = ReCo.DEFAULT_SKIN_TO_INTERACTION_RADIUS_RATIO * R_interaction
|
||||||
|
|
||||||
setcolor("blue")
|
setcolor("blue")
|
||||||
reference_particle_x = 0.25 * R_skin
|
reference_particle_x = 0.25 * R_skin
|
||||||
|
|
15
src/RL/RL.jl
15
src/RL/RL.jl
|
@ -66,11 +66,12 @@ function run_rl(;
|
||||||
n_particles::Int64=100,
|
n_particles::Int64=100,
|
||||||
seed::Int64=42,
|
seed::Int64=42,
|
||||||
ϵ_stable::Float64=0.0001,
|
ϵ_stable::Float64=0.0001,
|
||||||
skin_to_interaction_radius_ratio::Float64=ReCo.DEFAULT_SKIN_TO_INTERACTION_R_RATIO,
|
skin_to_interaction_radius_ratio::Float64=ReCo.DEFAULT_SKIN_TO_INTERACTION_RADIUS_RATIO,
|
||||||
packing_ratio::Float64=0.15,
|
packing_ratio::Float64=0.15,
|
||||||
show_progress::Bool=true,
|
show_progress::Bool=true,
|
||||||
reward_discount::Float64=0.1,
|
reward_discount::Float64=0.1,
|
||||||
show_simulation_progress::Bool=true,
|
show_simulation_progress::Bool=true,
|
||||||
|
n_episodes_before_env_helper_saving::Int64=10,
|
||||||
) where {E<:Env}
|
) where {E<:Env}
|
||||||
@assert 0.0 <= elliptical_a_b_ratio <= 1.0
|
@assert 0.0 <= elliptical_a_b_ratio <= 1.0
|
||||||
@assert n_episodes > 0
|
@assert n_episodes > 0
|
||||||
|
@ -78,6 +79,8 @@ function run_rl(;
|
||||||
@assert update_actions_at in 0.001:0.001:episode_duration
|
@assert update_actions_at in 0.001:0.001:episode_duration
|
||||||
@assert n_particles > 0
|
@assert n_particles > 0
|
||||||
@assert 0.0 < ϵ_stable < 1.0
|
@assert 0.0 < ϵ_stable < 1.0
|
||||||
|
@assert 0.0 <= reward_discount <= 1.0
|
||||||
|
@assert n_episodes_before_env_helper_saving > 0
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
Random.seed!(seed)
|
Random.seed!(seed)
|
||||||
|
@ -118,6 +121,8 @@ function run_rl(;
|
||||||
|
|
||||||
parent_dir = "RL/" * process_dir
|
parent_dir = "RL/" * process_dir
|
||||||
|
|
||||||
|
env_helper_path = ReCo.DEFAULT_EXPORTS_DIR * "/$parent_dir/env_helper.jld2"
|
||||||
|
|
||||||
# Pre experiment
|
# Pre experiment
|
||||||
hook(PRE_EXPERIMENT_STAGE, agent, env)
|
hook(PRE_EXPERIMENT_STAGE, agent, env)
|
||||||
agent(PRE_EXPERIMENT_STAGE, env)
|
agent(PRE_EXPERIMENT_STAGE, env)
|
||||||
|
@ -149,16 +154,16 @@ function run_rl(;
|
||||||
hook(POST_EPISODE_STAGE, agent, env)
|
hook(POST_EPISODE_STAGE, agent, env)
|
||||||
agent(POST_EPISODE_STAGE, env)
|
agent(POST_EPISODE_STAGE, env)
|
||||||
|
|
||||||
|
if episode % n_episodes_before_env_helper_saving == 0
|
||||||
|
JLD2.save_object(env_helper_path, env_helper)
|
||||||
|
end
|
||||||
|
|
||||||
ProgressMeter.next!(progress; showvalues=[(:rewards, hook.rewards)])
|
ProgressMeter.next!(progress; showvalues=[(:rewards, hook.rewards)])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Post experiment
|
# Post experiment
|
||||||
hook(POST_EXPERIMENT_STAGE, agent, env)
|
hook(POST_EXPERIMENT_STAGE, agent, env)
|
||||||
|
|
||||||
process_dir = ReCo.DEFAULT_EXPORTS_DIR * "/$parent_dir"
|
|
||||||
|
|
||||||
JLD2.save_object("$process_dir/env_helper.jld2", env_helper)
|
|
||||||
|
|
||||||
return env_helper
|
return env_helper
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const DEFAULT_PACKING_RATIO = 0.5
|
const DEFAULT_PACKING_RATIO = 0.5
|
||||||
const DEFAULT_δt = 1e-5
|
const DEFAULT_δt = 1e-5
|
||||||
const DEFAULT_SKIN_TO_INTERACTION_R_RATIO = 2.5
|
const DEFAULT_SKIN_TO_INTERACTION_RADIUS_RATIO = 2.5
|
||||||
const DEFAULT_EXPORTS_DIR = "exports"
|
const DEFAULT_EXPORTS_DIR = "exports"
|
||||||
const DEFAULT_PARENT_DIR = ""
|
const DEFAULT_PARENT_DIR = ""
|
||||||
const DEFAULT_COMMENT = ""
|
const DEFAULT_COMMENT = ""
|
||||||
|
@ -51,7 +51,7 @@ function gen_sim_consts(
|
||||||
v₀::Float64;
|
v₀::Float64;
|
||||||
δt::Float64=DEFAULT_δt,
|
δt::Float64=DEFAULT_δt,
|
||||||
packing_ratio::Float64=DEFAULT_PACKING_RATIO,
|
packing_ratio::Float64=DEFAULT_PACKING_RATIO,
|
||||||
skin_to_interaction_radius_ratio::Float64=DEFAULT_SKIN_TO_INTERACTION_R_RATIO,
|
skin_to_interaction_radius_ratio::Float64=DEFAULT_SKIN_TO_INTERACTION_RADIUS_RATIO,
|
||||||
half_box_len::Float64=0.0,
|
half_box_len::Float64=0.0,
|
||||||
)
|
)
|
||||||
@assert n_particles > 0
|
@assert n_particles > 0
|
||||||
|
@ -160,7 +160,7 @@ function init_sim(;
|
||||||
v₀::Float64,
|
v₀::Float64,
|
||||||
δt::Float64=DEFAULT_δt,
|
δt::Float64=DEFAULT_δt,
|
||||||
packing_ratio::Float64=DEFAULT_PACKING_RATIO,
|
packing_ratio::Float64=DEFAULT_PACKING_RATIO,
|
||||||
skin_to_interaction_radius_ratio::Float64=DEFAULT_SKIN_TO_INTERACTION_R_RATIO,
|
skin_to_interaction_radius_ratio::Float64=DEFAULT_SKIN_TO_INTERACTION_RADIUS_RATIO,
|
||||||
exports_dir::String=DEFAULT_EXPORTS_DIR,
|
exports_dir::String=DEFAULT_EXPORTS_DIR,
|
||||||
parent_dir::String=DEFAULT_PARENT_DIR,
|
parent_dir::String=DEFAULT_PARENT_DIR,
|
||||||
comment::String=DEFAULT_COMMENT,
|
comment::String=DEFAULT_COMMENT,
|
||||||
|
|
Loading…
Reference in a new issue