Skip to content

Commit

Permalink
Move pre-existing output directory
Browse files Browse the repository at this point in the history
If a output_dir already exists, move it to `output_dir_YYYYMMDD_HHMM`
  • Loading branch information
Sbozzolo committed Jan 30, 2024
1 parent 8760f6e commit 4890ce1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
20 changes: 17 additions & 3 deletions examples/hybrid/driver.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
# When Julia 1.10+ is used interactively, stacktraces contain reduced type information to make them shorter.
# On the other hand, the full type information is printed when julia is not run interactively.
# On the other hand, the full type information is printed when julia is not run interactively.
# Given that ClimaCore objects are heavily parametrized, non-abbreviated stacktraces are hard to read,
# so we force abbreviated stacktraces even in non-interactive runs.
# (See also Base.type_limited_string_from_context())
redirect_stderr(IOContext(stderr, :stacktrace_types_limited => Ref(false)))
import ClimaAtmos as CA
import ClimaComms
import Random
import Base.Filesystem: rm, mv
import Dates
Random.seed!(1234)

if !(@isdefined config)
config = CA.AtmosConfig()
end
output_dir = CA.get_output_dir(config)
if ispath(output_dir)
if ClimaComms.iamroot(config.comms_ctx)
formatted_date = Dates.format(Dates.now(), "yyyymmdd_HHMM")
move_to = joinpath(
dirname(output_dir),
"$(basename(output_dir))_$formatted_date",
)
@warn "output_dir $output_dir found. Moving it to $move_to"
mv(output_dir, move_to)
end
ClimaComms.barrier(config.comms_ctx)
end
simulation = CA.get_simulation(config)
(; integrator) = simulation
sol_res = CA.solve_atmos!(simulation)
Expand All @@ -24,7 +40,6 @@ import ClimaAtmos.InitialConditions as ICs
using Statistics: mean
import ClimaAtmos.Parameters as CAP
import Thermodynamics as TD
import ClimaComms
using SciMLBase
using PrettyTables
import DiffEqCallbacks as DECB
Expand All @@ -34,7 +49,6 @@ using ClimaTimeSteppers
import JSON
using Test
import Tar
import Base.Filesystem: rm
import OrderedCollections
using ClimaCoreTempestRemap
using ClimaCorePlots, Plots
Expand Down
17 changes: 14 additions & 3 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ function get_callbacks(parsed_args, sim_info, atmos, params, comms_ctx)
return callbacks
end

function get_output_dir(config::AtmosConfig)
(; parsed_args) = config
job_id = if isnothing(parsed_args["job_id"])
job_id_from_config(parsed_args)
else
parsed_args["job_id"]
end
default_output = haskey(ENV, "CI") ? job_id : joinpath("output", job_id)
out_dir = parsed_args["output_dir"]
return isnothing(out_dir) ? default_output : out_dir
end

function get_sim_info(config::AtmosConfig)
(; parsed_args) = config
FT = eltype(config)
Expand All @@ -526,9 +538,8 @@ function get_sim_info(config::AtmosConfig)
else
parsed_args["job_id"]
end
default_output = haskey(ENV, "CI") ? job_id : joinpath("output", job_id)
out_dir = parsed_args["output_dir"]
output_dir = isnothing(out_dir) ? default_output : out_dir

output_dir = get_output_dir(config)
mkpath(output_dir)

sim = (;
Expand Down

0 comments on commit 4890ce1

Please sign in to comment.