From e36ec96be1cb88980bb4b77303305b833255251d Mon Sep 17 00:00:00 2001 From: JM Etancelin <jean-matthieu.etancelin@univ-pau.fr> Date: Thu, 18 Mar 2021 14:46:22 +0100 Subject: [PATCH] Fix problem when checkpoint_handler is none --- hysop/problem.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hysop/problem.py b/hysop/problem.py index 9bf70d4dc..6962118c6 100644 --- a/hysop/problem.py +++ b/hysop/problem.py @@ -1,4 +1,5 @@ -import sys, datetime +import sys +import datetime from hysop.constants import Backend, MemoryOrdering from hysop.tools.types import check_instance, first_not_None, to_tuple, to_list @@ -15,7 +16,7 @@ class Problem(ComputationalGraph): def __init__(self, name=None, method=None, mpi_params=None, check_unique_clenv=True, **kwds): - mpi_params = first_not_None(mpi_params, MPIParams()) # enforce mpi params for problems + mpi_params = first_not_None(mpi_params, MPIParams()) # enforce mpi params for problems super(Problem, self).__init__(name=name, method=method, mpi_params=mpi_params, **kwds) self._do_check_unique_clenv = check_unique_clenv @@ -138,8 +139,9 @@ class Problem(ComputationalGraph): simu.initialize() check_instance(checkpoint_handler, CheckpointHandler, allow_none=True) - checkpoint_handler.create_checkpoint_template(self, simu) - checkpoint_handler.load_checkpoint(self, simu) + if checkpoint_handler: + checkpoint_handler.create_checkpoint_template(self, simu) + checkpoint_handler.load_checkpoint(self, simu) vprint('\nSolving problem...') with Timer() as tm: @@ -147,7 +149,7 @@ class Problem(ComputationalGraph): vprint() simu.print_state() self.apply(simulation=simu, dbg=dbg, **kwds) - should_dump_checkpoint = checkpoint_handler.should_dump(simu) # determined before simu advance + should_dump_checkpoint = checkpoint_handler and checkpoint_handler.should_dump(simu) # determined before simu advance simu.advance(dbg=dbg, plot_freq=plot_freq) if should_dump_checkpoint: checkpoint_handler.save_checkpoint(self, simu) @@ -166,7 +168,8 @@ class Problem(ComputationalGraph): vprint_banner(msg, spacing=True, at_border=2) simu.finalize() - checkpoint_handler.finalize(self.mpi_params) + if checkpoint_handler: + checkpoint_handler.finalize(self.mpi_params) self.final_report() if (dbg is not None): @@ -179,4 +182,3 @@ class Problem(ComputationalGraph): def finalize(self): vprint('Finalizing problem...') super(Problem, self).finalize() - -- GitLab