Skip to content
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
856821c
Add pre/post callback function args to advance_state
thomasgibson May 28, 2021
72ceaf6
Pass checkpoint functions as pre-step callbacks
thomasgibson May 28, 2021
2814826
Add healthcheck callback and exceptions
thomasgibson May 28, 2021
25dd51c
Use healthcheck callbacks in examples
thomasgibson May 28, 2021
7ee673c
Fix docstring for sim_healthcheck
thomasgibson May 28, 2021
9dba4ff
Document callback signature and return state
thomasgibson Jun 4, 2021
f1b3e4f
Test the basic healthcheck callback
thomasgibson Jun 4, 2021
faba167
Remove EOS copy-pasta
thomasgibson Jun 4, 2021
0b6df95
Minor refactoring and allow callbacks to terminate the simulation
thomasgibson Jun 5, 2021
b656079
Fix exception docs
thomasgibson Jun 5, 2021
2acdf73
Expand documentation of callbacks
thomasgibson Jun 5, 2021
5405604
Simplify sim_checkpoint and modularize callbacks
thomasgibson Jun 5, 2021
ca7c37b
Update steppers
thomasgibson Jun 6, 2021
da65cd2
Write short test for comparison callback
thomasgibson Jun 6, 2021
2523fbd
Renaming: {cfd_healthcheck,StepperCrashError} -> {sim_healthcheck,Syn…
thomasgibson Jun 7, 2021
8284d8a
Simplify drivers; move exception handling into sim_checkpoint
thomasgibson Jun 7, 2021
00d29a0
Merge branch 'main' into thg/callbacks
thomasgibson Jun 8, 2021
cba127b
Fix callback tests
thomasgibson Jun 8, 2021
5c091bd
Merge branch 'thg/callbacks' of github.com:illinois-ceesd/mirgecom in…
thomasgibson Jun 8, 2021
4c938fa
Clean up sim_checkpoint function
thomasgibson Jun 8, 2021
ed8d1b3
Merge branch 'main' into thg/callbacks
thomasgibson Jun 11, 2021
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
2 changes: 1 addition & 1 deletion doc/support/tools.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Random Pile'o'Tools
===================

.. automodule:: mirgecom.exceptions
.. automodule:: mirgecom.simutil

.. automodule:: mirgecom.utils
43 changes: 16 additions & 27 deletions examples/autoignition-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
inviscid_sim_timestep,
sim_checkpoint,
check_step,
generate_and_distribute_mesh,
ExactSolutionMismatch
generate_and_distribute_mesh
)
from mirgecom.fluid import split_conserved
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point

Expand All @@ -52,7 +52,7 @@
from mirgecom.boundary import AdiabaticSlipBoundary
from mirgecom.initializers import MixtureInitializer
from mirgecom.eos import PyrometheusMixture
from mirgecom.euler import split_conserved

import cantera
import pyrometheus as pyro

Expand Down Expand Up @@ -92,7 +92,6 @@ def main(ctx_factory=cl.create_some_context, use_leap=False):
timestepper = rk4_step
box_ll = -0.005
box_ur = 0.005
error_state = False
debug = False

from mpi4py import MPI
Expand Down Expand Up @@ -233,23 +232,19 @@ def my_checkpoint(step, t, dt, state):
cv = split_conserved(dim, state)
reaction_rates = eos.get_production_rates(cv)
viz_fields = [("reaction_rates", reaction_rates)]
return sim_checkpoint(discr, visualizer, eos, q=state,
vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
constant_cfl=constant_cfl, comm=comm,
viz_fields=viz_fields)

try:
(current_step, current_t, current_state) = \
advance_state(rhs=my_rhs, timestepper=timestepper,
checkpoint=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final)
except ExactSolutionMismatch as ex:
error_state = True
current_step = ex.step
current_t = ex.t
current_state = ex.state
# Perform status checkpointing
sim_checkpoint(discr, visualizer, eos, q=state,
vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
constant_cfl=constant_cfl,
viz_fields=viz_fields)
return state

current_step, current_t, current_state = \
advance_state(rhs=my_rhs, timestepper=timestepper,
pre_step_callback=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final, eos=eos, dim=dim)

if not check_step(current_step, nviz): # If final step not an output step
if rank == 0:
Expand All @@ -258,12 +253,6 @@ def my_checkpoint(step, t, dt, state):
dt=(current_t - checkpoint_t),
state=current_state)

if current_t - t_final < 0:
error_state = True

if error_state:
raise ValueError("Simulation did not complete successfully.")


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
Expand Down
32 changes: 12 additions & 20 deletions examples/lump-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
from mirgecom.simutil import (
inviscid_sim_timestep,
sim_checkpoint,
generate_and_distribute_mesh,
ExactSolutionMismatch
generate_and_distribute_mesh
)
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
Expand Down Expand Up @@ -131,21 +130,17 @@ def my_rhs(t, state):
boundaries=boundaries, eos=eos)

def my_checkpoint(step, t, dt, state):
return sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl, comm=comm)

try:
(current_step, current_t, current_state) = \
advance_state(rhs=my_rhs, timestepper=timestepper,
checkpoint=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final)
except ExactSolutionMismatch as ex:
current_step = ex.step
current_t = ex.t
current_state = ex.state
sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl)
return state

current_step, current_t, current_state = \
advance_state(rhs=my_rhs, timestepper=timestepper,
pre_step_callback=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final, eos=eos, dim=dim)

# if current_t != checkpoint_t:
if rank == 0:
Expand All @@ -154,9 +149,6 @@ def my_checkpoint(step, t, dt, state):
dt=(current_t - checkpoint_t),
state=current_state)

if current_t - t_final < 0:
raise ValueError("Simulation exited abnormally")


if __name__ == "__main__":
logging.basicConfig(format="%(message)s", level=logging.INFO)
Expand Down
39 changes: 12 additions & 27 deletions examples/mixture-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
from mirgecom.simutil import (
inviscid_sim_timestep,
sim_checkpoint,
generate_and_distribute_mesh,
ExactSolutionMismatch
generate_and_distribute_mesh
)
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
Expand Down Expand Up @@ -89,7 +88,6 @@ def main(ctx_factory=cl.create_some_context, use_leap=False):
timestepper = rk4_step
box_ll = -5.0
box_ur = 5.0
error_state = 0

from mpi4py import MPI
comm = MPI.COMM_WORLD
Expand Down Expand Up @@ -152,24 +150,17 @@ def my_rhs(t, state):
boundaries=boundaries, eos=eos)

def my_checkpoint(step, t, dt, state):
global checkpoint_t
checkpoint_t = t
return sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl, comm=comm)

try:
(current_step, current_t, current_state) = \
advance_state(rhs=my_rhs, timestepper=timestepper,
checkpoint=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final)
except ExactSolutionMismatch as ex:
error_state = 1
current_step = ex.step
current_t = ex.t
current_state = ex.state
sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl)
return state

current_step, current_t, current_state = \
advance_state(rhs=my_rhs, timestepper=timestepper,
pre_step_callback=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final, eos=eos, dim=dim)

if current_t != checkpoint_t: # This check because !overwrite
if rank == 0:
Expand All @@ -178,12 +169,6 @@ def my_checkpoint(step, t, dt, state):
dt=(current_t - checkpoint_t),
state=current_state)

if current_t - t_final < 0:
error_state = 1

if error_state:
raise ValueError("Simulation did not complete successfully.")


if __name__ == "__main__":
logging.basicConfig(format="%(message)s", level=logging.INFO)
Expand Down
33 changes: 12 additions & 21 deletions examples/pulse-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
from mirgecom.euler import euler_operator
from mirgecom.simutil import (
inviscid_sim_timestep,
generate_and_distribute_mesh,
sim_checkpoint,
ExactSolutionMismatch,
generate_and_distribute_mesh
)

from mirgecom.io import make_init_message

from mirgecom.integrators import rk4_step
Expand Down Expand Up @@ -154,21 +152,17 @@ def my_rhs(t, state):
boundaries=boundaries, eos=eos)

def my_checkpoint(step, t, dt, state):
return sim_checkpoint(discr, visualizer, eos, q=state,
vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl, comm=comm)

try:
(current_step, current_t, current_state) = \
advance_state(rhs=my_rhs, timestepper=timestepper,
checkpoint=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final)
except ExactSolutionMismatch as ex:
current_step = ex.step
current_t = ex.t
current_state = ex.state
sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl)
return state

current_step, current_t, current_state = \
advance_state(rhs=my_rhs, timestepper=timestepper,
pre_step_callback=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final, eos=eos, dim=dim)

# if current_t != checkpoint_t:
if rank == 0:
Expand All @@ -177,9 +171,6 @@ def my_checkpoint(step, t, dt, state):
dt=(current_t - checkpoint_t),
state=current_state)

if current_t - t_final < 0:
raise ValueError("Simulation exited abnormally")


if __name__ == "__main__":
logging.basicConfig(format="%(message)s", level=logging.INFO)
Expand Down
32 changes: 12 additions & 20 deletions examples/scalar-lump-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
from mirgecom.simutil import (
inviscid_sim_timestep,
sim_checkpoint,
generate_and_distribute_mesh,
ExactSolutionMismatch
generate_and_distribute_mesh
)
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
Expand Down Expand Up @@ -141,21 +140,17 @@ def my_rhs(t, state):
boundaries=boundaries, eos=eos)

def my_checkpoint(step, t, dt, state):
return sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl, comm=comm)

try:
(current_step, current_t, current_state) = \
advance_state(rhs=my_rhs, timestepper=timestepper,
checkpoint=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final)
except ExactSolutionMismatch as ex:
current_step = ex.step
current_t = ex.t
current_state = ex.state
sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl)
return state

current_step, current_t, current_state = \
advance_state(rhs=my_rhs, timestepper=timestepper,
pre_step_callback=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final, eos=eos, dim=dim)

# if current_t != checkpoint_t:
if rank == 0:
Expand All @@ -164,9 +159,6 @@ def my_checkpoint(step, t, dt, state):
dt=(current_t - checkpoint_t),
state=current_state)

if current_t - t_final < 0:
raise ValueError("Simulation exited abnormally")


if __name__ == "__main__":
logging.basicConfig(format="%(message)s", level=logging.INFO)
Expand Down
32 changes: 12 additions & 20 deletions examples/sod-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
from mirgecom.simutil import (
inviscid_sim_timestep,
sim_checkpoint,
generate_and_distribute_mesh,
ExactSolutionMismatch,
generate_and_distribute_mesh
)
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
Expand Down Expand Up @@ -130,21 +129,17 @@ def my_rhs(t, state):
boundaries=boundaries, eos=eos)

def my_checkpoint(step, t, dt, state):
return sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl, comm=comm)

try:
(current_step, current_t, current_state) = \
advance_state(rhs=my_rhs, timestepper=timestepper,
checkpoint=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final)
except ExactSolutionMismatch as ex:
current_step = ex.step
current_t = ex.t
current_state = ex.state
sim_checkpoint(discr, visualizer, eos, q=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
exittol=exittol, constant_cfl=constant_cfl)
return state

current_step, current_t, current_state = \
advance_state(rhs=my_rhs, timestepper=timestepper,
pre_step_callback=my_checkpoint,
get_timestep=get_timestep, state=current_state,
t=current_t, t_final=t_final, eos=eos, dim=dim)

# if current_t != checkpoint_t:
if rank == 0:
Expand All @@ -153,9 +148,6 @@ def my_checkpoint(step, t, dt, state):
dt=(current_t - checkpoint_t),
state=current_state)

if current_t - t_final < 0:
raise ValueError("Simulation exited abnormally")


if __name__ == "__main__":
logging.basicConfig(format="%(message)s", level=logging.INFO)
Expand Down
Loading