Skip to content

Add deprecation warning for timeout in run method(s) #54

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 19 additions & 6 deletions cadet/cadet.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,20 +514,33 @@ def run_simulation(
clear: bool = True
) -> ReturnInformation:
"""
Run the CADET simulation and load the results.
Execute the CADET simulation and load the results.

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
Expand Down
13 changes: 13 additions & 0 deletions cadet/cadet_dll.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from pathlib import Path
from typing import Any, Optional
import warnings

import addict
import numpy
Expand Down Expand Up @@ -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()
Expand Down
34 changes: 22 additions & 12 deletions cadet/runner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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
import warnings


@dataclass
Expand All @@ -16,12 +16,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
Expand All @@ -38,7 +40,6 @@ class CadetRunnerBase(ABC):
def run(
self,
simulation: "Cadet",
timeout: Optional[int] = None,
) -> ReturnInformation:
"""
Run a CADET simulation.
Expand All @@ -47,8 +48,6 @@ def run(
----------
simulation : Cadet
The simulation object.
timeout : Optional[int]
Maximum time allowed for the simulation to run, in seconds.

Returns
-------
Expand All @@ -59,9 +58,7 @@ def run(

@abstractmethod
def clear(self) -> None:
"""
Clear the simulation data.
"""
"""Clear the simulation data."""
pass

@abstractmethod
Expand Down Expand Up @@ -147,7 +144,18 @@ def run(
-------
ReturnInformation
Information about the simulation run.

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
)
if simulation.filename is None:
raise ValueError("Filename must be set before run can be used")

Expand Down Expand Up @@ -187,10 +195,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
Expand Down
Loading