diff --git a/Project.toml b/Project.toml index 96d8ebc..ba69134 100644 --- a/Project.toml +++ b/Project.toml @@ -11,6 +11,7 @@ ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" +Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" @@ -18,6 +19,7 @@ LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890" Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc" +OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7" ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/src/ReCo.jl b/src/ReCo.jl index cd1eb19..a37d6fa 100644 --- a/src/ReCo.jl +++ b/src/ReCo.jl @@ -2,6 +2,7 @@ module ReCo export init_sim, run_sim +include("utils.jl") include("PreVector.jl") include("Particle.jl") include("reinforcement_learning.jl") diff --git a/src/data.jl b/src/data.jl index 340171f..dd6e696 100644 --- a/src/data.jl +++ b/src/data.jl @@ -35,7 +35,7 @@ end function set_sim_state(dir::String, n_bundles::Int64, T::Float64) open("$dir/sim_state.json", "w") do f - JSON3.write(f, Dict("n_bundles" => n_bundles, "T" => round(T; digits=3))) + JSON3.write(f, (n_bundles=n_bundles, T=round(T; digits=3))) end return nothing diff --git a/src/run.jl b/src/run.jl index a53c1ee..250b128 100644 --- a/src/run.jl +++ b/src/run.jl @@ -13,7 +13,7 @@ function run_sim( ) @assert length(dir) > 0 @assert duration > 0 - @assert snapshot_at in 0.01:0.01:duration + @assert snapshot_at in 0.001:0.001:duration @assert n_steps_before_verlet_list_update >= 0 @assert seed > 0 @assert n_bundle_snapshots >= 0 diff --git a/src/utils.jl b/src/utils.jl new file mode 100644 index 0000000..16fcf30 --- /dev/null +++ b/src/utils.jl @@ -0,0 +1,16 @@ +using JSON3: JSON3 +using OrderedCollections: OrderedDict + +function struct_to_ordered_dict(s) + return OrderedDict(key => getfield(s, key) for key in propertynames(s)) +end + +function write_struct_to_json(s, path_without_extension::String) + ordered_dict = struct_to_ordered_dict(s) + + open("$path_without_extension.json", "w") do f + JSON3.write(f, ordered_dict) + end + + return nothing +end \ No newline at end of file