From b697a250bd0c54a334dd5349906563bcf7887e53 Mon Sep 17 00:00:00 2001 From: nefrathenrici Date: Fri, 10 Nov 2023 11:39:04 -0800 Subject: [PATCH] parse repeats kwarg --- src/TOMLInterface.jl | 20 +++++++++++++++++-- test/TOMLInterface/runtests.jl | 9 +++++++++ .../toml/uq_test_parameters.toml | 3 +++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/TOMLInterface.jl b/src/TOMLInterface.jl index eed0996b7..5ad9b1cc0 100644 --- a/src/TOMLInterface.jl +++ b/src/TOMLInterface.jl @@ -251,8 +251,24 @@ function get_distribution_from_expr(d::Expr) lower_bound = parse(Float64, string(d.args[5])) upper_bound = parse(Float64, string(d.args[6])) dist_type = getfield(Main, dist_type_symb) - - return constrained_gaussian(string(d.args[2]), d.args[3], d.args[4], lower_bound, upper_bound) + # Parse repeats kwarg + repeats = 1 + if length(d.args) > 6 + if d.args[7].head == :kw && d.args[7].args[1] == :repeats + repeats = d.args[7].args[2] + end + if length(d.args) > 7 + throw(ArgumentError("Unsupported arguments for TOMLInterface: $(d.args[8:end])")) + end + end + return constrained_gaussian( + string(d.args[2]), + d.args[3], + d.args[4], + lower_bound, + upper_bound, + repeats = repeats, + ) else throw(ArgumentError("Unknown distribution type from symbol: $(dist_type_symb)")) diff --git a/test/TOMLInterface/runtests.jl b/test/TOMLInterface/runtests.jl index f98b74d58..8d0296e36 100644 --- a/test/TOMLInterface/runtests.jl +++ b/test/TOMLInterface/runtests.jl @@ -53,6 +53,15 @@ const EKP = EnsembleKalmanProcesses ), "uq_param_9" => ParameterDistribution(Parameterized(Normal(4.0, 0.17881264846405112)), [bounded(0, Inf)], "uq_param_9"), + "uq_param_10" => ParameterDistribution( + VectorOfParameterized([ + Normal(4.0, 0.17881264846405112), + Normal(4.0, 0.17881264846405112), + Normal(4.0, 0.17881264846405112), + ]), + [bounded(0, Inf), bounded(0, Inf), bounded(0, Inf)], + "uq_param_10", + ), ) # Get all `ParameterDistribution`s. We also add dummy (key, value) pairs diff --git a/test/TOMLInterface/toml/uq_test_parameters.toml b/test/TOMLInterface/toml/uq_test_parameters.toml index 239020565..7898ccab1 100644 --- a/test/TOMLInterface/toml/uq_test_parameters.toml +++ b/test/TOMLInterface/toml/uq_test_parameters.toml @@ -44,6 +44,9 @@ constraint = "[no_constraint(), no_constraint(), bounded_below(-5.0)]" [uq_param_9] prior = "constrained_gaussian(uq_param_9, 55.47802418037957, 10, 0, Inf)" +[uq_param_10] +prior = "constrained_gaussian(uq_param_10, 55.47802418037957, 10, 0, Inf, repeats = 3)" + # The six parameters below are interpreted as "regular" (non-UQ) parameters, as they # they either have no key "prior", or a key "prior" that is set to "fixed" [mean_sea_level_pressure]