Skip to content

Commit 6f2d283

Browse files
authored
Merge pull request #245 from kaipartmann/studies
Restarted studies now fixed
2 parents e6c4fe7 + 2293a82 commit 6f2d283

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/core/study.jl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,11 @@ struct Study{F,S,J}
7979
check_jobpaths_unique(jobpaths)
8080
sim_success = fill(false, length(jobs))
8181
logfile = joinpath(root, "study_log.log")
82-
st = new{F,S,J}(jobcreator, setups, jobs, jobpaths, root, logfile, sim_success)
82+
study = new{F,S,J}(jobcreator, setups, jobs, jobpaths, root, logfile, sim_success)
8383
# If a logfile already exists from a previous run, initialize sim_success
8484
# from the logfile so processing or resuming works across interrupted runs.
85-
if isfile(st.logfile)
86-
try
87-
update_sim_success_from_log!(st)
88-
catch err
89-
@warn "failed to refresh study status from logfile" error=err
90-
end
91-
end
92-
return st
85+
isfile(logfile) && update_sim_success_from_log!(study)
86+
return study
9387
end
9488
end
9589

@@ -213,10 +207,11 @@ function submit!(study::Study; kwargs...)
213207
end
214208

215209
# Now submit each job
210+
n_jobs = length(study.jobs)
216211
for (i, job) in enumerate(study.jobs)
217212
# If this job already completed in a previous run, skip execution
218213
open(study.logfile, "a") do io
219-
msg = "Simulation `$(study.jobpaths[i])`:\n"
214+
msg = @sprintf "(%d/%d) Simulation `%s`:\n" i n_jobs job.options.root
220215
for (key, value) in pairs(study.setups[i])
221216
msg *= " $(key): $(value)\n"
222217
end
@@ -225,7 +220,7 @@ function submit!(study::Study; kwargs...)
225220
if study.sim_success[i]
226221
# Write a short note about skipping to the study logfile
227222
open(study.logfile, "a") do io
228-
write(io, " status: skipped (already completed)\n\n")
223+
write(io, " status: skipped (completed in a previous run)\n\n")
229224
end
230225
continue
231226
end
@@ -283,13 +278,13 @@ function update_sim_success_from_log!(study::Study)
283278
for (i, path) in enumerate(study.jobpaths)
284279
# Search for the Simulation line for this job path
285280
sim_line_pattern = "Simulation `$(path)`:"
286-
sim_line_idx = findfirst(line -> occursin(sim_line_pattern, line), lines)
287-
288-
if sim_line_idx === nothing
281+
sim_line_idxs = findall(line -> occursin(sim_line_pattern, line), lines)
282+
if isempty(sim_line_idxs)
289283
# No record for this job in logfile
290284
study.sim_success[i] = false
291285
continue
292286
end
287+
sim_line_idx = sim_line_idxs[end] # Take the last occurrence (restarts also logged)
293288

294289
# Look for status line in the next few lines after the simulation line
295290
found_status = false

0 commit comments

Comments
 (0)