From 9d88940f0d45e448ef7d636210bb720341fac8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Fri, 21 Mar 2025 15:58:58 +0100 Subject: [PATCH 1/2] Formatting --- cadet/cadet.py | 2 +- cadet/runner.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cadet/cadet.py b/cadet/cadet.py index ab83c1a..e090754 100644 --- a/cadet/cadet.py +++ b/cadet/cadet.py @@ -514,7 +514,7 @@ def run_simulation( clear: bool = True ) -> ReturnInformation: """ - Run the CADET simulation and load the results. + Execute the CADET simulation and load the results. Parameters ---------- diff --git a/cadet/runner.py b/cadet/runner.py index e862de8..64fc723 100644 --- a/cadet/runner.py +++ b/cadet/runner.py @@ -1,10 +1,9 @@ -import os -import pathlib -import re -import subprocess from abc import ABC, abstractmethod from dataclasses import dataclass +import os from pathlib import Path +import re +import subprocess from typing import Optional @@ -16,12 +15,14 @@ class ReturnInformation: Parameters ---------- return_code : int - An integer representing the return code. 0 indicates success, non-zero values indicate errors. + An integer representing the return code. + 0 indicates success, non-zero values indicate errors. error_message : str A string containing the error message if an error occurred. Empty if no error. log : str A string containing log information. """ + return_code: int error_message: str log: str @@ -59,9 +60,7 @@ def run( @abstractmethod def clear(self) -> None: - """ - Clear the simulation data. - """ + """Clear the simulation data.""" pass @abstractmethod @@ -147,6 +146,11 @@ def run( ------- ReturnInformation Information about the simulation run. + + Warnings + -------- + The `timeout` parameter is deprecated. Set the timeout in the solver options + instead. """ if simulation.filename is None: raise ValueError("Filename must be set before run can be used") @@ -187,10 +191,12 @@ def load_results(self, sim: "Cadet") -> None: def _get_cadet_version(self) -> dict: """ Get version and branch name of the currently instanced CADET build. + Returns ------- dict - Dictionary containing: cadet_version as x.x.x, cadet_branch, cadet_build_type, cadet_commit_hash + Dictionary containing: cadet_version as x.x.x, + cadet_branch, cadet_build_type, cadet_commit_hash Raises ------ ValueError From c08df9ded343cb5db1e3233536995cf2422f448c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Fri, 21 Mar 2025 15:59:46 +0100 Subject: [PATCH 2/2] Add deprecation warning for timeout in run method(s) --- cadet/cadet.py | 23 ++++++++++++++++++----- cadet/cadet_dll.py | 13 +++++++++++++ cadet/runner.py | 10 +++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/cadet/cadet.py b/cadet/cadet.py index e090754..4b1dcde 100644 --- a/cadet/cadet.py +++ b/cadet/cadet.py @@ -518,16 +518,29 @@ def run_simulation( Parameters ---------- - timeout : Optional[int] - Maximum time allowed for the simulation to run, in seconds. - clear : bool - If True, clear the simulation results from the current runner instance. + timeout : Optional[int], default=None + Maximum simulation runtime in seconds. + + clear : bool, default=True + Clear previous results before loading new ones. Returns ------- ReturnInformation - Information about the simulation run. + Simulation run details and results. + + Warnings + -------- + The `timeout` parameter is deprecated. Set the timeout in the solver options + instead. """ + if timeout is not None: + warnings.warn( + "Support for setting timeout via `run_simulation` will be removed in a " + " future version. Please set the value in the solver options instead.", + FutureWarning + ) + return_information = self.cadet_runner.run( simulation=self, timeout=timeout diff --git a/cadet/cadet_dll.py b/cadet/cadet_dll.py index 162e87f..04415ed 100644 --- a/cadet/cadet_dll.py +++ b/cadet/cadet_dll.py @@ -3,6 +3,7 @@ import os from pathlib import Path from typing import Any, Optional +import warnings import addict import numpy @@ -1782,7 +1783,19 @@ def run( ------ RuntimeError If the simulation process returns a non-zero exit code. + + Warnings + -------- + The `timeout` parameter is deprecated. Set the timeout in the solver options + instead. """ + if timeout is not None: + warnings.warn( + "Support for setting timeout via `run_simulation` will be removed in a " + " future version. Please set the value in the solver options instead.", + FutureWarning + ) + pp = cadet_dll_parameterprovider.PARAMETERPROVIDER(simulation) log_buffer = self.setup_log_buffer() diff --git a/cadet/runner.py b/cadet/runner.py index 64fc723..77941af 100644 --- a/cadet/runner.py +++ b/cadet/runner.py @@ -5,6 +5,7 @@ import re import subprocess from typing import Optional +import warnings @dataclass @@ -39,7 +40,6 @@ class CadetRunnerBase(ABC): def run( self, simulation: "Cadet", - timeout: Optional[int] = None, ) -> ReturnInformation: """ Run a CADET simulation. @@ -48,8 +48,6 @@ def run( ---------- simulation : Cadet The simulation object. - timeout : Optional[int] - Maximum time allowed for the simulation to run, in seconds. Returns ------- @@ -152,6 +150,12 @@ def run( The `timeout` parameter is deprecated. Set the timeout in the solver options instead. """ + if timeout is not None: + warnings.warn( + "Support for setting timeout via `run_simulation` will be removed in a " + " future version. Please set the value in the solver options instead.", + FutureWarning + ) if simulation.filename is None: raise ValueError("Filename must be set before run can be used")