Skip to content

Commit

Permalink
Remove Adapt dependency
Browse files Browse the repository at this point in the history
Replace interpolation op with
generalised spacevaryingutility tools.
  • Loading branch information
akshaysridhar committed Oct 23, 2024
1 parent 09ca71a commit 266d885
Show file tree
Hide file tree
Showing 26 changed files with 597 additions and 487 deletions.
11 changes: 6 additions & 5 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ steps:
- label: "end to end test"
command: julia --project=calibration/test calibration/test/e2e_test.jl
artifact_paths: "calibration_end_to_end_test/*"
soft_fail: true

- group: "Diagnostic EDMFX"
steps:
Expand Down Expand Up @@ -1184,11 +1185,11 @@ steps:
- label: ":bar_chart: Tabulate performance summary"
command: "julia --color=yes --project=perf perf/tabulate_perf_summary.jl"

- label: ":chart_with_downwards_trend: build history"
command:
- build_history main
artifact_paths:
- "build_history.html"
# - label: ":chart_with_downwards_trend: build history"
# command:
# - build_history main
# artifact_paths:
# - "build_history.html"

- wait

Expand Down
11 changes: 11 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ git-tree-sha1 = "6693f8451b447543952b3d557d733c7e5c670ed3"
[[ozone_concentrations_lowres.download]]
sha256 = "908384b32e90c733c2173654afbb974d238a9a516ad8965039077c6ddb29b5f0"
url = "https://caltech.box.com/shared/static/6c16wt7i1htxq6tadpt1ng2uftjgdtpr.gz"

[earth_orography_30arcseconds]
git-tree-sha1 = "03dd08fcbf363ed055a176dd7adefb60ff1c3493"

[earth_orography_60arcseconds]
git-tree-sha1 = "fe19d8dbe7a18ff39588e1f718014b0479d9c0f7"
lazy = true

[[earth_orography_60arcseconds.download]]
sha256 = "eca66c0701d1c2b9e271742314915ffbf4a0fae92709df611c323f38e019966e"
url = "https://caltech.box.com/shared/static/4asrxcgl6xsgenfcug9p0wkkyhtqilgk.gz"
16 changes: 15 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ ClimaAtmos.jl Release Notes
Main
-------

v0.27.7
-------

### Reproducible restarts for simulations with clouds with RRTMGP

- Reset the RNG seed before calling RRTGMP to a known value (the iteration 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.

Note: Setting this option to `true` is behavior-changing.
PR [3382](https://github.com/CliMA/ClimaAtmos.jl/pull/3382)

### ![][badge-🐛bugfix] Bug fixes

- Update RRTMGP to v0.19.1, which fixes the sea salt aerosol lookup table.
Sea salt aerosol is added to the target amip config.
Sea salt aerosol is added to the target amip config.
PR [3374](https://github.com/CliMA/ClimaAtmos.jl/pull/3374)

- Fixed radiation diagnostics conflicting with each other. Prior to this change,
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaAtmos"
uuid = "b2c96348-7fb7-4fe0-8da9-78d88439e717"
authors = ["Climate Modeling Alliance"]
version = "0.27.6"
version = "0.27.7"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -27,6 +27,7 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NVTX = "5da4648a-3479-48b8-97b9-01cb529c0a1f"
RRTMGP = "a01a1ee8-cea4-48fc-987c-fc7878d79da1"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down Expand Up @@ -59,6 +60,7 @@ Logging = "1"
NCDatasets = "0.14.2"
NVTX = "0.3"
RRTMGP = "0.19"
Random = "1"
SciMLBase = "2.12"
StaticArrays = "1.7"
Statistics = "1"
Expand Down
2 changes: 1 addition & 1 deletion calibration/test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
ClimaCalibrate = "0.0.2, 0.0.3"
ClimaCalibrate = "0.0.2 - 0.0.4"
176 changes: 90 additions & 86 deletions calibration/test/e2e_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,87 @@ using Test

using Dates

# Debug plots
function scatter_plot(eki::EKP.EnsembleKalmanProcess)
f = CairoMakie.Figure(resolution = (800, 600))
ax = CairoMakie.Axis(
f[1, 1],
ylabel = "Parameter Value",
xlabel = "Top of atmosphere radiative SW flux",
)

g = vec.(EKP.get_g(eki; return_array = true))
params = vec.((EKP.get_ϕ(prior, eki)))

for (gg, uu) in zip(g, params)
CairoMakie.scatter!(ax, gg, uu)
end

CairoMakie.hlines!(ax, [astronomical_unit], linestyle = :dash)
CairoMakie.vlines!(ax, observations, linestyle = :dash)

output = joinpath(output_dir, "scatter.png")
CairoMakie.save(output, f)
return output
end

function param_versus_iter_plot(eki::EKP.EnsembleKalmanProcess)
f = CairoMakie.Figure(resolution = (800, 600))
ax = CairoMakie.Axis(
f[1, 1],
ylabel = "Parameter Value",
xlabel = "Iteration",
)
params = EKP.get_ϕ(prior, eki)
for (i, param) in enumerate(params)
CairoMakie.scatter!(ax, fill(i, length(param)), vec(param))
end

CairoMakie.hlines!(ax, [astronomical_unit]; color = :red, linestyle = :dash)

output = joinpath(output_dir, "param_vs_iter.png")
CairoMakie.save(output, f)
return output
end

# Observation map
function CAL.observation_map(iteration)
single_member_dims = (1,)
G_ensemble = Array{Float64}(undef, single_member_dims..., ensemble_size)

for m in 1:ensemble_size
member_path = CAL.path_to_ensemble_member(output_dir, iteration, m)
simdir_path = joinpath(member_path, "output_active")
if isdir(simdir_path)
simdir = SimDir(simdir_path)
G_ensemble[:, m] .= process_member_data(simdir)
else
G_ensemble[:, m] .= NaN
end
end
return G_ensemble
end

function process_member_data(simdir::SimDir)
isempty(simdir.vars) && return NaN
rsut =
get(simdir; short_name = "rsut", reduction = "average", period = "30d")
return slice(average_xy(rsut); time = 30).data
end

# EKI test
function minimal_eki_test(eki)
params = EKP.get_ϕ(prior, eki)
spread = map(var, params)

# Spread should be heavily decreased as particles have converged
@test last(spread) / first(spread) < 0.1
# Parameter should be close to true value
@test mean(last(params)) astronomical_unit rtol = 0.02
end

# Script:

if !(@isdefined backend)
backend = CAL.get_backend()
end
Expand All @@ -39,7 +120,9 @@ if backend <: CAL.HPCBackend
Dates.value(t2 - t1) / 1000 / 60
end / length(wait_times)

if mean_wait_time_in_mins > 20
@show mean_wait_time_in_mins

if mean_wait_time_in_mins > 10
@warn """Average wait time for esmbuild is $(round(mean_wait_time_in_mins, digits=2)) minutes. \
Cluster is too busy to run this test, exiting"""
exit()
Expand All @@ -52,32 +135,7 @@ const model_interface =
joinpath(pkgdir(CA), "calibration", "model_interface.jl")
const output_dir = "calibration_end_to_end_test"
include(model_interface)
ensemble_size = 10

# Observation map
function CAL.observation_map(iteration)
single_member_dims = (1,)
G_ensemble = Array{Float64}(undef, single_member_dims..., ensemble_size)

for m in 1:ensemble_size
member_path = CAL.path_to_ensemble_member(output_dir, iteration, m)
simdir_path = joinpath(member_path, "output_active")
if isdir(simdir_path)
simdir = SimDir(simdir_path)
G_ensemble[:, m] .= process_member_data(simdir)
else
G_ensemble[:, m] .= NaN
end
end
return G_ensemble
end

function process_member_data(simdir::SimDir)
isempty(simdir.vars) && return NaN
rsut =
get(simdir; short_name = "rsut", reduction = "average", period = "30d")
return slice(average_xy(rsut); time = 30).data
end
ensemble_size = 15

# Generate observations
obs_path = joinpath(experiment_dir, "observations.jld2")
Expand All @@ -95,7 +153,7 @@ end
astronomical_unit = 149_597_870_000
observations = JLD2.load_object(obs_path)
noise = 0.1 * I
n_iterations = 3
n_iterations = 4
prior = CAL.get_prior(joinpath(experiment_dir, "prior.toml"))
experiment_config = CAL.ExperimentConfig(;
n_iterations,
Expand All @@ -106,17 +164,6 @@ experiment_config = CAL.ExperimentConfig(;
prior,
)

# Minimal EKI test
function minimal_eki_test(eki)
params = EKP.get_u(eki)
spread = map(x -> var(abs.(x)), params)

# Spread should be heavily decreased as particles have converged
@test last(spread) / first(spread) < 0.1
# Parameter should be close to true value
@test mean(last(params)) astronomical_unit rtol = 0.02
end

@info "Running calibration E2E test" backend
if backend <: CAL.HPCBackend
test_eki = CAL.calibrate(
Expand All @@ -129,6 +176,10 @@ if backend <: CAL.HPCBackend
else
test_eki = CAL.calibrate(backend, experiment_config)
end

scatter_plot(test_eki)
param_versus_iter_plot(test_eki)

@testset "Test Calibration on $backend" begin
minimal_eki_test(test_eki)
end
Expand All @@ -145,50 +196,3 @@ end
@test uu slurm_uu rtol = 0.02
end
end

# Debug plots
function scatter_plot(eki::EKP.EnsembleKalmanProcess)
f = CairoMakie.Figure(resolution = (800, 600))
ax = CairoMakie.Axis(
f[1, 1],
ylabel = "Absolute Parameter Value",
xlabel = "Top of atmosphere radiative SW flux",
)

g = vec.(EKP.get_g(eki; return_array = true))
params = map(x -> abs.(x), vec.((EKP.get_u(eki))))

for (gg, uu) in zip(g, params)
CairoMakie.scatter!(ax, gg, uu)
end

CairoMakie.hlines!(ax, [astronomical_unit], linestyle = :dash)
CairoMakie.vlines!(ax, observations, linestyle = :dash)

output = joinpath(output_dir, "scatter.png")
CairoMakie.save(output, f)
return output
end

scatter_plot(test_eki)

function param_versus_iter_plot(eki::EKP.EnsembleKalmanProcess)
f = CairoMakie.Figure(resolution = (800, 600))
ax = CairoMakie.Axis(
f[1, 1],
ylabel = "Parameter Value",
xlabel = "Iteration",
)
params = EKP.get_u(eki)
for (i, param) in enumerate(params)
CairoMakie.scatter!(ax, fill(i, length(param)), vec(param))
end

CairoMakie.hlines!(ax, [astronomical_unit]; color = :red, linestyle = :dash)

output = joinpath(output_dir, "param_vs_iter.png")
CairoMakie.save(output, f)
return output
end

param_versus_iter_plot(test_eki)
2 changes: 1 addition & 1 deletion calibration/test/prior.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[astronomical_unit]
prior = "constrained_gaussian(astronomical_unit, 200_000, 100597870000, -Inf, Inf)"
prior = "constrained_gaussian(astronomical_unit, 60_000_000_000, 100_000_000_000, 200_000, Inf)"
type = "float"
6 changes: 3 additions & 3 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ sleve_s:
topo_smoothing:
help: "Choose whether to order-2 smoothing on the LGL mesh"
value: false
smoothing_order:
help: "Define the surface smoothing kernel factor (integer) [`3 (default)`]"
value: 3
# ODE
use_newton_rtol:
help: "Whether to check if the current iteration of Newton's method has an error within a relative tolerance, instead of always taking the maximum number of iterations (only for ClimaTimeSteppers.jl)"
Expand Down Expand Up @@ -336,3 +333,6 @@ edmfx_sgs_diffusive_flux:
updraft_number:
help: "Sets the number of updrafts for the EDMF scheme"
value: 1
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
Loading

0 comments on commit 266d885

Please sign in to comment.