Skip to content
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

Add Ipopt factory for use with SacessOptimizer #1533

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions pypesto/optimize/ess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .refset import RefSet
from .sacess import (
SacessFidesFactory,
SacessIpoptFactory,
SacessOptimizer,
SacessOptions,
get_default_ess_options,
Expand Down
46 changes: 46 additions & 0 deletions pypesto/optimize/ess/sacess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,52 @@ def __repr__(self):
return f"{self.__class__.__name__}(fides_options={self._fides_options}, fides_kwargs={self._fides_kwargs})"


class SacessIpoptFactory:
"""Factory for :class:`IpoptOptimizer` instances for use with :class:`SacessOptimizer`.

:meth:`__call__` will forward the walltime limit and function evaluation
limit imposed on :class:`SacessOptimizer` to :class:`IpoptOptimizer`.
Besides that, default options are used.


Parameters
----------
ipopt_options:
Options for the :class:`IpoptOptimizer`.
See https://coin-or.github.io/Ipopt/OPTIONS.html.
"""

def __init__(
self,
ipopt_options: dict[str, Any] | None = None,
):
if ipopt_options is None:
ipopt_options = {}

self._ipopt_options = ipopt_options

def __call__(
self, max_walltime_s: int, max_eval: int
) -> pypesto.optimize.IpoptOptimizer:
"""Create a :class:`IpoptOptimizer` instance."""

options = self._ipopt_options.copy()
if np.isfinite(max_eval):
options["max_wall_time"] = max_walltime_s

# only accepts int
if np.isfinite(max_eval):
dweindl marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplementedError(
"Ipopt does not support function evaluation limits."
)
return pypesto.optimize.IpoptOptimizer(options=options)

def __repr__(self):
return (
f"{self.__class__.__name__}(ipopt_options={self._ipopt_options})"
)


@dataclass
class SacessWorkerResult:
"""Container for :class:`SacessWorker` results.
Expand Down
8 changes: 7 additions & 1 deletion test/optimize/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
FunctionEvaluatorMP,
RefSet,
SacessFidesFactory,
SacessIpoptFactory,
SacessOptimizer,
SacessOptions,
get_default_ess_options,
Expand Down Expand Up @@ -462,7 +463,12 @@ def test_history_beats_optimizer():
@pytest.mark.parametrize("ess_type", ["ess", "sacess"])
@pytest.mark.parametrize(
"local_optimizer",
[None, optimize.FidesOptimizer(), SacessFidesFactory()],
[
None,
optimize.FidesOptimizer(),
SacessFidesFactory(),
SacessIpoptFactory(),
],
)
@pytest.mark.flaky(reruns=3)
def test_ess(problem, local_optimizer, ess_type, request):
Expand Down
Loading