From a1305a18c42f5930427e3977add9517940eb0dad Mon Sep 17 00:00:00 2001 From: nefrathenrici Date: Mon, 18 Sep 2023 16:36:50 -0700 Subject: [PATCH] Make perf config work without arguments --- src/solver/types.jl | 4 ++-- test/config.jl | 58 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/config.jl diff --git a/src/solver/types.jl b/src/solver/types.jl index 967cb239bcb..6e92b03104c 100644 --- a/src/solver/types.jl +++ b/src/solver/types.jl @@ -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") diff --git a/test/config.jl b/test/config.jl new file mode 100644 index 00000000000..bbca6684a71 --- /dev/null +++ b/test/config.jl @@ -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