I want to provide a struct with configuration variables (parameters) to my simulation.
I have a yaml file like this one:
system:
log_file: "data/log_8700W_8ms" # filename without extension [replay only]
time_lapse: 1.0 # relative replay speed
sim_time: 100.0 # simulation time [sim only]
(Well, in reality much bigger, see: https://github.com/ufechner7/KiteUtils.jl/blob/main/data/settings.yaml)
Now I would like to create the following struct automatically:
using Parameters
@with_kw mutable struct Settings @deftype Float64
log_file::String = ""
time_lapse = 0
sim_time = 0
end
const SETTINGS = Settings()
In addition I would like to autogenerate the code that reads the yaml file values
into the struct, like this:
function se(project)
dict = YAML.load_file(joinpath(DATA_PATH[1], project))
SETTINGS.log_file = dict["system"]["log_file"]
SETTINGS.time_lapse = dict["system"]["time_lapse"]
SETTINGS.sim_time = dict["system"]["sim_time"]
SETTINGS
end
What would be a good approach do do that?
Background:
I would like to provide a function se() to many modules and users such that they can
easily use the same settings in many modules of the project. It should also be
possible for them to add or delete parameters, but that would never happen frequently,
so if this generation process is slow that doesnβt matter.
What does matter is that the runtime access is fast, and in my inner loop I save
100ns if I have my parameters defined as constant mutable struct.