Skip to content

Commit

Permalink
parse repeats kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Nov 10, 2023
1 parent 4e20778 commit b697a25
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/TOMLInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])"))

Check warning on line 261 in src/TOMLInterface.jl

View check run for this annotation

Codecov / codecov/patch

src/TOMLInterface.jl#L261

Added line #L261 was not covered by tests
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)"))
Expand Down
9 changes: 9 additions & 0 deletions test/TOMLInterface/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/TOMLInterface/toml/uq_test_parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b697a25

Please sign in to comment.