Skip to content

Commit 624534c

Browse files
committed
Refactoring and test fix
1 parent ced83b5 commit 624534c

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/core/study.jl

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,10 @@ function submit!(study::Study; kwargs...)
199199
# If logfile exists, refresh sim_success and append a resume marker. Otherwise
200200
# create a new logfile with header.
201201
if isfile(study.logfile)
202-
try
203-
update_sim_success_from_log!(study)
204-
catch err
205-
@warn "failed to refresh study status from existing logfile" error=err
206-
end
202+
update_sim_success_from_log!(study)
207203
open(study.logfile, "a") do io
208204
datetime = Dates.format(Dates.now(), "yyyy-mm-dd, HH:MM:SS")
209-
write(io, "\n--- RESUMED: $datetime ---\n\n")
205+
write(io, "\n\n--- RESUMED: $datetime ---\n\n")
210206
end
211207
else
212208
open(study.logfile, "w+") do io
@@ -233,11 +229,12 @@ function submit!(study::Study; kwargs...)
233229
end
234230
continue
235231
end
236-
success = false
237232
simtime = @elapsed begin
238-
try
233+
success = try
234+
# remove the vtk files from previous failed runs if any
235+
isdir(job.options.vtk) && rm(job.options.vtk; force=true, recursive=true)
239236
submit(job; kwargs...)
240-
success = true
237+
true
241238
catch err
242239
# Try to log the error to the job's logfile, but if that fails
243240
# (e.g., invalid path), just continue
@@ -248,6 +245,7 @@ function submit!(study::Study; kwargs...)
248245
catch
249246
# If logging fails, just continue - error will be recorded in job log
250247
end
248+
false
251249
end
252250
end
253251
study.sim_success[i] = success
@@ -277,7 +275,7 @@ last recorded status for each job. This allows resuming processing or submission
277275
after an interrupted run.
278276
"""
279277
function update_sim_success_from_log!(study::Study)
280-
isfile(study.logfile) || return false
278+
isfile(study.logfile) || return nothing
281279

282280
# Read logfile line by line
283281
lines = readlines(study.logfile)
@@ -319,7 +317,7 @@ function update_sim_success_from_log!(study::Study)
319317
study.sim_success[i] = false
320318
end
321319
end
322-
return true
320+
return nothing
323321
end
324322

325323
"""
@@ -383,13 +381,7 @@ See also: [`Study`](@ref), [`submit!`](@ref)
383381
"""
384382
function process_each_job(f::F, study::Study, default_result::NamedTuple) where {F}
385383
# Refresh sim_success from logfile if it exists (in case study was interrupted/resumed)
386-
if isfile(study.logfile)
387-
try
388-
update_sim_success_from_log!(study)
389-
catch err
390-
@warn "failed to refresh study status from logfile before processing" error=err
391-
end
392-
end
384+
isfile(study.logfile) && update_sim_success_from_log!(study)
393385

394386
results = fill(default_result, length(study.jobs))
395387
for (i, job) in enumerate(study.jobs)

test/core/test_study.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ end
8585
mkpath(study.jobpaths[1])
8686
open(study.logfile, "w") do io
8787
write(io, "SIMULATION STUDY LOGFILE\n\n")
88-
write(io, "Simulation `$(study.jobpaths[1])`:\n status: completed ✓ (0.00 seconds)\n\n")
88+
write(io, "Simulation `$(study.jobpaths[1])`:\n")
89+
write(io, " status: completed ✓ (0.00 seconds)\n\n")
8990
end
9091

9192
# Now resuming submit! should only run the remaining job (E=2)
@@ -283,6 +284,9 @@ end
283284
end
284285

285286
@testitem "Study with MultibodySetup" begin
287+
__mpi_run__ = Peridynamics.MPI_RUN[]
288+
Peridynamics.MPI_RUN[] = false
289+
286290
function create_job(setup::NamedTuple, root::String)
287291
b1 = Body(BBMaterial(), rand(3, 50), rand(50))
288292
material!(b1, horizon=1, E=1, rho=1, Gc=1)
@@ -306,6 +310,8 @@ end
306310

307311
Peridynamics.submit!(study)
308312
@test study.sim_success[1] == true
313+
314+
Peridynamics.MPI_RUN[] = __mpi_run__
309315
end
310316

311317
@testitem "Study logfile format and content" begin

0 commit comments

Comments
 (0)