1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-11-08 22:21:08 +00:00

Replaced progress macro

This commit is contained in:
Mo8it 2022-01-23 04:21:06 +01:00
parent a392840a91
commit e50336d6e4
5 changed files with 31 additions and 7 deletions

View file

@ -6,7 +6,7 @@ using GLMakie
using ColorSchemes: cyclic_mrybm_35_75_c68_n256_s25 using ColorSchemes: cyclic_mrybm_35_75_c68_n256_s25
using LaTeXStrings: @L_str using LaTeXStrings: @L_str
using JLD2: JLD2 using JLD2: JLD2
using ProgressMeter: @showprogress using ProgressMeter: ProgressMeter
using ..ReCo: ReCo using ..ReCo: ReCo
@ -123,6 +123,7 @@ function animate_with_sim_consts(
show_interaction_circle::Bool, show_interaction_circle::Bool,
show_skin_circle::Bool, show_skin_circle::Bool,
show_frame_diff::Bool, show_frame_diff::Bool,
show_progress::Bool,
) )
GLMakie.activate!() GLMakie.activate!()
set_theme!(theme_black()) set_theme!(theme_black())
@ -184,7 +185,11 @@ function animate_with_sim_consts(
bundle_paths = ReCo.sorted_bundle_paths(dir) bundle_paths = ReCo.sorted_bundle_paths(dir)
@showprogress 1 for (n_bundle, bundle_path) in enumerate(bundle_paths) progress = ProgressMeter.Progress(
length(bundle_paths); dt=1, enabled=show_progress, desc="Animation: "
)
for (n_bundle, bundle_path) in enumerate(bundle_paths)
bundle::ReCo.Bundle = JLD2.load_object(bundle_path) bundle::ReCo.Bundle = JLD2.load_object(bundle_path)
args = (; args = (;
@ -212,6 +217,8 @@ function animate_with_sim_consts(
) )
animate_bundle!(args, sim_consts) animate_bundle!(args, sim_consts)
ProgressMeter.next!(progress)
end end
end end
@ -225,6 +232,7 @@ function animate(
show_interaction_circle::Bool=false, show_interaction_circle::Bool=false,
show_skin_circle::Bool=false, show_skin_circle::Bool=false,
show_frame_diff::Bool=false, show_frame_diff::Bool=false,
show_progress::Bool=true,
) )
println("Generating animation...") println("Generating animation...")
@ -238,6 +246,7 @@ function animate(
show_interaction_circle, show_interaction_circle,
show_skin_circle, show_skin_circle,
show_frame_diff, show_frame_diff,
show_progress,
) )
println("Animation done.") println("Animation done.")

View file

@ -10,7 +10,7 @@ using Intervals
using StaticArrays: SVector using StaticArrays: SVector
using LoopVectorization: @turbo using LoopVectorization: @turbo
using Random: Random using Random: Random
using ProgressMeter: @showprogress using ProgressMeter: ProgressMeter
using ..ReCo: ReCo using ..ReCo: ReCo
@ -62,6 +62,7 @@ function run_rl(;
ϵ_stable::Float64=0.0001, ϵ_stable::Float64=0.0001,
skin_to_interaction_r_ratio::Float64=ReCo.DEFAULT_SKIN_TO_INTERACTION_R_RATIO, skin_to_interaction_r_ratio::Float64=ReCo.DEFAULT_SKIN_TO_INTERACTION_R_RATIO,
packing_ratio::Float64=0.22, packing_ratio::Float64=0.22,
show_progress::Bool=true,
) where {E<:Env} ) where {E<:Env}
@assert 0.0 <= goal_gyration_tensor_eigvals_ratio <= 1.0 @assert 0.0 <= goal_gyration_tensor_eigvals_ratio <= 1.0
@assert n_episodes > 0 @assert n_episodes > 0
@ -110,7 +111,9 @@ function run_rl(;
hook(PRE_EXPERIMENT_STAGE, agent, env) hook(PRE_EXPERIMENT_STAGE, agent, env)
agent(PRE_EXPERIMENT_STAGE, env) agent(PRE_EXPERIMENT_STAGE, env)
@showprogress 0.6 for episode in 1:n_episodes progress = ProgressMeter.Progress(n_episodes; dt=1, enabled=show_progress, desc="RL: ")
for episode in 1:n_episodes
dir = ReCo.init_sim_with_sim_consts(sim_consts; parent_dir=parent_dir) dir = ReCo.init_sim_with_sim_consts(sim_consts; parent_dir=parent_dir)
# Reset # Reset
@ -136,7 +139,9 @@ function run_rl(;
# TODO: Replace with live plot # TODO: Replace with live plot
@show hook.rewards @show hook.rewards
@show agent.policy.explorer.step # @show agent.policy.explorer.step
ProgressMeter.next!(progress)
end end
# Post experiment # Post experiment

View file

@ -5,7 +5,7 @@ export init_sim, run_sim, run_rl, animate, LocalCOMEnv
using StaticArrays: SVector using StaticArrays: SVector
using JLD2: JLD2 using JLD2: JLD2
using Distributions: Uniform, Normal using Distributions: Uniform, Normal
using ProgressMeter: @showprogress using ProgressMeter: ProgressMeter
using CellListMap: CellListMap using CellListMap: CellListMap
using Random: Random using Random: Random

View file

@ -13,6 +13,7 @@ function run_sim(
seed::Int64=42, seed::Int64=42,
n_bundle_snapshots::Int64=100, n_bundle_snapshots::Int64=100,
env_helper::Union{RL.EnvHelper,Nothing}=nothing, env_helper::Union{RL.EnvHelper,Nothing}=nothing,
show_progress::Bool=true,
) )
@assert length(dir) > 0 @assert length(dir) > 0
@assert duration > 0 @assert duration > 0
@ -102,6 +103,7 @@ function run_sim(
n_bundle_snapshots=n_bundle_snapshots, n_bundle_snapshots=n_bundle_snapshots,
bundle=Bundle(sim_consts.n_particles, n_bundle_snapshots), bundle=Bundle(sim_consts.n_particles, n_bundle_snapshots),
box=gen_cell_list_box(sim_consts.half_box_len, sim_consts.skin_r), box=gen_cell_list_box(sim_consts.half_box_len, sim_consts.skin_r),
show_progress=show_progress,
) )
simulate!( simulate!(

View file

@ -132,7 +132,13 @@ function simulate!(
start_time = Dates.now() start_time = Dates.now()
println("Started simulation at $start_time.") println("Started simulation at $start_time.")
@showprogress 0.6 for (integration_step, t) in enumerate(T0:(args.δt):T) time_range = T0:(args.δt):T
progress = ProgressMeter.Progress(
length(time_range); dt=1, enabled=args.show_progress, desc="Simulation: "
)
for (integration_step, t) in enumerate(time_range)
if (integration_step % n_steps_before_snapshot == 0) && save_data if (integration_step % n_steps_before_snapshot == 0) && save_data
wait(task) wait(task)
@ -178,6 +184,8 @@ function simulate!(
end end
first_integration_step = false first_integration_step = false
ProgressMeter.next!(progress)
end end
wait(task) wait(task)