Skip to content

Conversation

@r0hansaxena
Copy link
Contributor

@r0hansaxena r0hansaxena commented Oct 25, 2025

Description

This PR introduces a max_wall_time parameter to the BaseSolver class, with support extended to child classes like CasadiSolver and IDAKLUSolver. The parameter enables wall-clock timeout handling to stop solver steps if they exceed a set time limit, avoiding prolonged hangs. It is optional (default None, meaning no limit) and specified in seconds. When enabled, the solver records the start time and checks elapsed time in BaseSolver.step() using time.time(). If the limit is reached, it raises a SolverError ("Wall time limit exceeded during step") and retains partial Solution objects for analysis. Users can set it during solver creation (e.g., CasadiSolver(max_wall_time=3600)) or pass it via **kwargs in Simulation.solve(). In experiment runs, the _solve_steps() method re-raises timeout errors for clear handling, while logging others as standard.​

No specific issue is resolved; this is a new enhancement for solver stability.

Fixes #5161

Type of change

This is an enhancement adding timeout functionality to solvers and simulations.

max_wall_time parameter to BaseSolver.init() (propagated to child solvers CasadiSolver and IDAKLUSolver), enabling optional wall-clock timeout checks in BaseSolver.step() using time.time(); raises SolverError on exceedance while preserving partial Solution objects for analysis; supports setting via Simulation.solve(**kwargs) and clean re-raising in Simulation._solve_steps() for experiments

Important checks:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • Tests added that prove fix is effective or that feature works (new TestWallTimeTimeout class with 3 tests: normal SPM run without timeout, timeout via solver init on long experiment, timeout via solve() kwarg—all pass with pytest -v)

@r0hansaxena r0hansaxena requested a review from a team as a code owner October 25, 2025 10:19
Copy link
Member

@BradyPlanden BradyPlanden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @r0hansaxena — a few comments on the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add walltime timeout to solvers

2 participants