Skip to content

Commit

Permalink
Added possibility to set solver options and plugins at construction t…
Browse files Browse the repository at this point in the history
…ime.
  • Loading branch information
S-Dafarra committed Apr 6, 2023
1 parent 34ba2dd commit 57e4a17
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/hippopt/base/opti_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class OptiSolver(OptimizationSolver):

_options_plugin: dict[str, Any] = dataclasses.field(default_factory=dict)
_options_solver: dict[str, Any] = dataclasses.field(default_factory=dict)
options_solver: dataclasses.InitVar[dict[str, Any]] = dataclasses.field(
default=None
)
options_plugin: dataclasses.InitVar[dict[str, Any]] = dataclasses.field(
default=None
)

_cost: cs.MX = dataclasses.field(default=None)
_solver: cs.Opti = dataclasses.field(default=None)
Expand All @@ -36,8 +42,19 @@ class OptiSolver(OptimizationSolver):
default=None
)

def __post_init__(self, problem_type: str) -> None:
def __post_init__(
self,
problem_type: str,
options_solver: dict[str, Any] = None,
options_plugin: dict[str, Any] = None,
):
self._solver = cs.Opti(problem_type)
self._options_solver = (
options_solver if isinstance(options_solver, dict) else {}
)
self._options_plugin = (
options_plugin if isinstance(options_plugin, dict) else {}
)
self._solver.solver(
self._inner_solver, self._options_plugin, self._options_solver
)
Expand Down Expand Up @@ -364,8 +381,8 @@ def set_initial_guess(
def set_opti_options(
self,
inner_solver: str = None,
options_plugin: dict[str, Any] = None,
options_solver: dict[str, Any] = None,
options_plugin: dict[str, Any] = None,
) -> None:
if inner_solver is not None:
self._inner_solver = inner_solver
Expand Down

0 comments on commit 57e4a17

Please sign in to comment.