Skip to content

Commit

Permalink
Make perf config work without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Sep 18, 2023
1 parent d5bcde4 commit a1305a1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/solver/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ Creates a config from the following in order of top priority to last:
"""
function AtmosCoveragePerfConfig(;
s = argparse_settings(),
config_dict = nothing,
config_dict = Dict(),
)
parsed_args = parse_commandline(s)
if isnothing(config_dict)
if !isnothing(parsed_args["config_file"])
config_dict = YAML.load_file(parsed_args["config_file"])
end
target_job_config = if haskey(config_dict, "target_job")
Expand Down
58 changes: 58 additions & 0 deletions test/config.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Test
import ClimaAtmos as CA

@testset "AtmosCoveragePerfConfig" begin
# Just default config overridden by `default_perf.yml`
config = CA.AtmosCoveragePerfConfig()
# Test defaults overridden by `default_perf`
@test config.parsed_args["dt"] == "1secs"
# Test defaults not overridden by `default_perf`
@test config.parsed_args["y_elem"] == 6

# Test with `target_job`
config = CA.AtmosCoveragePerfConfig(;
config_dict = Dict("target_job" => "sphere_baroclinic_wave_rhoe"),
)
# Target job config overridden by `default_perf`
@test config.parsed_args["dt"] == "1secs"
# Target job config not overridden by `default_perf`
@test config.parsed_args["regression_test"] == true

# Test that config_file overrides `default_perf`
yaml_path = joinpath(
@__DIR__,
"..",
"config",
"model_configs",
"edmf_soares_jfnk_imex.yml",
)
args_str = "--config_file " * yaml_path
empty!(ARGS)
append!(ARGS, split(args_str, " "))
config = CA.AtmosCoveragePerfConfig()
@test config.parsed_args["dt"] == "50secs"
@test config.parsed_args["turbconv_case"] == "Soares"

empty!(ARGS)
# Test that config_dict overrides `default_perf`
config_dict = Dict("dt" => "50secs", "turbconv_case" => "GABLS")
config = CA.AtmosCoveragePerfConfig(; config_dict)
@test config.parsed_args["dt"] == "50secs"
@test config.parsed_args["turbconv_case"] == "GABLS"

# Test that `default_perf` overrides `target_job`
config = CA.AtmosCoveragePerfConfig(;
config_dict = Dict(
"target_job" => "sphere_baroclinic_wave_rhoe",
"turbconv_case" => "GABLS",
),
)
# config_dict
@test config.parsed_args["turbconv_case"] == "GABLS"
# default_perf
@test config.parsed_args["dt"] == "1secs"
# target_job
@test config.parsed_args["regression_test"] == true
# defaults
@test config.parsed_args["y_elem"] == 6
end

0 comments on commit a1305a1

Please sign in to comment.