3535
3636import functools
3737from dataclasses import dataclass
38- from typing import Any , Callable , List , Literal , Tuple
38+ from typing import Any , Callable , List , Literal , SupportsInt , Tuple
3939
4040import numpy as np
4141import scipy
@@ -677,10 +677,10 @@ def process_scipy_result(scipy_res: ScipyOptimizeResult) -> InternalOptimizeResu
677677 fun = scipy_res .fun ,
678678 success = bool (scipy_res .success ),
679679 message = str (scipy_res .message ),
680- n_fun_evals = scipy_res .get ("nfev" ),
681- n_jac_evals = scipy_res .get ("njev" ),
682- n_hess_evals = scipy_res .get ("nhev" ),
683- n_iterations = scipy_res .get ("nit" ),
680+ n_fun_evals = _int_if_not_none ( scipy_res .get ("nfev" ) ),
681+ n_jac_evals = _int_if_not_none ( scipy_res .get ("njev" ) ),
682+ n_hess_evals = _int_if_not_none ( scipy_res .get ("nhev" ) ),
683+ n_iterations = _int_if_not_none ( scipy_res .get ("nit" ) ),
684684 # TODO: Pass on more things once we can convert them to external
685685 status = None ,
686686 jac = None ,
@@ -693,6 +693,12 @@ def process_scipy_result(scipy_res: ScipyOptimizeResult) -> InternalOptimizeResu
693693 return res
694694
695695
696+ def _int_if_not_none (value : SupportsInt | None ) -> int | None :
697+ if value is None :
698+ return None
699+ return int (value )
700+
701+
696702def _get_scipy_constraints (constraints ):
697703 """Transform internal nonlinear constraints to scipy readable format.
698704
0 commit comments