Skip to content

Commit 4232948

Browse files
Merge pull request #111 from CliMA/ne/early_termination
Enable early termination
2 parents d4b6acc + 476102e commit 4232948

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ jobs:
3333
- uses: actions/cache@v1
3434
env:
3535
cache-name: cache-artifacts
36-
PYTHON: ""
3736
with:
3837
path: ~/.julia/artifacts
3938
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}

src/backends.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function calibrate(
8484
reruns = 0,
8585
ekp_kwargs...,
8686
)
87-
(; n_iterations, ensemble_size) = config
87+
(; n_iterations, output_dir, ensemble_size) = config
8888
eki = initialize(config; ekp_kwargs...)
8989
on_error(e::InterruptException) = rethrow(e)
9090
on_error(e) =
@@ -98,7 +98,10 @@ function calibrate(
9898
end
9999
G_ensemble = observation_map(i)
100100
save_G_ensemble(config, i, G_ensemble)
101-
eki = update_ensemble(config, i)
101+
terminate = update_ensemble(config, i)
102+
!isnothing(terminate) && break
103+
iter_path = path_to_iteration(output_dir, i + 1)
104+
eki = JLD2.load_object(joinpath(iter_path, "eki_file.jld2"))
102105
end
103106
return eki
104107
end
@@ -119,6 +122,7 @@ Available Backends: CaltechHPCBackend, ClimaGPUBackend, DerechoBackend, JuliaBac
119122
- `hpc_kwargs`: Dictionary of resource arguments, passed to the job scheduler.
120123
- `reruns`: Number of times to retry a failed ensemble member.
121124
- `verbose::Bool`: Enable verbose logging.
125+
- Any keyword arguments for the EnsembleKalmanProcess constructor, such as `scheduler`
122126
123127
# Usage
124128
Open julia: `julia --project=experiments/surface_fluxes_perfect_model`
@@ -159,19 +163,18 @@ function calibrate(
159163
hpc_kwargs,
160164
ekp_kwargs...,
161165
)
162-
# ExperimentConfig is created from a YAML file within the experiment_dir
163166
(; n_iterations, output_dir, ensemble_size) = config
164167
@info "Initializing calibration" n_iterations ensemble_size output_dir
165168

166169
eki = initialize(config; ekp_kwargs...)
167170
module_load_str = module_load_string(b)
168-
for iter in 0:(n_iterations - 1)
169-
@info "Iteration $iter"
171+
for i in 0:(n_iterations - 1)
172+
@info "Iteration $i"
170173
jobids = map(1:ensemble_size) do member
171174
@info "Running ensemble member $member"
172175
model_run(
173176
b,
174-
iter,
177+
i,
175178
member,
176179
output_dir,
177180
experiment_dir,
@@ -184,18 +187,21 @@ function calibrate(
184187
wait_for_jobs(
185188
jobids,
186189
output_dir,
187-
iter,
190+
i,
188191
experiment_dir,
189192
model_interface,
190193
module_load_str;
191194
hpc_kwargs,
192195
verbose,
193196
reruns,
194197
)
195-
@info "Completed iteration $iter, updating ensemble"
196-
G_ensemble = observation_map(iter)
197-
save_G_ensemble(config, iter, G_ensemble)
198-
eki = update_ensemble(config, iter)
198+
@info "Completed iteration $i, updating ensemble"
199+
G_ensemble = observation_map(i)
200+
save_G_ensemble(config, i, G_ensemble)
201+
terminate = update_ensemble(config, i)
202+
!isnothing(terminate) && break
203+
iter_path = path_to_iteration(output_dir, i + 1)
204+
eki = JLD2.load_object(joinpath(iter_path, "eki_file.jld2"))
199205
end
200206
return eki
201207
end

src/ekp_interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ function update_ensemble(output_dir::AbstractString, iteration, prior)
317317

318318
# Load data from the ensemble
319319
G_ens = JLD2.load_object(joinpath(iter_path, "G_ensemble.jld2"))
320-
EKP.update_ensemble!(eki, G_ens)
321320

321+
terminate = EKP.update_ensemble!(eki, G_ens)
322322
save_eki_state(eki, output_dir, iteration + 1, prior)
323-
return eki
323+
return terminate
324324
end

0 commit comments

Comments
 (0)