Skip to content
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

Handles restarting problem of adaptive time integration methods #1565

Merged
merged 124 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
a975a25
Create test.jl
ArseniyKholod Mar 15, 2023
4680a7e
Delete test.jl
ArseniyKholod Mar 15, 2023
988d6b1
Merge branch 'trixi-framework:main' into main
ArseniyKholod May 6, 2023
16d93b9
Merge branch 'trixi-framework:main' into main
ArseniyKholod May 9, 2023
d2dbbb0
Merge branch 'trixi-framework:main' into main
ArseniyKholod May 12, 2023
acf8569
Merge branch 'trixi-framework:main' into main
ArseniyKholod May 26, 2023
41451f9
Merge branch 'trixi-framework:main' into main
ArseniyKholod Jun 16, 2023
47a4f69
Merge branch 'trixi-framework:main' into main
ArseniyKholod Jun 22, 2023
586b9d2
Merge branch 'trixi-framework:main' into main
ArseniyKholod Jul 11, 2023
ff59a97
loadcallback
ArseniyKholod Jul 13, 2023
68f3598
adding_parallel_support
ArseniyKholod Jul 14, 2023
8b07b2a
Merge branch 'main' into restart
ArseniyKholod Jul 21, 2023
5354faf
formatting
ArseniyKholod Jul 21, 2023
163a9b9
minimize dependencies
ArseniyKholod Jul 28, 2023
dd6bd1a
combine loadrestart and saverestart
ArseniyKholod Jul 30, 2023
68df7b6
fix
ArseniyKholod Jul 30, 2023
05c1246
Update test_threaded.jl
ArseniyKholod Jul 30, 2023
65517dc
fix
ArseniyKholod Jul 30, 2023
b61021e
test fix
ArseniyKholod Jul 30, 2023
3b96005
fix
ArseniyKholod Jul 30, 2023
85bcd87
MODULE add
ArseniyKholod Jul 30, 2023
be1f868
fix
ArseniyKholod Jul 30, 2023
8dd3302
runtime macros
ArseniyKholod Jul 30, 2023
9b6cc48
Update test_threaded.jl
ArseniyKholod Jul 30, 2023
7f2f9bd
Merge branch 'main' into restart
ArseniyKholod Jul 30, 2023
0f9439b
handle MPI issues
ArseniyKholod Jul 31, 2023
cdb3ad4
Merge branch 'restart' of https://github.com/ArseniyKholod/Trixi.jl i…
ArseniyKholod Jul 31, 2023
7f65b3e
enable PIDController test
ArseniyKholod Aug 1, 2023
53cb000
Update test_mpi_tree.jl
ArseniyKholod Aug 1, 2023
b240c9c
fix
ArseniyKholod Aug 1, 2023
e3813b2
add asserts
ArseniyKholod Aug 1, 2023
8315b5e
Update save_restart.jl
ArseniyKholod Aug 1, 2023
b78b932
add IController tests
ArseniyKholod Aug 2, 2023
e4d5756
Merge branch 'restart' of https://github.com/ArseniyKholod/Trixi.jl i…
ArseniyKholod Aug 2, 2023
556e91a
enable HDF5 parallel
ArseniyKholod Aug 2, 2023
88d9c57
fix shot
ArseniyKholod Aug 2, 2023
84133ee
fix shot 2
ArseniyKholod Aug 2, 2023
4ec808f
fix shot 3
ArseniyKholod Aug 2, 2023
55ba995
fix shot 4
ArseniyKholod Aug 2, 2023
46f51fd
fix shot 5
ArseniyKholod Aug 2, 2023
8e9cfa3
fix shot 6
ArseniyKholod Aug 2, 2023
3b090a1
fix shot 7
ArseniyKholod Aug 2, 2023
e8f28e4
fix shot 8
ArseniyKholod Aug 2, 2023
0dcabc1
fix shot 9
ArseniyKholod Aug 2, 2023
32965f6
fix shot 10
ArseniyKholod Aug 2, 2023
008ca58
fix shot 11
ArseniyKholod Aug 2, 2023
3a41ca9
fix shot 12
ArseniyKholod Aug 2, 2023
7576665
fix shot 13
ArseniyKholod Aug 2, 2023
9dac2da
fix shot 14
ArseniyKholod Aug 2, 2023
aa5447e
fix shot 15
ArseniyKholod Aug 2, 2023
0fcfff2
fix shot 16
ArseniyKholod Aug 2, 2023
63e607a
fix shot 17
ArseniyKholod Aug 2, 2023
43e240b
fix shot 18
ArseniyKholod Aug 2, 2023
d15c7c7
enable additional configuration only in mpi test on linux
ArseniyKholod Aug 3, 2023
451e42d
enable environment
ArseniyKholod Aug 3, 2023
a4b3544
test coverage issue
ArseniyKholod Aug 3, 2023
f66a1a2
disable mpi macOs CI because of failure
ArseniyKholod Aug 3, 2023
c8393fd
disable new configurations to test coverage
ArseniyKholod Aug 3, 2023
93a39ad
disable PID and I test to test coverage issue
ArseniyKholod Aug 3, 2023
5b75944
enable old coverage all
ArseniyKholod Aug 4, 2023
460c8df
undo last commit and enable coverage on windows
ArseniyKholod Aug 4, 2023
903f27e
enable new tests, mpi macOs and HDF5 parallel
ArseniyKholod Aug 4, 2023
6eb1bcc
fix
ArseniyKholod Aug 4, 2023
2ab9cb3
enable coverage on threads
ArseniyKholod Aug 4, 2023
e020129
test HDF5 parallel
ArseniyKholod Aug 4, 2023
9377349
test HDF5 parallel 2
ArseniyKholod Aug 4, 2023
40e5d45
test HDF5 parallel 3
ArseniyKholod Aug 4, 2023
68f41c3
fix
ArseniyKholod Aug 4, 2023
21d9702
Update save_restart_dg.jl
ArseniyKholod Aug 4, 2023
935c7d4
Merge branch 'restart' of https://github.com/ArseniyKholod/Trixi.jl i…
ArseniyKholod Aug 4, 2023
a0b5b3b
test HDF5 parallel 4
ArseniyKholod Aug 4, 2023
714ca91
test HDF5 parallel 5
ArseniyKholod Aug 4, 2023
32c3939
Update configure_packages.jl
ArseniyKholod Aug 5, 2023
27666c7
delete unnecessary changes
ArseniyKholod Aug 5, 2023
74583fb
Merge branch 'restart' of https://github.com/ArseniyKholod/Trixi.jl i…
ArseniyKholod Aug 5, 2023
7de973b
Update save_restart_dg.jl
ArseniyKholod Aug 5, 2023
5c91748
Update save_restart_dg.jl
ArseniyKholod Aug 5, 2023
d76653e
remove dependency on OrdinaryDiffEq
ArseniyKholod Aug 15, 2023
3a786d5
format
ArseniyKholod Aug 15, 2023
22607d5
discard unrelated changes
ArseniyKholod Aug 15, 2023
4a82228
Merge branch 'main' into restart
ArseniyKholod Aug 15, 2023
082fca4
delete barrier
ArseniyKholod Aug 15, 2023
503a50f
delete eval()
ArseniyKholod Aug 15, 2023
047db67
comments & delete mpi_parallel
ArseniyKholod Aug 15, 2023
55f30af
format
ArseniyKholod Aug 15, 2023
15cbc68
Update runtests.jl
ArseniyKholod Aug 15, 2023
8a726a4
Update runtests.jl
ArseniyKholod Aug 15, 2023
425681d
Merge branch 'restart' of https://github.com/ArseniyKholod/Trixi.jl i…
ArseniyKholod Aug 15, 2023
c3adcf8
Merge branch 'main' into restart
ArseniyKholod Aug 15, 2023
c91b68c
simplify tests
ArseniyKholod Aug 16, 2023
0db10e3
Merge branch 'restart' of https://github.com/ArseniyKholod/Trixi.jl i…
ArseniyKholod Aug 16, 2023
629d4da
test failing MPI on windiws and macOs
ArseniyKholod Aug 16, 2023
506abc5
test with RDPK3SpFSAL49
ArseniyKholod Aug 21, 2023
b83904e
test with RDPK3SpFSAL35
ArseniyKholod Aug 21, 2023
89d1ae7
change tests
ArseniyKholod Aug 21, 2023
34c9847
Merge branch 'main' into restart
ArseniyKholod Aug 21, 2023
d1b2802
fix and new test
ArseniyKholod Aug 23, 2023
bebc1ec
Update test_tree_2d_euler.jl
ArseniyKholod Aug 23, 2023
f085ab7
fix and delete unnecessary test
ArseniyKholod Aug 23, 2023
4837f46
add printing format
ArseniyKholod Aug 23, 2023
ea66328
Merge branch 'main' into restart
ArseniyKholod Aug 23, 2023
60388d1
add docstrings
ArseniyKholod Aug 23, 2023
a2602f9
Merge branch 'restart' of https://github.com/ArseniyKholod/Trixi.jl i…
ArseniyKholod Aug 23, 2023
08b0ee1
Update src/callbacks_step/save_restart.jl
ArseniyKholod Aug 25, 2023
8cee6f1
fix
ArseniyKholod Aug 25, 2023
a96c485
formatting
ArseniyKholod Aug 25, 2023
e17a61a
Update src/callbacks_step/save_restart_dg.jl
ArseniyKholod Aug 25, 2023
17cb086
Update src/callbacks_step/save_restart_dg.jl
ArseniyKholod Aug 25, 2023
e5942e9
Update src/callbacks_step/save_restart.jl
ArseniyKholod Aug 25, 2023
c024b73
Update src/callbacks_step/save_restart.jl
ArseniyKholod Aug 25, 2023
6ccd652
Update src/callbacks_step/save_restart.jl
ArseniyKholod Aug 25, 2023
2481433
suggested changes
ArseniyKholod Aug 25, 2023
f4c081b
new test
ArseniyKholod Aug 25, 2023
ebea8c9
fix
ArseniyKholod Aug 25, 2023
4ca23b2
fix
ArseniyKholod Aug 25, 2023
b3141f7
Update test_tree_2d_advection.jl
ArseniyKholod Aug 25, 2023
6303ff9
fix
ArseniyKholod Aug 25, 2023
526408d
fix error mpi on windows
ArseniyKholod Aug 25, 2023
adb5846
rerun
ArseniyKholod Aug 27, 2023
5c8f729
Update src/callbacks_step/save_restart.jl
ArseniyKholod Aug 30, 2023
05b1971
Add comments
ArseniyKholod Aug 30, 2023
8429f31
Merge branch 'main' into restart
ArseniyKholod Sep 12, 2023
b5f80b5
Merge branch 'main' into restart
ArseniyKholod Sep 14, 2023
a41f45f
format
ArseniyKholod Sep 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
Octavian = "6fd5a793-0b7e-452c-907f-f8bfe9c57db4"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
ArseniyKholod marked this conversation as resolved.
Show resolved Hide resolved
ArseniyKholod marked this conversation as resolved.
Show resolved Hide resolved
P4est = "7d669430-f675-4ae7-b43e-fab78ec5a902"
Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Expand Down
4 changes: 2 additions & 2 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using Reexport: @reexport
# MPI needs to be imported before HDF5 to be able to use parallel HDF5
# as long as HDF5.jl uses Requires.jl to enable parallel HDF5 with MPI
using MPI: MPI

using OrdinaryDiffEq
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
using SciMLBase: CallbackSet, DiscreteCallback,
ODEProblem, ODESolution, ODEFunction,
SplitODEProblem
Expand Down Expand Up @@ -245,7 +245,7 @@ export SummaryCallback, SteadyStateCallback, AnalysisCallback, AliveCallback,
AveragingCallback,
AMRCallback, StepsizeCallback,
GlmSpeedCallback, LBMCollisionCallback, EulerAcousticsCouplingCallback,
TrivialCallback, AnalysisCallbackCoupled
TrivialCallback, AnalysisCallbackCoupled, LoadRestartCallback

export load_mesh, load_time, load_timestep, load_dt

Expand Down
1 change: 1 addition & 0 deletions src/callbacks_step/callbacks_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ include("steady_state.jl")
include("analysis.jl")
include("alive.jl")
include("save_restart.jl")
include("load_restart.jl")
include("save_solution.jl")
include("time_series.jl")
include("visualization.jl")
Expand Down
112 changes: 112 additions & 0 deletions src/callbacks_step/load_restart.jl
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
# we need to opt-in explicitly.
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
@muladd begin

#! format: noindent

mutable struct LoadRestartCallback
restart_file::String
end

function Base.show(io::IO, cb::DiscreteCallback{<:Any, <:LoadRestartCallback})
@nospecialize cb # reduce precompilation time

load_callback = cb.affect!
print(io, "LoadRestartCallback(restart file=", load_callback.restart_file, ")")
end

function Base.show(io::IO, ::MIME"text/plain",
cb::DiscreteCallback{<:Any, <:LoadRestartCallback})
@nospecialize cb # reduce precompilation time

if get(io, :compact, false)
show(io, cb)
else
save_load_callback = cb.affect!
setup = [
"restart file" => save_load_callback.restart_file]
summary_box(io, "LoadRestartCallback", setup)
end
end

function LoadRestartCallback(; restart_file = "out.h5")
load_callback = LoadRestartCallback(restart_file)

DiscreteCallback(load_callback, load_callback, # the first one is the condition, the second the affect!
save_positions = (false, false),
initialize = initialize!)
end

function initialize!(cb::DiscreteCallback{Condition, Affect!}, u, t,
integrator) where {Condition, Affect! <: LoadRestartCallback}
load_callback = cb.affect!
if integrator.opts.adaptive
load_integrator!(load_callback.restart_file, integrator,
integrator.opts.controller, integrator.alg)
end
return nothing
end

function load_integrator!(restart_file::String, integrator, controller::PIController,
alg)
if mpi_isroot()
h5open(restart_file, "r") do file
integrator.qold = read(attributes(file)["qold"])
integrator.dt = read(attributes(file)["dtpropose"])
end
end
if mpi_isparallel()
recv_buf = [integrator.qold, integrator.dt]
MPI.Bcast!(recv_buf, mpi_root(), mpi_comm())
integrator.qold, integrator.dt = recv_buf
end
end

function load_integrator!(restart_file::String, integrator, controller::PIDController,
alg)
if mpi_isroot()
h5open(restart_file, "r") do file
integrator.qold = read(attributes(file)["qold"])
integrator.dt = read(attributes(file)["dtpropose"])
err = read(file["controller_err"])
controller.err[1] = err[1]
controller.err[2] = err[2]
controller.err[3] = err[3]
end
end
if mpi_isparallel()
recv_buf = [integrator.qold, integrator.dt]
append!(recv_buf, controller.err)
MPI.Bcast!(recv_buf, mpi_root(), mpi_comm())
integrator.qold = recv_buf[1]
integrator.dt = recv_buf[2]
controller.err[1] = recv_buf[3]
controller.err[2] = recv_buf[4]
controller.err[3] = recv_buf[5]
end
end

function load_integrator!(restart_file::String, integrator, controller, alg)
h5open(restart_file, "r") do file
integrator.dt = read(attributes(file)["dtpropose"])
end
if mpi_isroot()
h5open(restart_file, "r") do file
integrator.dt = read(attributes(file)["dtpropose"])
end
end
if mpi_isparallel()
recv_buf = [integrator.dt]
MPI.Bcast!(recv_buf, mpi_root(), mpi_comm())
integrator.dt = recv_buf[1]
end
end

# this method is called to determine whether the callback should be activated
(load_callback::LoadRestartCallback)(u, t, integrator) = false

# this method is called when the callback is activated
(load_callback::LoadRestartCallback)(integrator) = nothing
end # @muladd
4 changes: 4 additions & 0 deletions src/callbacks_step/save_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ function (restart_callback::SaveRestartCallback)(integrator)
end

save_restart_file(u_ode, t, dt, iter, semi, restart_callback)
if integrator.opts.adaptive
ArseniyKholod marked this conversation as resolved.
Show resolved Hide resolved
sloede marked this conversation as resolved.
Show resolved Hide resolved
save_restart_controller(mesh, integrator, integrator.opts.controller,
restart_callback)
end
end

# avoid re-evaluating possible FSAL stages
Expand Down
44 changes: 44 additions & 0 deletions src/callbacks_step/save_restart_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,48 @@ function load_restart_file_on_root(mesh::Union{ParallelTreeMesh, ParallelP4estMe

return u_ode
end

function save_restart_controller(mesh, integrator,
ArseniyKholod marked this conversation as resolved.
Show resolved Hide resolved
controller, restart_callback)
if mpi_isroot()
save_restart_controller(integrator, controller, restart_callback)
end
if mpi_isparallel()
MPI.Barrier(mpi_comm())
end
ArseniyKholod marked this conversation as resolved.
Show resolved Hide resolved
end

function save_restart_controller(integrator, controller::PIController, restart_callback)
@unpack output_directory = restart_callback
timestep = integrator.stats.naccept
filename = joinpath(output_directory, @sprintf("restart_%06d.h5", timestep))
# Open file (preserve existing content)
h5open(filename, "cw") do file
attributes(file)["qold"] = integrator.qold
attributes(file)["dtpropose"] = integrator.dtpropose
end
end

function save_restart_controller(integrator, controller::PIDController,
restart_callback)
@unpack output_directory = restart_callback
timestep = integrator.stats.naccept
filename = joinpath(output_directory, @sprintf("restart_%06d.h5", timestep))
# Open file (preserve existing content)
h5open(filename, "cw") do file
attributes(file)["qold"] = integrator.qold
attributes(file)["dtpropose"] = integrator.dtpropose
file["controller_err"] = controller.err
end
end

function save_restart_controller(integrator, controller, restart_callback)
@unpack output_directory = restart_callback
timestep = integrator.stats.naccept
filename = joinpath(output_directory, @sprintf("restart_%06d.h5", timestep))
# Open file (preserve existing content)
h5open(filename, "cw") do file
attributes(file)["dtpropose"] = integrator.dtpropose
end
end
end # @muladd