Skip to content

Commit c5b2b09

Browse files
authored
Merge branch 'main' into update-plotly-kaleido
2 parents 9323d6a + ca72d02 commit c5b2b09

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/optimagic/optimizers/scipy_optimizers.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import functools
3737
from dataclasses import dataclass
38-
from typing import Any, Callable, List, Literal, Tuple
38+
from typing import Any, Callable, List, Literal, SupportsInt, Tuple
3939

4040
import numpy as np
4141
import 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+
696702
def _get_scipy_constraints(constraints):
697703
"""Transform internal nonlinear constraints to scipy readable format.
698704

0 commit comments

Comments
 (0)