-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checkpointing - adds jld2 function #145
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ Additional details and impacted files📢 Thoughts on this report? Let us know! |
With the JustPIC PR #106, the particles and phases can now also be transferred to the CPU. However, not with the Array(particles/phases) coming from JustPIC, we might need to include it in the Project.toml |
src/IO/H5.jl
Outdated
h5file = h5open(file_path, "r") # Open the file in read mode | ||
P = read(h5file["P"]) # Read the stokes variable | ||
T = read(h5file["T"]) # Read the thermal.T variable | ||
Vx = read(h5file["Vx"]) # Read the stokes.V.Vx variable | ||
Vy = read(h5file["Vy"]) # Read the stokes.V.Vy variable | ||
η = read(h5file["η"]) # Read the stokes.viscosity.η variable | ||
t = read(h5file["time"]) # Read the t variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h5file = h5open(file_path, "r") # Open the file in read mode | |
P = read(h5file["P"]) # Read the stokes variable | |
T = read(h5file["T"]) # Read the thermal.T variable | |
Vx = read(h5file["Vx"]) # Read the stokes.V.Vx variable | |
Vy = read(h5file["Vy"]) # Read the stokes.V.Vy variable | |
η = read(h5file["η"]) # Read the stokes.viscosity.η variable | |
t = read(h5file["time"]) # Read the t variable | |
h5file = h5open(file_path, "r") # Open the file in read mode | |
P = read(h5file["P"]) # Read the stokes variable | |
T = read(h5file["T"]) # Read the thermal.T variable | |
Vx = read(h5file["Vx"]) # Read the stokes.V.Vx variable | |
Vy = read(h5file["Vy"]) # Read the stokes.V.Vy variable | |
Vz = read(h5file["Vz"]) # Read the stokes.V.Vz variable | |
η = read(h5file["η"]) # Read the stokes.viscosity.η variable | |
t = read(h5file["time"]) # Read the t variable |
src/IO/JLD2.jl
Outdated
restart = load(file_path) # Load the file | ||
stokes = restart["stokes"] # Read the stokes variable | ||
thermal = restart["thermal"] # Read the thermal variable | ||
particles = restart["particles"] # Read the particles variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still need to remove the particles
Before merging we need to add the time step plus the model time to the jld2 file. And I think it would be nice to copy the scripts that are being run, plus the Could organize the files like this:
The user would need to specify what |
From experience it may happen on an HPC cluster that the simulation is out of time exactly when you are writing the checkpoint file. In that case the file will be corrupt and if you were overwriting an earlier file you have to start the simulation from the beginning again. A workaround is to save it to all to a temporary checkpoint file and remove the original one only once you are finished writing the current one. |
Sounds like the smart thing to do. |
The checkpointing have now been updated to save a temporary file that is being moved to the real dst after completion @boriskaus function checkpointing_jld2(dst, stokes, thermal, time, timestep, fname::String)
!isdir(dst) && mkpath(dst) # create folder in case it does not exist
# Create a temporary directory
mktempdir() do tmpdir
# Save the checkpoint file in the temporary directory
tmpfname = joinpath(tmpdir, basename(fname))
jldsave(
tmpfname;
stokes=Array(stokes),
thermal=Array(thermal),
time=time,
timestep=timestep,
)
# Move the checkpoint file from the temporary directory to the destination directory
mv(tmpfname, fname; force=true)
end
return nothing
end The function metadata will store the function metadata(src, dst, files...)
@assert dst != pwd()
if !ispath(dst)
println("Created $dst folder")
mkpath(dst)
end
for f in vcat(collect(files), ["Manifest.toml", "Project.toml"])
!isfile(joinpath(f)) && continue
newfile = joinpath(dst, basename(f))
isfile(newfile) && rm(newfile)
cp(joinpath(src,f), newfile)
end
end |
This PR features a new checkpointing routine
checkpointing_jld2()
which stores the entire stokes and thermal arrays as well as the particles, its location and phase for restarting.The older function
checkpointing()
with HDF5is now updated after the reworking of the package.Also in this PR: load functions for both checkpoint formats
To be updated after JustPIC implementation: