feat(solvers): add max_wall_time for solver timeout handling #5240
      
        
          +211
        
        
          −89
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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:
nox -s pre-commitnox -s testsTestWallTimeTimeoutclass with 3 tests: normal SPM run without timeout, timeout via solver init on long experiment, timeout viasolve()kwarg—all pass withpytest -v)