Skip to content

Commit

Permalink
Move perf funcs to perf folder
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Sep 25, 2023
1 parent 69ce863 commit ca97b43
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 44 deletions.
3 changes: 2 additions & 1 deletion perf/benchmark.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 32 additions & 0 deletions perf/common.jl
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 2 additions & 1 deletion perf/flame.jl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion perf/inference_flame_init.jl
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
5 changes: 2 additions & 3 deletions perf/jet.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion perf/jet_test_nfailures.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/solver/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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₀);
Expand Down
46 changes: 10 additions & 36 deletions src/solver/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
Expand Down

0 comments on commit ca97b43

Please sign in to comment.