Skip to content

Commit

Permalink
Merge default config files, get job_id from config
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed May 7, 2024
1 parent 43ddac5 commit 400833f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 111 deletions.
43 changes: 43 additions & 0 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,46 @@ prescribed_aerosols:
call_cloud_diagnostics_per_stage:
help: "A temporary Bool for calling cloud diagnostics every stage"
value: false
# EDMF configuration
turbconv:
help: "Turbulence convection scheme [`nothing` (default), 'prognostic_edmfx', 'diagnostic_edmfx']"
value: ~
advection_test:
help: "Switches off all grid-scale and subgrid-scale momentum tendencies [`false` (default), `true`]"
value: false
zero_tendency:
help: "Turns off tendencies [`nothing` (default), `grid_scale`, `subgrid_scale`]"
value: ~
implicit_sgs_advection:
help: "Whether to treat the subgrid-scale vertical advection tendency implicitly [`false` (default), `true`]"
value: false
edmf_coriolis:
help: "EDMF coriolis [`nothing` (default), `Bomex`,`LifeCycleTan2018`,`Rico`,`ARM_SGP`,`DYCOMS_RF01`,`DYCOMS_RF02`,`GABLS`]"
value: ~
edmfx_filter:
help: "If set to true, it switches on the relaxation of negative velocity in EDMFX. [`true`, `false` (default)]"
value: false
edmfx_nh_pressure:
help: "If set to true, it switches on EDMFX pressure drag closure. [`true`, `false` (default)]"
value: false
edmfx_entr_model:
help: "EDMFX entrainment closure. [`nothing` (default), `PiGroups`, `Generalized`, `GeneralizedHarmonics`]"
value: ~
edmfx_detr_model:
help: "EDMFX detrainment closure. [`nothing` (default), `PiGroups`, `Generalized`, `GeneralizedHarmonics`]"
value: ~
edmfx_upwinding:
help: "EDMFX upwinding mode [`none` (default), `first_order`, `third_order`]"
value: none
edmfx_sgsflux_upwinding:
help: "EDMFX SGS mass flux upwinding mode [`none` (default), `first_order`, `third_order`]"
value: none
edmfx_sgs_mass_flux:
help: "If set to true, it switches on EDMFX SGS mass flux. [`true`, `false` (default)]"
value: false
edmfx_sgs_diffusive_flux:
help: "If set to true, it switches on EDMFX SGS diffusive flux. [`true`, `false` (default)]"
value: false
updraft_number:
help: "Sets the number of updrafts for the EDMF scheme"
value: 1
43 changes: 0 additions & 43 deletions config/default_configs/default_edmf_config.yml

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Add an entry with the following format:
help: <help string>
```
The `help` field is optional if you don't plan on making a permanent change to the configuration argument.
If adding a configuration used in EDMF, add it to `.buildkite/default_edmf_config.yml`.

See below for the full list of configuration arguments.

Expand Down
2 changes: 0 additions & 2 deletions docs/src/config_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ function make_table_from_config_file(config_file, title)
end
default_configs = joinpath(ca_dir, "config", "default_configs")
default_config_file = joinpath(default_configs, "default_config.yml")
edmf_config_file = joinpath(default_configs, "default_edmf_config.yml")

make_table_from_config_file(default_config_file, "Default configuration")
make_table_from_config_file(edmf_config_file, "EDMF configuration")

nothing
26 changes: 14 additions & 12 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,29 +477,31 @@ thermo_state_type(::NonEquilMoistModel, ::Type{FT}) where {FT} =

# TODO: move to ClimaComms
context_short_name(ctx::ClimaComms.SingletonCommsContext) = "1_proc"
context_short_name(ctx::ClimaComms.MPICommsContext) = "mpi_$(ClimaComms.nprocs(ctx))"
context_short_name(ctx::ClimaComms.MPICommsContext) =
"mpi_$(ClimaComms.nprocs(ctx))"
device_short_name(dev::ClimaComms.CUDADevice) = "gpu"
device_short_name(dev::ClimaComms.CPUSingleThreaded) = "cpu"
device_short_name(dev::ClimaComms.CPUMultiThreaded) = "threaded_cpu_$(Threads.nthreads())"
resource_short_name(ctx::ClimaComms.AbstractCommsContext) = join(context_short_name(ctx), device_short_name(ctx), "_")
device_short_name(dev::ClimaComms.CPUMultiThreaded) =
"threaded_cpu_$(Threads.nthreads())"
resource_short_name(ctx::ClimaComms.AbstractCommsContext) =
join(context_short_name(ctx), device_short_name(ctx), "_")

function get_sim_info(config::AtmosConfig)
(; parsed_args) = config
FT = eltype(config)
context = config.comms_ctx

job_id = if isnothing(parsed_args["job_id"])
job_id_from_config(parsed_args)
else
parsed_args["job_id"]
end
job_id = join(
config_id_from_config_file(config.config_file),
resource_short_name(context),
"_",
)
default_output = haskey(ENV, "CI") ? job_id : joinpath("output", job_id)
out_dir = parsed_args["output_dir"]
base_output_dir = isnothing(out_dir) ? default_output : out_dir

output_dir = OutputPathGenerator.generate_output_path(
base_output_dir;
context = config.comms_ctx,
)
output_dir =
OutputPathGenerator.generate_output_path(base_output_dir; context)

sim = (;
output_dir,
Expand Down
30 changes: 7 additions & 23 deletions src/solver/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,34 +483,18 @@ Base.eltype(::AtmosConfig{FT}) where {FT} = FT
Helper function for the AtmosConfig constructor. Reads a YAML file into a Dict
and passes it to the AtmosConfig constructor.
"""
function AtmosConfig(config_file::String; comms_ctx = nothing)
config = YAML.load_file(config_file)
function AtmosConfig(
config_file::String = default_config_file;
comms_ctx = nothing,
)
config₀ = YAML.load_file(config_file)
config = strip_help_messages(config₀)
return AtmosConfig(config; comms_ctx, config_file)
end

"""
AtmosConfig(; comms_ctx = nothing)
Helper function for the AtmosConfig constructor.
Reads the `config_file` from the command line into a Dict
and passes it to the AtmosConfig constructor.
"""
function AtmosConfig(; comms_ctx = nothing)
parsed_args = parse_commandline(argparse_settings())
config_file = parsed_args["config_file"]
if config_file isa String
return AtmosConfig(config_file; comms_ctx)
elseif config_file isa Nothing
return AtmosConfig(config_file; comms_ctx, config_file)
else
error("`config_file` must be a Nothing or a String.")
end
end

AtmosConfig(config::Nothing; comms_ctx = nothing, config_file) =
AtmosConfig(Dict(); comms_ctx, config_file)

"""
AtmosConfig(config::Dict; comms_ctx = nothing)
Constructs the AtmosConfig from the Dict passed in. This Dict overrides all of
the default configurations set in `default_config_dict()`.
"""
Expand Down
44 changes: 14 additions & 30 deletions src/solver/yaml_helper.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
import YAML

const config_path = joinpath(dirname(@__FILE__), "..", "..", "config")

const default_config_file =
joinpath(config_path, "default_configs", "default_config.yml")

strip_help_messages(d) =
Dict(map(k -> Pair(k, d[k]["value"]), collect(keys(d))))

"""
default_config_dict()
default_config_dict(config_path)
default_config_dict(config_file)
Loads the default configuration from files into a Dict for use in AtmosConfig().
"""
function default_config_dict(
config_path = joinpath(
dirname(@__FILE__),
"..",
"..",
"config",
"default_configs",
),
)
default_config_file = joinpath(config_path, "default_config.yml")
config = YAML.load_file(default_config_file)
edmf_config_file = joinpath(config_path, "default_edmf_config.yml")
edmf_config = YAML.load_file(edmf_config_file)
# Combine base config with EDMF config - Don't allow duplicate entries.
!isempty(intersect(keys(config), keys(edmf_config))) &&
error("Duplicate keys in default config and EDMF config.")
merge!(config, edmf_config)
# Strip out help messages
for (k, v) in config
config[k] = v["value"]
end
return config
function default_config_dict(config_file = default_config_file)
config = YAML.load_file(config_file)
return strip_help_messages(config)
end

"""
Expand Down Expand Up @@ -119,12 +108,7 @@ To filter only configurations with a certain key/value pair,
use the `filter_name` keyword argument with a Pair.
"""
function configs_per_config_id(
directory::AbstractString = joinpath(
dirname(@__FILE__),
"..",
"..",
"config",
),
directory::AbstractString = config_path,
filter_name = nothing,
)
cmds = Dict()
Expand All @@ -149,7 +133,7 @@ end

function is_unique_basename(file, bname = first(splitext(basename(file))))
is_unique = true
for (root, _, files) in walkdir(first(splitpath(file)))
for (root, _, files) in walkdir(config_path)
for f in files
file = joinpath(root, f)
if basename(f) == bname
Expand Down

0 comments on commit 400833f

Please sign in to comment.