Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Dec 13, 2024
1 parent 0285b53 commit a76e140
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ authors = ["Climate Modeling Alliance"]
version = "0.0.5"

[deps]
ClusterManagers = "34f1f09b-3a8b-5176-ab39-66d58a4d544e"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
EnsembleKalmanProcesses = "aa8a2aa5-91d8-4396-bcef-d4f2ec43552d"
Expand All @@ -21,7 +20,6 @@ CESExt = "CalibrateEmulateSample"

[compat]
CalibrateEmulateSample = "0.5"
ClusterManagers = "0.4.6"
Distributed = "1"
Distributions = "0.25"
EnsembleKalmanProcesses = "1, 2"
Expand Down
3 changes: 2 additions & 1 deletion experiments/surface_fluxes_perfect_model/generate_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ JLD2.save_object(
ustar =
JLD2.load_object(joinpath(data_path, "synthetic_ustar_array_noisy.jld2"))
(; observation, variance) = process_member_data(ustar; output_variance = true)
nothing
JLD2.save_object(joinpath(data_path, "obs_mean.jld2"), observation)
JLD2.save_object(joinpath(data_path, "obs_noise_cov.jld2"), variance)
2 changes: 2 additions & 0 deletions experiments/surface_fluxes_perfect_model/postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function convergence_plot(
Makie.hlines!(ax, [theta_star], color = :red, linestyle = :dash)

Makie.save(joinpath(output_dir, "convergence_$param_name.png"), f)
println(joinpath(output_dir, "convergence_$param_name.png"))
end
end

Expand Down Expand Up @@ -181,3 +182,4 @@ Makie.lines!(
)

Makie.save(joinpath(output_dir, "scatter_iter.png"), f)
println(joinpath(output_dir, "scatter_iter.png"))
16 changes: 8 additions & 8 deletions test/hpc_backend_e2e.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ function test_sf_calibration_output(eki, prior)
spread = map(var, params)

# Spread should be heavily decreased as particles have converged
@test last(spread) / first(spread) < 0.20
@test last(spread) / first(spread) < 0.15

forward_model_output = get_g_mean_final(eki)
@show forward_model_output
@test all(isapprox.(forward_model_output, observations; rtol = 1e-2))
end
end

@assert get_backend() <: HPCBackend
hpc_kwargs = kwargs(time = 5, ntasks = 1, cpus_per_task = 1)
if get_backend() == DerechoBackend
hpc_kwargs[:queue] = "develop"
end
eki = calibrate(experiment_dir; model_interface, hpc_kwargs, verbose = true)
test_sf_calibration_output(eki, prior)
# @assert get_backend() <: HPCBackend
# hpc_kwargs = kwargs(time = 5, ntasks = 1, cpus_per_task = 1)
# if get_backend() == DerechoBackend
# hpc_kwargs[:queue] = "develop"
# end
# eki = calibrate(experiment_dir; model_interface, hpc_kwargs, verbose = true)
# test_sf_calibration_output(eki, prior)

# Pure Julia calibration, this should run anywhere
eki = calibrate(JuliaBackend, experiment_dir)
Expand Down
17 changes: 3 additions & 14 deletions test/pure_julia_e2e.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ n_iterations = 1
ensemble_size = 20
observations = [20.0]
noise = [0.01;;]
output_dir = joinpath("test", "e2e_test_output")
output_dir = mktempdir()

experiment_config = ExperimentConfig(
n_iterations,
Expand All @@ -37,21 +37,11 @@ experiment_config = ExperimentConfig(
# This "model" just samples parameters and returns them, we are checking that the
# results are reproducible.
function forward_model(iteration, member)
experiment_config = ExperimentConfig(project_dir())
model_config = Dict()
output_dir = (experiment_config.output_dir)
member_path = path_to_ensemble_member(output_dir, iteration, member)
model_config["output_dir"] = member_path
parameter_path = joinpath(member_path, "parameters.toml")
model_config["toml"] = parameter_path
return model_config
end

function run_forward_model(config)
toml_dict = CP.create_toml_dict(Float64; override_file = config["toml"])
toml_dict = CP.create_toml_dict(Float64; override_file = parameter_path)
(; test_param) = CP.get_parameter_values(toml_dict, "test_param")
output = test_param
JLD2.save_object(joinpath(config["output_dir"], output_file), output)
JLD2.save_object(joinpath(member_path, output_file), test_param)
end

function observation_map(iteration)
Expand All @@ -77,4 +67,3 @@ ekp = calibrate(JuliaBackend, experiment_config)
@test parameter_values[end][1] 11.852161842745355 rtol = 0.01
end

rm(output_dir; recursive = true)
9 changes: 5 additions & 4 deletions test/slurm_unit_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ iteration = 1; member = 1
model_interface = "model_interface.jl"; include(model_interface)
experiment_dir = "exp/dir"
CAL.forward_model(member, iteration, experiment_dir))'
CAL.forward_model(iteration, member)'
exit 0
"""

for (generated_str, test_str) in
zip(split(sbatch_file, "\n"), split(expected_sbatch_contents, "\n"))
# Test one line at a time to see discrepancies
@test generated_str == test_str
end

Expand All @@ -77,15 +78,15 @@ end
# Test job lifecycle
test_cmd = """
#!/bin/bash
#SBATCH --time=00:00:10
sleep 10
#SBATCH --time=00:00:02
sleep 1
"""

jobid = submit_cmd_helper(test_cmd)
@test CAL.job_status(jobid) == :RUNNING
@test CAL.job_running(CAL.job_status(jobid))

sleep(180) # Ensure job finishes. To debug, lower sleep time or comment out the code block
sleep(60) # Ensure job finishes. To debug, lower sleep time or comment out the code block
@test CAL.job_status(jobid) == :COMPLETED
@test CAL.job_completed(CAL.job_status(jobid))
@test CAL.job_success(CAL.job_status(jobid))
Expand Down

0 comments on commit a76e140

Please sign in to comment.