diff --git a/NEWS.md b/NEWS.md index d44232c0f99..414ba40306d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,13 @@ See the [documentation](https://clima.github.io/ClimaAtmos.jl/dev/contributor_g ### Features +### File Logging + +`ClimaAtmos` now supports logging to stdout and file simultaneously using +`ClimaComms.FileLogger`. This option is enabled by default. To disable, +run with `log_to_file = false`. See [ClimaComms documentation](https://clima.github.io/ClimaComms.jl/dev/logging/) + for more background on logging. + ### Read CO2 from file `ClimaAtmos` now support using data from the Mauna Loa CO2 measurements to set diff --git a/Project.toml b/Project.toml index 09cc5802cde..d17cd040867 100644 --- a/Project.toml +++ b/Project.toml @@ -41,7 +41,7 @@ ArgParse = "1" ArtifactWrappers = "0.2" Artifacts = "1" AtmosphericProfilesLibrary = "0.1.7" -ClimaComms = "0.6.4" +ClimaComms = "0.6.6" ClimaCore = "0.14.19" ClimaDiagnostics = "0.2.4" ClimaParams = "0.10.17" diff --git a/config/default_configs/default_config.yml b/config/default_configs/default_config.yml index d72848f224d..3d285b3c53a 100644 --- a/config/default_configs/default_config.yml +++ b/config/default_configs/default_config.yml @@ -345,3 +345,6 @@ updraft_number: radiation_reset_rng_seed: help: "Reset the RNG seed before calling RRTGMP to a known value (the timestep number). When modeling cloud optics, RRTGMP uses a random number generator. Resetting the seed every time RRTGMP is called to a deterministic value ensures that the simulation is fully reproducible and can be restarted in a reproducible way. Disable this option when running production runs. Please note that this flag is only used for `AllSkyRadiation` and `AllSkyRadiationWithClearSkyDiagnostics` radiation modes." value: false +log_to_file: + help: "Log to stdout and file simultaneously. The log file is saved within the output directory" + value: true diff --git a/config/mpi_configs/mpi_sphere_aquaplanet_rhoe_equilmoist_clearsky.yml b/config/mpi_configs/mpi_sphere_aquaplanet_rhoe_equilmoist_clearsky.yml index f3f1004cf60..d9af623991e 100644 --- a/config/mpi_configs/mpi_sphere_aquaplanet_rhoe_equilmoist_clearsky.yml +++ b/config/mpi_configs/mpi_sphere_aquaplanet_rhoe_equilmoist_clearsky.yml @@ -10,3 +10,4 @@ diagnostics: - short_name: [pfull, wa, va, rv] period: 1days writer: h5 +log_to_file: false diff --git a/examples/Manifest.toml b/examples/Manifest.toml index be00cee98f1..98205a87ac7 100644 --- a/examples/Manifest.toml +++ b/examples/Manifest.toml @@ -345,9 +345,9 @@ version = "0.28.2" [[deps.ClimaComms]] deps = ["Adapt", "Logging", "LoggingExtras"] -git-tree-sha1 = "d29ca07d91e6ca6c0a3649ad6cf37f2634951fd3" +git-tree-sha1 = "40ad44466dfe0092e18c04bc02c849fe8e095d30" uuid = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d" -version = "0.6.5" +version = "0.6.6" weakdeps = ["CUDA", "MPI"] [deps.ClimaComms.extensions] @@ -1229,9 +1229,9 @@ version = "1.0.0" [[deps.JET]] deps = ["CodeTracking", "InteractiveUtils", "JuliaInterpreter", "LoweredCodeUtils", "MacroTools", "Pkg", "PrecompileTools", "Preferences", "Test"] -git-tree-sha1 = "5c5ac91e775b585864015c5c1703cee283071a47" +git-tree-sha1 = "24bdbf3ef611b69d1f5ef9331e69b6007152989e" uuid = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" -version = "0.9.12" +version = "0.9.14" [deps.JET.extensions] JETCthulhuExt = "Cthulhu" @@ -2576,9 +2576,9 @@ version = "1.1.42+0" [[deps.XZ_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "beef98d5aad604d9e7d60b2ece5181f7888e2fd6" +git-tree-sha1 = "56c6604ec8b2d82cc4cfe01aa03b00426aac7e1f" uuid = "ffd25f8a-64ca-5728-b0f7-c24cf3aae800" -version = "5.6.4+0" +version = "5.6.4+1" [[deps.Xorg_libX11_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libxcb_jll", "Xorg_xtrans_jll"] diff --git a/src/solver/type_getters.jl b/src/solver/type_getters.jl index 675738a696d..832c662dbd5 100644 --- a/src/solver/type_getters.jl +++ b/src/solver/type_getters.jl @@ -9,6 +9,7 @@ import ClimaAtmos as CA import LinearAlgebra import ClimaCore.Fields import ClimaTimeSteppers as CTS +import Logging import ClimaDiagnostics @@ -502,7 +503,7 @@ function auto_detect_restart_file( end function get_sim_info(config::AtmosConfig) - (; parsed_args) = config + (; comms_ctx, parsed_args) = config FT = eltype(config) (; job_id) = config @@ -531,9 +532,21 @@ function get_sim_info(config::AtmosConfig) output_dir = OutputPathGenerator.generate_output_path( base_output_dir; - context = config.comms_ctx, + context = comms_ctx, style = output_dir_style, ) + if parsed_args["log_to_file"] + @info "Logging to $output_dir/output.log" + logger = ClimaComms.FileLogger(comms_ctx, output_dir) + Logging.global_logger(logger) + end + @info "Running on $(nameof(typeof(ClimaComms.device(comms_ctx))))" + if comms_ctx isa ClimaComms.SingletonCommsContext + @info "Setting up single-process ClimaAtmos run" + else + @info "Setting up distributed ClimaAtmos run" nprocs = + ClimaComms.nprocs(comms_ctx) + end isnothing(restart_file) || @info "Restarting simulation from file $restart_file" @@ -627,30 +640,10 @@ function get_comms_context(parsed_args) return comms_ctx end -""" - silence_non_root_processes(comms_ctx) - -Set the logging behavior based on the process rank within the given communication context `comms_ctx`. -If the process is the root process, logging is set to display messages to the console with `Info` level. -For all other processes, logging is silenced by setting it to a `NullLogger`. - -# Arguments -- `comms_ctx`: The communication context used to determine the rank of the process. - -""" -function silence_non_root_processes(comms_ctx) - # Set logging to only display for the root process - if ClimaComms.iamroot(comms_ctx) - Logging.global_logger(Logging.ConsoleLogger(stderr, Logging.Info)) - else - Logging.global_logger(Logging.NullLogger()) - end -end - function get_simulation(config::AtmosConfig) + sim_info = get_sim_info(config) params = ClimaAtmosParameters(config) atmos = get_atmos(config, params) - sim_info = get_sim_info(config) job_id = sim_info.job_id output_dir = sim_info.output_dir @info "Simulation info" job_id output_dir diff --git a/src/solver/types.jl b/src/solver/types.jl index ebdbe804ca6..9652ffbc42c 100644 --- a/src/solver/types.jl +++ b/src/solver/types.jl @@ -724,22 +724,7 @@ function AtmosConfig( override_file = CP.merge_toml_files(config["toml"]), ) comms_ctx = isnothing(comms_ctx) ? get_comms_context(config) : comms_ctx - device = ClimaComms.device(comms_ctx) - silence_non_root_processes(comms_ctx) - @info "Running on $(nameof(typeof(device)))" - if comms_ctx isa ClimaComms.SingletonCommsContext - @info "Setting up single-process ClimaAtmos run" - else - @info "Setting up distributed ClimaAtmos run" nprocs = - ClimaComms.nprocs(comms_ctx) - end - config = config_with_resolved_and_acquired_artifacts(config, comms_ctx) - if device isa ClimaComms.CPUMultiThreaded - @info "Running ClimaCore in threaded mode, with $(Threads.nthreads()) threads" - else - @info "Running ClimaCore in unthreaded mode" - end isempty(job_id) && @warn "`job_id` is empty and likely not passed to AtmosConfig"