From 8814450c507f0c6779415d2fbcf568acb4e17b89 Mon Sep 17 00:00:00 2001 From: Brian Drawert Date: Tue, 14 Feb 2023 15:07:42 -0800 Subject: [PATCH 1/2] timeout works, but does not include compile time in limit --- spatialpy/solvers/solver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spatialpy/solvers/solver.py b/spatialpy/solvers/solver.py index c884a6f8..d1591728 100644 --- a/spatialpy/solvers/solver.py +++ b/spatialpy/solvers/solver.py @@ -27,7 +27,7 @@ import numpy -from spatialpy.core.spatialpyerror import ModelError, SimulationError, SimulationTimeout +from spatialpy.core.spatialpyerror import ModelError, SimulationError def _read_from_stdout(stdout ,verbose=True): try: @@ -536,7 +536,6 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None, :returns: A SpatialPy Result object containing spatial and time series data from simulation. :rtype: spatialpy.Result.Result | list(spatialpy.Result.Result) - :raises SimulationTimeout: Simulation exceeded timeout. :raises SimulationError: Simulation execution failed. """ from spatialpy.core.result import Result # pylint: disable=import-outside-toplevel @@ -587,7 +586,7 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None, result.timeout = True # send signal to the process group os.killpg(process.pid, signal.SIGINT) - raise SimulationTimeout("SpatialPy solver timeout exceded.") from err + except OSError as err: print(f"Error, execution of solver raised an exception: {err}") print(f"cmd = {solver_cmd}") From 667097a43bd7bf2e869dc6f309d079d4dfa8bcdb Mon Sep 17 00:00:00 2001 From: Brian Drawert Date: Wed, 15 Feb 2023 15:38:17 -0800 Subject: [PATCH 2/2] Fixes #348 --- spatialpy/core/result.py | 13 +++++++++++++ spatialpy/solvers/solver.py | 14 ++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/spatialpy/core/result.py b/spatialpy/core/result.py index 1753a1d9..9b83348e 100644 --- a/spatialpy/core/result.py +++ b/spatialpy/core/result.py @@ -156,6 +156,19 @@ def __init__(self, model=None, result_dir=None): self.timeout = False self.official_vtk = False self.result_dir = result_dir + self.listOfResultObjects = [self] + + def __len__(self): + return len(self.listOfResultObjects) + + def __getitem__(self, index): + return self.listOfResultObjects[index] + + def __setitem__(self, index, item): + self.listOfResultObjects[index] = item + + def append(self, item): + self.listOfResultObjects.append(item) def __eq__(self, other): if isinstance(other, Result) and self.result_dir and other.result_dir: diff --git a/spatialpy/solvers/solver.py b/spatialpy/solvers/solver.py index d1591728..e6ee3115 100644 --- a/spatialpy/solvers/solver.py +++ b/spatialpy/solvers/solver.py @@ -534,13 +534,11 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None, :type verbose: bool :returns: A SpatialPy Result object containing spatial and time series data from simulation. - :rtype: spatialpy.Result.Result | list(spatialpy.Result.Result) + :rtype: spatialpy.Result.Result :raises SimulationError: Simulation execution failed. """ from spatialpy.core.result import Result # pylint: disable=import-outside-toplevel - if number_of_trajectories > 1: - result_list = [] # Check if compiled, call compile() if not. if not self.is_compiled: self.compile(debug=debug, profile=profile) @@ -601,9 +599,9 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None, result.success = True if profile: self.__read_profile_info(result) - if number_of_trajectories > 1: - result_list.append(result) - else: - return result + if run_ndx == 0: + first_result = result + elif number_of_trajectories > 1: + first_result.append(result) - return result_list + return first_result