Skip to content

Commit

Permalink
fix CI and checkpointing path
Browse files Browse the repository at this point in the history
  • Loading branch information
aelligp committed May 6, 2024
1 parent 3888211 commit 128352e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/IO/DataIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ using JLD2
using MPI

import ..JustRelax: Geometry
import ..JustRelax: IGG

include("H5.jl")

export save_hdf5, checkpointing, load_checkpoint, metadata
export save_hdf5, checkpointing_hdf5, load_checkpoint_hdf5, metadata

include("JLD2.jl")

Expand Down
6 changes: 3 additions & 3 deletions src/IO/H5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro namevar(x)
end

"""
checkpointing(dst, stokes, T, η, time)
checkpointing_hdf5(dst, stokes, T, η, time)
Save necessary data in `dst` as and HDF5 file to restart the model from the state at `time`
"""
Expand All @@ -31,7 +31,7 @@ function checkpointing_hdf5(dst, stokes, T, time)
end

"""
load_checkpoint(file_path)
load_checkpoint_hdf5(file_path)
Load the state of the simulation from an .h5 file.
Expand All @@ -56,7 +56,7 @@ P, T, Vx, Vy, η, t = load_checkpoint(file_path)
"""
function load_checkpoint(file_path)
function load_checkpoint_hdf5(file_path)
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
Expand Down
17 changes: 5 additions & 12 deletions src/IO/JLD2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
checkpointing_jld2(dst, stokes, thermal, particles, phases, time, igg)
Save necessary data in `dst` as a jld2 file to restart the model from the state at `time`.
If run in parallel, the file will be named after the corresponidng rank e.g. `checkpoint_rank_0.jld2`
If run in parallel, the file will be named after the corresponidng rank e.g. `checkpoint0000.jld2`
and thus can be loaded by the processor while restarting the simulation.
If you want to restart your simulation from the checkpoint you can use load() and specify the MPI rank
by providing a dollar sign and the rank number.
Expand All @@ -19,26 +19,19 @@ by providing a dollar sign and the rank number.
igg,
)
using JLD2
restart = load("path/to/dst/checkpoint_rank_(igg.me).jld2")"
stokes = restart["stokes"]
thermal = restart["thermal"]
particles = restart["particles"]
pPhases = restart["phases"]
t = restart["time"]
```
"""
checkpoint_name() = "checkpoint.jld2"
checkpoint_name(igg::IGG) = "checkpoint" * lpad("$(igg.me)", 4, "0") * ".jld2"
checkpoint_name(dst) = "$dst/checkpoint.jld2"
checkpoint_name(dst,igg::IGG) = "$dst/checkpoint" * lpad("$(igg.me)", 4, "0") * ".jld2"

function checkpointing_jld2(dst, stokes, thermal, particles, phases, time)
fname = checkpoint_name()
fname = checkpoint_name(dst)
checkpointing_jld2(dst, stokes, thermal, particles, phases, time, fname)
return nothing
end

function checkpointing_jld2(dst, stokes, thermal, particles, phases, time, igg::IGG)
fname = checkpoint_name(igg)
fname = checkpoint_name(dst,igg)
checkpointing_jld2(dst, stokes, thermal, particles, phases, time, fname)
return nothing
end
Expand Down
5 changes: 3 additions & 2 deletions test/test_checkpointing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ using GeoParams

# Call the function
checkpointing_jld2(dst, stokes, thermal, particles, pPhases, time, igg)
checkpointing_jld2(dst, stokes, thermal, particles, pPhases, time)

# Check that the file was created
fname = joinpath(dst, "checkpoint_rank_$(igg.me).jld2")
fname = joinpath(dst, "checkpoint" * lpad("$(igg.me)", 4, "0") * ".jld2")
@test isfile(fname)

# Load the data from the file
Expand All @@ -71,7 +72,7 @@ using GeoParams
@test isfile(fname)

# Load the data from the file
P, T, Vx, Vy, η, t = load_checkpoint(fname)
P, T, Vx, Vy, η, t = load_checkpoint_hdf5(fname)

stokes.viscosity.η .= η
stokes.V.Vy .= Vy
Expand Down

0 comments on commit 128352e

Please sign in to comment.