1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-09-19 19:01:17 +00:00

Delete old files

This commit is contained in:
Mo8it 2022-04-05 03:23:46 +02:00
parent eab5f7472b
commit a1516438ee
13 changed files with 0 additions and 1108 deletions

View file

@ -1,130 +0,0 @@
using Luxor
using ReCo: ReCo
function gen_COM_graphics()
box_length = 100
box_height = 100
L = 0.39 * box_length
R = 0.37 * box_length
A = -0.9 * L
B = 0.65 * L
particle_radius = 0.05 * L
Ap_vec = Vector(ReCo.Shape.project_to_unit_circle(A, L))
Bp_vec = Vector(ReCo.Shape.project_to_unit_circle(B, L))
for p in (Ap_vec, Bp_vec)
p[2] *= -1
end
Ap = Point(Ap_vec[1], Ap_vec[2])
Bp = Point(Bp_vec[1], Bp_vec[2])
M = R * ((Ap + Bp) / 2)
θ = atan(-M[2], M[1])
COM = ReCo.Shape.project_back_from_unit_circle(θ, L)
si, co = sincos(θ)
COMp = R * Point(co, -si)
##
graphics_export_dir = "exports/graphics/COM"
mkpath(graphics_export_dir)
Drawing(box_length, box_height, "$graphics_export_dir/linear.pdf")
origin()
fontsize(5)
setcolor("black")
arrow(Point(-1.1 * L, 0), Point(1.2 * L, 0); arrowheadlength=0.1 * L, linewidth=1.0)
green_orange = blend(Point(-1.5 * L, 0), Point(1.5 * L, 0))
addstop(green_orange, 0.0, "orange")
addstop(green_orange, (L) / (3 * L), "green")
addstop(green_orange, (2 * L) / (3 * L), "orange")
addstop(green_orange, 1.0, "green")
setblend(green_orange)
setline(1.0)
line(Point(-L, 0), Point(L, 0), :stroke)
setcolor("red")
setline(0.5)
for x in (-L, L)
line(Point(x, 0.05 * L), Point(x, -0.05 * L), :stroke)
end
setcolor("cyan3")
line(Point(0, 0.05 * L), Point(0, -0.05 * L), :stroke)
setcolor("blue")
for p in (A, B)
circle(Point(p, 0), particle_radius, :fill)
end
text("A", Point(A - 0.030 * L, -0.08 * L))
text("B", Point(B - 0.030 * L, -0.08 * L))
setcolor("brown")
circle(Point(COM, 0), particle_radius, :fill)
text("COM", Point(COM - 0.098 * L, -0.08 * L))
setcolor("black")
text("x", Point(1.2 * L, 0.038 * L))
text("-L/2", Point(-L - 0.15 * L, 0.20 * L))
text("0", Point(0 - 0.030 * L, 0.18 * L))
text("+L/2", Point(L - 0.15 * L, 0.20 * L))
finish()
##
Drawing(box_length, box_height, "$graphics_export_dir/circular_projection.pdf")
origin()
fontsize(5)
arrow(Point(-1.2 * R, 0), Point(1.2 * R, 0); arrowheadlength=0.1 * R, linewidth=1.0)
arrow(Point(0, 1.2 * R), Point(0, -1.2 * R); arrowheadlength=0.1 * R, linewidth=1.0)
setcolor("black")
text("α", Point(1.22 * R, 0.035 * R))
text("β", Point(-0.04 * R, -1.23 * R))
green_orange = blend(Point(0, -R), Point(0, R), "green", "orange")
setblend(green_orange)
setline(1.0)
circle(Point(0, 0), R, :stroke)
setcolor("red")
setline(0.5)
line(Point(1.05 * R, 0), Point(0.95 * R, 0), :stroke)
setcolor("cyan3")
line(Point(-1.05 * R, 0), Point(-0.95 * R, 0), :stroke)
setcolor("blue")
for pp in (Ap, Bp)
circle(R * pp, particle_radius, :fill)
end
text("A", 1.07 * R * Ap)
text("B", 1.14 * R * Bp)
setcolor("black")
setdash("dot")
line(R * Ap, R * Bp, :stroke)
line(Point(0, 0), COMp, :stroke)
setcolor("purple1")
circle(M, particle_radius, :fill)
text("COM'", 0.019 * R * M + R * Point(0.0, -0.04))
setcolor("brown")
circle(COMp, particle_radius, :fill)
text("COM", 0.029 * R * COMp)
finish()
return nothing
end

View file

@ -1,31 +0,0 @@
using CairoMakie
using LaTeXStrings: @L_str
include("../src/Visualization/common_CairoMakie.jl")
function gen_elliptical_distance_graphics()
init_cairomakie!()
fig = gen_figure()
ax = Axis(fig[1, 1]; xlabel=L"x", ylabel=L"y")
elliptical_b_a_ratio = 0.4
as = 1:1:3
for a in as
x = collect(LinRange(-a, a, 1000))
y = @. sqrt(a^2 - x^2) * elliptical_b_a_ratio
append!(x, reverse(x))
append!(y, reverse(-y))
lines!(x, y; label=L"a = %$a")
end
axislegend(ax; position=:rt, padding=3, rowgap=-3)
set_gaps!(fig)
save_fig("elliptical_distance.pdf", fig)
return nothing
end

View file

@ -1,115 +0,0 @@
using Luxor
using Random: Random
using StaticArrays: SVector
using ReCo: ReCo
function gen_periodic_boundary_conditions_graphics()
Random.seed!(23)
drawing_box_length = 300
graphics_export_dir = "exports/graphics"
mkpath(graphics_export_dir)
Drawing(
drawing_box_length,
drawing_box_length,
"$graphics_export_dir/periodic_boundary_conditions.pdf",
)
origin()
particle_radius = 10
box_len = drawing_box_length / 3
half_box_len = box_len / 2
N_in_one_box = 5
colors = ["red", "blue", "orange", "green", "cyan"]
distance_limit = 0.99 * 2 * particle_radius
particles = Vector{ReCo.Particle}(undef, 9 * N_in_one_box)
translation_vecs = [
SVector(0.0, 0.0),
SVector(box_len, 0.0),
SVector(box_len, box_len),
SVector(0.0, box_len),
SVector(-box_len, box_len),
SVector(-box_len, 0.0),
SVector(-box_len, -box_len),
SVector(0.0, -box_len),
SVector(box_len, -box_len),
]
p1_c = SVector(0.0, 0.0)
for p1_ind in 1:N_in_one_box
while true
x = (rand() - 0.5) * (box_len - 2 * particle_radius)
y = (rand() - 0.5) * (box_len - 2 * particle_radius)
p1_c = SVector(x, y)
no_collision = true
for p2_ind in 1:(p1_ind - 1)
if ReCo.norm2d(p1_c - particles[p2_ind].c) < distance_limit
no_collision = false
break
end
end
if no_collision
break
end
end
setcolor(colors[p1_ind])
for box_ind in 1:9
c = p1_c + translation_vecs[box_ind]
particle = ReCo.Particle(0, c, 0.0)
particles[p1_ind * box_ind] = particle
circle(c[1], c[2], particle_radius, :fill)
end
end
setcolor("black")
setline(1.0)
for line_factor in (-3, -1, 1, 3)
line(
Point(line_factor * drawing_box_length / 6, drawing_box_length / 2),
Point(line_factor * drawing_box_length / 6, -drawing_box_length / 2),
:stroke,
)
line(
Point(drawing_box_length / 2, line_factor * drawing_box_length / 6),
Point(-drawing_box_length / 2, line_factor * drawing_box_length / 6),
:stroke,
)
end
p1_ind = 3
p2_ind = 5
p1_c = particles[p1_ind].c
p2_c = particles[p2_ind].c
normal_vec_form_p1_to_p2 = p2_c - p1_c
min_image_vec = ReCo.restrict_coordinates(normal_vec_form_p1_to_p2, half_box_len)
min_image_vec_from_p1 = p1_c + min_image_vec
setcolor("black")
arrow(Point(p1_c[1], p1_c[2]), Point(p2_c[1], p2_c[2]); linewidth=2.0)
setcolor("red")
arrow(
Point(p1_c[1], p1_c[2]),
Point(min_image_vec_from_p1[1], min_image_vec_from_p1[2]);
linewidth=2.0,
)
finish()
return nothing
end

View file

@ -1,60 +0,0 @@
using CairoMakie
using LaTeXStrings: @L_str
include("../src/Visualization/common_CairoMakie.jl")
const minimum_r_σ_ratio = 2^(1 / 6)
function U_LJ_ϵ_ratio(r_σ_ratio::Real)
σ_r_ratio⁶ = r_σ_ratio^(-6)
return 4 * (σ_r_ratio⁶^2 - σ_r_ratio⁶)
end
function U_WCA_ϵ_ratio(r_σ_ratio::Real)
if r_σ_ratio > minimum_r_σ_ratio
return zero(r_σ_ratio)
else
return U_LJ_ϵ_ratio(r_σ_ratio) + 1
end
end
function plot_potentials()
init_cairomakie!()
fig = gen_figure()
max_x = 2.5
max_y = 1.05
min_y = -max_y
ax = Axis(
fig[1, 1]; xlabel=L"r / σ", ylabel=L"U(r) / ϵ", limits=(0.88, max_x, min_y, max_y)
)
r_σ_ratio = LinRange(0.95, max_x, 1000)
LJ = lines!(ax, r_σ_ratio, U_LJ_ϵ_ratio.(r_σ_ratio))
WCA = lines!(ax, r_σ_ratio, U_WCA_ϵ_ratio.(r_σ_ratio))
minimum_r_σ_ratio_line = lines!(
ax,
[minimum_r_σ_ratio, minimum_r_σ_ratio],
[min_y, max_y];
linestyle=:dash,
linewidth=1,
)
Legend(
fig[1, 2],
[LJ, WCA, minimum_r_σ_ratio_line],
[L"U_{LJ}", L"U_{WCA}", L"\frac{r}{σ} = 2^{1/6}"],
)
set_gaps!(fig)
save_fig("potential.pdf", fig)
return nothing
end

View file

@ -1,87 +0,0 @@
using Luxor
using Random: Random
using StaticArrays: SVector
using ReCo: ReCo
function gen_rdf_graphics()
Random.seed!(1)
box_length = 100
graphics_export_dir = "exports/graphics"
mkpath(graphics_export_dir)
Drawing(box_length, box_length, "$graphics_export_dir/rdf_shells.pdf")
origin()
particle_radius = 6
Δr = 2.4 * particle_radius
setcolor("blue")
circle(Point(0, 0), particle_radius, :fill)
N = 50
selected_shell_ind = 3
selected_lower_radius = (selected_shell_ind - 1) * Δr
particle_cs = Vector{SVector{2,Float64}}(undef, N)
distance_limit = 0.99 * 2 * particle_radius
x = y = distance = 0.0
for p1_ind in 1:N
while true
x = (rand() - 0.5) * box_length
y = (rand() - 0.5) * box_length
p1_c = SVector(x, y)
distance = ReCo.norm2d(p1_c)
no_collision = true
if distance >= distance_limit
for p2_ind in 1:(p1_ind - 1)
if ReCo.norm2d(p1_c - particle_cs[p2_ind]) < distance_limit
no_collision = false
break
end
end
if no_collision
particle_cs[p1_ind] = p1_c
break
end
end
end
if selected_lower_radius <= distance < selected_lower_radius + Δr
setcolor("green")
else
setcolor("orange")
end
circle(x, y, particle_radius, :fill)
end
setcolor("black")
setline(0.2)
for shell_ind in 1:ceil(Int64, (box_length - 1) / 2 / Δr)
circle(Point(0, 0), shell_ind * Δr, :stroke)
end
setcolor("red")
setline(0.3)
line(Point(0, 0), Point(Δr, 0), :stroke)
fontsize(4.5)
text("Δr", Point(0.44 * Δr, -0.05 * Δr))
finish()
return nothing
end

View file

@ -1,29 +0,0 @@
using CairoMakie
using LaTeXStrings: @L_str
using ReCo: ReCo
include("../src/Visualization/common_CairoMakie.jl")
function plot_reward_function()
init_cairomakie!()
fig = gen_figure()
min_x = 0.0
max_x = 1.15
ax = Axis(
fig[1, 1]; xlabel=L"x / x_{\max}", ylabel=L"R(x)", limits=(min_x, max_x, 0.0, 1.05)
)
x = LinRange(min_x, max_x, 1000)
lines!(ax, x, ReCo.RL.minimizing_reward.(x, 1.0))
set_gaps!(fig)
save_fig("reward_shaping.pdf", fig)
return nothing
end

View file

@ -1,96 +0,0 @@
using Luxor
using Random: Random
using StaticArrays: SVector
using ReCo: ReCo
function gen_verlet_and_cell_lists_graphics()
Random.seed!(3)
box_length = 100
graphics_export_dir = "exports/graphics"
mkpath(graphics_export_dir)
Drawing(box_length, box_length, "$graphics_export_dir/verlet_and_cell_lists.pdf")
origin()
R_particle = 4.2
σ = 2 * R_particle * 2^(-1 / 6)
R_interaction = 2^(1 / 6) * σ
R_skin = ReCo.DEFAULT_SKIN_TO_INTERACTION_RADIUS_RATIO * R_interaction
setcolor("blue")
reference_particle_x = 0.25 * R_skin
reference_particle_y = -0.1 * R_skin
circle(Point(reference_particle_x, reference_particle_y), R_particle, :fill)
reference_particle_c = SVector(reference_particle_x, reference_particle_y)
N = 107
particle_cs = Vector{SVector{2,Float64}}(undef, N)
distance_limit = 0.98 * 2 * R_particle
x = y = distance = 0.0
for p1_ind in 1:N
while true
x = (rand() - 0.5) * box_length
y = (rand() - 0.5) * box_length
p1_c = SVector(x, y)
distance = ReCo.norm2d(p1_c - reference_particle_c)
no_collision = true
if distance >= distance_limit
for p2_ind in 1:(p1_ind - 1)
if ReCo.norm2d(p1_c - particle_cs[p2_ind]) < distance_limit
no_collision = false
break
end
end
if no_collision
particle_cs[p1_ind] = p1_c
break
end
end
end
if distance < R_interaction
setcolor("red")
elseif R_interaction <= distance < R_skin
setcolor("green")
else
setcolor("orange")
end
circle(x, y, R_particle, :fill)
end
setcolor("black")
setline(0.28)
for R in (R_interaction, R_skin)
circle(Point(reference_particle_x, reference_particle_y), R, :stroke)
end
half_n_lines = floor(Int64, box_length / (2 * R_skin) + 0.5)
for i in 1:half_n_lines
coordinate = (i - 0.5) * R_skin
line(Point(coordinate, -box_length), Point(coordinate, box_length), :stroke)
line(Point(-coordinate, -box_length), Point(-coordinate, box_length), :stroke)
line(Point(-box_length, coordinate), Point(box_length, coordinate), :stroke)
line(Point(-box_length, -coordinate), Point(box_length, -coordinate), :stroke)
end
setcolor((0.2, 0.0, 1.0, 0.3))
rect(-1.5 * R_skin, -1.5 * R_skin, 3 * R_skin, 3 * R_skin, :fill)
finish()
return nothing
end

View file

@ -1,49 +0,0 @@
module Benchmark
using Statistics: mean
using Dates: Dates
using BenchmarkTools: @benchmark
using JSON3: JSON3
using ReCo
function run_benchmarks(
dir::String="";
n_particles::Int64=1000,
v₀::Float64=20.0,
duration::Float64=2.0,
n_bundle_snapshots::Int64=0,
comment="",
)
if length(dir) == 0
dir = init_sim(; n_particles=n_particles, v₀=v₀, parent_dir="benchmark")
end
benchmark = @benchmark run_sim(
$dir; duration=$duration, n_bundle_snapshots=$n_bundle_snapshots
)
display(benchmark)
open("exports/benchmark.txt", "a+") do f
JSON3.pretty(
f,
Dict(
"n_particles" => n_particles,
"v₀" => v₀,
"duration" => duration,
"n_bundle_snapshots" => n_bundle_snapshots,
"comment" => comment,
"datetime" => Dates.now(),
"mean_time/ns" => mean(benchmark.times),
"allocs" => benchmark.allocs,
"memory" => benchmark.memory,
),
)
write(f, "\n")
end
return dir
end
end # module

View file

@ -1,282 +0,0 @@
module Animation
export animate
using GLMakie
using ColorSchemes: ColorSchemes
using LaTeXStrings: @L_str
using JLD2: JLD2
using ProgressMeter: ProgressMeter
using ..ReCo: ReCo
include("common.jl")
const DEFAULT_FRAMERATE = 10
const DEFAULT_SHOW_CENTER_OF_MASS = false
const DEFAULT_SHOW_INTERACTION_CIRCLE = false
const DEFAULT_SHOW_SKIN_CIRCLE = false
const DEFAULT_SHOW_FRAME_DIFF = false
const DEFAULT_SHOW_PROGRESS = false
function animate_bundle!(args, sim_consts::ReCo.SimConsts)
bundle_t = args.bundle.t
bundle_c = args.bundle.c
bundle_φ = args.bundle.φ
for bundle_snapshot in 1:length(bundle_t)
@simd for particle_ind in 1:(sim_consts.n_particles)
c = bundle_c[particle_ind, bundle_snapshot]
φ = bundle_φ[particle_ind, bundle_snapshot]
args.particle_xs[][particle_ind] = c[1]
args.particle_ys[][particle_ind] = c[2]
color = angle_color(φ, args.color_scheme)
args.particle_colors[][particle_ind] = color
if args.show_interaction_circle
args.interaction_colors[][particle_ind] = ColorSchemes.ColorTypes.RGBA(
color, 0.08
)
end
if args.show_skin_circle
args.skin_colors[][particle_ind] = ColorSchemes.ColorTypes.RGBA(color, 0.04)
end
end
if args.show_center_of_mass
center_of_mass = ReCo.center_of_mass(
view(bundle_c, :, bundle_snapshot), sim_consts.half_box_len
)
args.center_of_mass_point[] = Point(center_of_mass)
end
if args.n_bundle == 1 && bundle_snapshot == 1
scatter!(
args.ax,
args.particle_xs,
args.particle_ys;
markersize=2 * sim_consts.particle_radius,
markerspace=SceneSpace,
color=args.particle_colors,
)
if args.show_center_of_mass
scatter!(
args.ax,
args.center_of_mass_point;
markersize=6 * sim_consts.particle_radius,
markerspace=SceneSpace,
color=ColorSchemes.ColorTypes.RGBA(1.0, 1.0, 1.0, 0.6),
)
end
if args.show_interaction_circle
scatter!(
args.ax,
args.particle_xs,
args.particle_ys;
markersize=2 * sim_consts.interaction_radius,
markerspace=SceneSpace,
color=args.interaction_colors,
)
end
if args.show_skin_circle
scatter!(
args.ax,
args.particle_xs,
args.particle_ys;
markersize=2 * sim_consts.skin_radius,
markerspace=SceneSpace,
color=args.skin_colors,
)
end
println("Recording started!")
else
if args.show_frame_diff && bundle_snapshot > 1
@simd for i in 1:(sim_consts.n_particles)
first_ind = 2 * i - 1
second_ind = 2 * i
frame_min_1 = bundle_snapshot - 1
args.segment_xs[][first_ind] = bundle_c[i, frame_min_1][1]
args.segment_xs[][second_ind] = bundle_c[i, bundle_snapshot][1]
args.segment_ys[][first_ind] = bundle_c[i, frame_min_1][2]
args.segment_ys[][second_ind] = bundle_c[i, bundle_snapshot][2]
end
if bundle_snapshot == 2
linesegments!(
args.ax,
args.segment_xs,
args.segment_ys;
color=args.particle_colors,
)
end
notify(args.segment_xs)
notify(args.segment_ys)
end
notify(args.particle_xs)
notify(args.particle_ys)
notify(args.particle_colors)
if args.show_center_of_mass
notify(args.center_of_mass_point)
end
if args.show_interaction_circle
notify(args.interaction_colors)
end
if args.show_skin_circle
notify(args.skin_colors)
end
end
args.ax.title = "t = $(round(bundle_t[bundle_snapshot], digits=3))"
recordframe!(args.io)
end
return nothing
end
"""
animate(sim_dir::String; <keyword arguments>)
Animate a simulation.
The output is `sim_dir/animation.mkv`.
Return `nothing`.
# Arguments
- `sim_dir::String`: Simulation directory.
- `framerate::Int64=$DEFAULT_FRAMERATE`: Framerate
- `show_center_of_mass::Bool=$DEFAULT_SHOW_CENTER_OF_MASS`: Show the center of mass as transparent white circle.
- `show_interaction_circle::Bool=$DEFAULT_SHOW_INTERACTION_CIRCLE`: Show the interaction radius with a circle around every particle.
- `show_skin_circle::Bool=$DEFAULT_SHOW_SKIN_CIRCLE`: Show the skin radius with a circle around every particle.
- `show_frame_diff::Bool=$DEFAULT_SHOW_FRAME_DIFF`: Show the translation of particles between two frames as lines connecting the old and new position. This is helpful to recognize unwanted jumps.
- `show_progress::Bool=$DEFAULT_SHOW_PROGRESS`: Show animation progress bar.
"""
function animate(
sim_dir::String;
framerate::Int64=DEFAULT_FRAMERATE,
show_center_of_mass::Bool=DEFAULT_SHOW_CENTER_OF_MASS,
show_interaction_circle::Bool=DEFAULT_SHOW_INTERACTION_CIRCLE,
show_skin_circle::Bool=DEFAULT_SHOW_SKIN_CIRCLE,
show_frame_diff::Bool=DEFAULT_SHOW_FRAME_DIFF,
show_progress::Bool=DEFAULT_SHOW_PROGRESS,
)
println("Initializing GLMakie...")
GLMakie.activate!()
set_theme!(theme_black())
fig = Figure(; resolution=(1080, 1080))
sim_consts = ReCo.load_sim_consts(sim_dir)
ax, color_scheme = gen_axis_and_colorbar(fig, sim_consts)
n_particles = sim_consts.n_particles
animation_path = "$sim_dir/animation.mkv"
record(fig, animation_path; framerate=framerate) do io
particle_xs = Observable(Vector{Float64}(undef, n_particles))
particle_ys = Observable(Vector{Float64}(undef, n_particles))
particle_colors = Observable(
Vector{ColorSchemes.ColorTypes.RGB{Float64}}(undef, n_particles)
)
center_of_mass_point =
segment_xs =
segment_ys =
interaction_circle_xs =
interaction_circle_ys =
skin_circle_xs =
skin_circle_ys = interaction_colors = skin_colors = nothing
if show_center_of_mass
center_of_mass_point = Observable(Point2(0.0, 0.0))
end
if show_interaction_circle
interaction_circle_xs = Observable(Vector{Float64}(undef, n_particles))
interaction_circle_ys = Observable(Vector{Float64}(undef, n_particles))
interaction_colors = Observable(
Vector{ColorSchemes.ColorTypes.RGBA{Float64}}(undef, n_particles)
)
end
if show_skin_circle
skin_circle_xs = Observable(Vector{Float64}(undef, n_particles))
skin_circle_ys = Observable(Vector{Float64}(undef, n_particles))
skin_colors = Observable(
Vector{ColorSchemes.ColorTypes.RGBA{Float64}}(undef, n_particles)
)
end
if show_frame_diff
segment_xs = Observable(zeros(Float64, 2 * n_particles))
segment_ys = Observable(zeros(Float64, 2 * n_particles))
end
bundle_paths = ReCo.sorted_bundle_paths(sim_dir)
progress = ProgressMeter.Progress(
length(bundle_paths); dt=2, enabled=show_progress, desc="Animation: "
)
for (n_bundle, bundle_path) in enumerate(bundle_paths)
bundle::ReCo.Bundle = JLD2.load_object(bundle_path)
args = (;
# Input
show_center_of_mass,
show_interaction_circle,
show_skin_circle,
show_frame_diff,
# Internal
io,
ax,
bundle,
particle_xs,
particle_ys,
particle_colors,
center_of_mass_point,
segment_xs,
segment_ys,
interaction_circle_xs,
interaction_circle_ys,
skin_circle_xs,
skin_circle_ys,
interaction_colors,
skin_colors,
color_scheme,
n_bundle,
)
animate_bundle!(args, sim_consts)
ProgressMeter.next!(progress)
end
end
println("Animation done.")
return nothing
end
end # module

View file

@ -1,54 +0,0 @@
module RewardsPlot
export plot_rewards
using CairoMakie
using JLD2: JLD2
using ReCo: ReCo
include("common_CairoMakie.jl")
const DEFAULT_ENV_HELPER_FILENAME = "env_helper.jld2"
function plot_rewards_from_env_helper(; env_helper::ReCo.RL.EnvHelper, rl_dir::String)
rewards = env_helper.shared.hook.rewards
n_episodes = length(rewards)
init_cairomakie!()
fig = gen_figure(; padding=10)
ax = Axis(
fig[1, 1]; xlabel="Episode", ylabel="Reward", limits=((0, n_episodes), nothing)
)
lines!(ax, 1:n_episodes, rewards)
set_gaps!(fig)
save_fig("rewards.pdf", fig; parent_dir=rl_dir)
return nothing
end
"""
plot_rewards(rl_dir::String, env_helper_filename::String="$DEFAULT_ENV_HELPER_FILENAME")
Plot the rewards of the reinforcement learning process at the directory `rl_dir`.
The output is `rl_dir/rewards.pdf`. `env_helper_filename` can be provided if the name of the `jld2`-file of the environment helper differs from the default `$DEFAULT_ENV_HELPER_FILENAME`.
Return `nothing`.
"""
function plot_rewards(
rl_dir::String, env_helper_filename::String=DEFAULT_ENV_HELPER_FILENAME
)
env_helper::ReCo.RL.EnvHelper = JLD2.load_object("$rl_dir/$env_helper_filename")
plot_rewards_from_env_helper(; env_helper, rl_dir)
return nothing
end
end # module

View file

@ -1,115 +0,0 @@
module SnapshotPlot
export plot_snapshot
using CairoMakie
using ColorSchemes: ColorSchemes
using LaTeXStrings: @L_str
using ..ReCo: ReCo
include("common.jl")
include("common_CairoMakie.jl")
const DEFAULT_SHOW_CENTER_OF_MASS = false
const DEFAULT_SHOW_KAPPA = true
function get_wanted_snapshot_number(total_n_snapshots::Int64)
print("There are $total_n_snapshots snapshots. Enter the wanted snapshot number: ")
answer = readline()
snapshot = parse(Int64, answer)
return snapshot
end
"""
plot_snapshot(sim_dir::String; <keyword arguments>)
Plot one snapshot of a simulation.
The function will ask for the number of the snapshot to plot out of the total number of snapshots. The output is `sim_dir/graphics/N.pdf` with `N` as the number of the chosen snapshot.
# Arguments
- `sim_dir::String`: Simulation directory.
- `show_center_of_mass::Bool=$DEFAULT_SHOW_CENTER_OF_MASS`: Show the center of mass as a transparent black circle.
- `show_κ::Bool=$DEFAULT_SHOW_KAPPA`: Show κ as the ratio of the eigenvalues of the gyration tensor.
"""
function plot_snapshot(
sim_dir::String;
show_center_of_mass::Bool=DEFAULT_SHOW_CENTER_OF_MASS,
show_κ::Bool=DEFAULT_SHOW_KAPPA,
)
bundles_info = ReCo.BundlesInfo(sim_dir)
wanted_snapshot_out_of_total = get_wanted_snapshot_number(
bundles_info.total_n_snapshots
)
bundle, bundle_snapshot = ReCo.get_bundle_to_snapshot(
bundles_info, wanted_snapshot_out_of_total
)
sim_consts = ReCo.load_sim_consts(sim_dir)
println("Initializing CairoMakie...")
init_cairomakie!()
fig = gen_figure()
cs_view = view(bundle.c, :, bundle_snapshot)
center_of_mass = ReCo.center_of_mass(cs_view, sim_consts.half_box_len)
if show_κ
eigvals_ratio = ReCo.gyration_tensor_eigvals_ratio(
cs_view, sim_consts.half_box_len, center_of_mass
)
κ = round(eigvals_ratio; digits=2)
title = L"\kappa = %"
ax, color_scheme = gen_axis_and_colorbar(fig, sim_consts; axis_title=title)
else
ax, color_scheme = gen_axis_and_colorbar(fig, sim_consts)
end
particle_xs = Vector{Float64}(undef, sim_consts.n_particles)
particle_ys = Vector{Float64}(undef, sim_consts.n_particles)
particle_colors = Vector{ColorSchemes.ColorTypes.RGB}(undef, sim_consts.n_particles)
@simd for particle_ind in 1:(sim_consts.n_particles)
c = bundle.c[particle_ind, bundle_snapshot]
φ = bundle.φ[particle_ind, bundle_snapshot]
color = angle_color(φ, color_scheme)
particle_xs[particle_ind] = c[1]
particle_ys[particle_ind] = c[2]
particle_colors[particle_ind] = color
end
scatter!(
ax,
particle_xs,
particle_ys;
markersize=2 * sim_consts.particle_radius,
markerspace=SceneSpace,
color=particle_colors,
)
if show_center_of_mass
scatter!(
ax,
Point(center_of_mass);
markersize=6 * sim_consts.particle_radius,
markerspace=SceneSpace,
color=ColorSchemes.ColorTypes.RGBA(0.0, 0.0, 0.0, 0.6),
)
end
set_gaps!(fig)
save_fig("$wanted_snapshot_out_of_total.pdf", fig; parent_dir="$sim_dir/graphics")
return nothing
end
end # module

View file

@ -1,29 +0,0 @@
using ColorSchemes
function angle_color(φ::Float64, color_scheme::ColorSchemes.ColorScheme)
return get(color_scheme, rem2pi(φ, RoundDown) / (2 * π))
end
function gen_axis_and_colorbar(
fig, sim_consts::ReCo.SimConsts; axis_title::AbstractString=""
)
ax = Axis(
fig[1, 1];
limits=(
-sim_consts.half_box_len,
sim_consts.half_box_len,
-sim_consts.half_box_len,
sim_consts.half_box_len,
),
aspect=AxisAspect(1),
xlabel=L"x",
ylabel=L"y",
title=axis_title,
)
color_scheme = ColorSchemes.cyclic_mrybm_35_75_c68_n256_s25
Colorbar(fig[1, 2]; limits=(0, 2), colormap=color_scheme, label=L"\varphi / \pi")
return (ax, color_scheme)
end

View file

@ -1,31 +0,0 @@
function init_cairomakie!()
CairoMakie.activate!()
set_theme!()
return nothing
end
function gen_figure(; padding=5)
text_width_in_pt = 405
return Figure(;
resolution=(text_width_in_pt, 0.55 * text_width_in_pt),
fontsize=10,
figure_padding=padding,
)
end
function set_gaps!(fig::Figure)
colgap!(fig.layout, 5)
rowgap!(fig.layout, 5)
return nothing
end
function save_fig(filename::String, fig::Figure; parent_dir="exports/graphics")
mkpath(parent_dir)
save("$parent_dir/$filename", fig; pt_per_unit=1)
return nothing
end