From ca97b43a4a3ab9e1d4fed3188a50affee06fc95b Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Mon, 25 Sep 2023 11:38:58 -0700 Subject: [PATCH] Move perf funcs to perf folder --- perf/benchmark.jl | 3 ++- perf/common.jl | 32 +++++++++++++++++++++++++ perf/flame.jl | 3 ++- perf/inference_flame_init.jl | 3 ++- perf/jet.jl | 5 ++-- perf/jet_test_nfailures.jl | 3 ++- src/solver/solve.jl | 3 ++- src/solver/types.jl | 46 ++++++++---------------------------- 8 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 perf/common.jl diff --git a/perf/benchmark.jl b/perf/benchmark.jl index cef75aeb021..0ef816892fa 100644 --- a/perf/benchmark.jl +++ b/perf/benchmark.jl @@ -1,7 +1,8 @@ import Random Random.seed!(1234) import ClimaAtmos as CA -config = CA.AtmosCoveragePerfConfig() +include("common.jl") +config = AtmosCoveragePerfConfig() integrator = CA.get_integrator(config) (; parsed_args) = config diff --git a/perf/common.jl b/perf/common.jl new file mode 100644 index 00000000000..dcbbb7b481b --- /dev/null +++ b/perf/common.jl @@ -0,0 +1,32 @@ +""" + AtmosCoveragePerfConfig() + AtmosCoveragePerfConfig(; config_dict) + +Creates a model configuration that covers many physics components. + +The configuration precedence is as follows: +1. Configuration from the given config file/dict (highest precedence) +2. Default perf configuration (to increase coverage) +3. Default configuration (lowest precedence) +""" +function AtmosCoveragePerfConfig(; config_dict = CA.default_config_dict()) + perf_defaults = joinpath( + dirname(@__FILE__), + "..", + "config", + "default_configs", + "default_perf.yml", + ) + perf_default_config = YAML.load_file(perf_defaults) + config_dict = merge(perf_default_config, config_dict) + return AtmosConfig(; config_dict) +end + +""" + AtmosTargetConfig() + AtmosTargetConfig(; target_job) + +Creates an AtmosConfig given the job ID (target_job). +""" +AtmosTargetConfig(; target_job) = + AtmosConfig(; config_dict = CA.config_from_target_job(target_job)) diff --git a/perf/flame.jl b/perf/flame.jl index 9fe702cccce..cb138d8cda7 100644 --- a/perf/flame.jl +++ b/perf/flame.jl @@ -1,7 +1,8 @@ import Random Random.seed!(1234) import ClimaAtmos as CA -config = CA.AtmosCoveragePerfConfig() +include("common.jl") +config = AtmosCoveragePerfConfig() integrator = CA.get_integrator(config) # The callbacks flame graph is very expensive, so only do 2 steps. diff --git a/perf/inference_flame_init.jl b/perf/inference_flame_init.jl index 11941391178..6877e74c13c 100644 --- a/perf/inference_flame_init.jl +++ b/perf/inference_flame_init.jl @@ -1,7 +1,8 @@ import Random Random.seed!(1234) import ClimaAtmos as CA -config = CA.AtmosCoveragePerfConfig() +include("common.jl") +config = AtmosCoveragePerfConfig() # To revive, define `args_integrator(::AtmosConfig)` and use that here integrator = CA.get_integrator(config) diff --git a/perf/jet.jl b/perf/jet.jl index 07e4e5f0ce2..a67f11264aa 100644 --- a/perf/jet.jl +++ b/perf/jet.jl @@ -1,9 +1,8 @@ import Random Random.seed!(1234) import ClimaAtmos as CA -config = CA.AtmosCoveragePerfConfig(; - config_dict = CA.config_from_target_job("edmfx_adv_test_box"), -) +include("common.jl") +config = CA.AtmosTargetConfig(; target_job = "edmfx_adv_test_box") integrator = CA.get_integrator(config) import JET diff --git a/perf/jet_test_nfailures.jl b/perf/jet_test_nfailures.jl index 8c6adf8272f..88373d2bd0a 100644 --- a/perf/jet_test_nfailures.jl +++ b/perf/jet_test_nfailures.jl @@ -1,7 +1,8 @@ import Random Random.seed!(1234) import ClimaAtmos as CA -config = CA.AtmosCoveragePerfConfig() +include("common.jl") +config = AtmosCoveragePerfConfig() integrator = CA.get_integrator(config) import JET diff --git a/src/solver/solve.jl b/src/solver/solve.jl index ea08f573eed..9bdb50ebf33 100644 --- a/src/solver/solve.jl +++ b/src/solver/solve.jl @@ -89,7 +89,8 @@ Then, to run interactively: import ClimaAtmos as CA import Random Random.seed!(1234) -config = CA.AtmosCoveragePerfConfig(); +include("common.jl") +config = AtmosCoveragePerfConfig(); integrator = CA.get_integrator(config); Y₀ = deepcopy(integrator.u); CA.benchmark_step!(integrator, Y₀); diff --git a/src/solver/types.jl b/src/solver/types.jl index 598cefa675b..7afb6efbb06 100644 --- a/src/solver/types.jl +++ b/src/solver/types.jl @@ -389,42 +389,6 @@ struct AtmosConfig{FT, TD, PA, C} comms_ctx::C end -""" - AtmosCoveragePerfConfig() - AtmosCoveragePerfConfig(; s, config_dict) -Creates a model configuration for many performance tests. -Creates a config from the following in order of top priority to last: -1. Configuration from the given config file/dict -2. Default perf configuration -3. Target job configuration -4. Default configuration -""" -function AtmosCoveragePerfConfig(; - s = argparse_settings(), - config_dict = nothing, -) - parsed_args = parse_commandline(s) - if isnothing(config_dict) - config_dict = YAML.load_file(parsed_args["config_file"]) - end - target_job_config = if haskey(config_dict, "target_job") - config_from_target_job(config_dict["target_job"]) - else - Dict() - end - perf_defaults = joinpath( - dirname(@__FILE__), - "..", - "..", - "config", - "default_configs", - "default_perf.yml", - ) - perf_default_config = YAML.load_file(perf_defaults) - config_dict = merge(target_job_config, perf_default_config, config_dict) - return AtmosConfig(; s, config_dict) -end - function AtmosConfig(; s = argparse_settings(), parsed_args = parse_commandline(s), @@ -439,6 +403,16 @@ function AtmosConfig(; @info "Using default configuration" default_config_dict() end + return AtmosConfig(config; comms_ctx) +end + +""" + AtmosConfig(config::Dict; comms_ctx = nothing) + +Creates an AtmosConfig given the `config` Dict and kwargs: + - `comms_ctx` (optional) ClimaComms context. +""" +function AtmosConfig(config::Dict; comms_ctx = nothing) FT = config["FLOAT_TYPE"] == "Float64" ? Float64 : Float32 toml_dict = CP.create_toml_dict( FT;