From d30cd4c9e68b5cc51615f77b9281d40046d48053 Mon Sep 17 00:00:00 2001 From: Christoph Hansknecht Date: Tue, 20 Aug 2024 16:52:15 +0200 Subject: [PATCH 1/2] Ensure steps are always projected to bounds --- pygradflow/step/solver/step_solver.py | 31 ++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pygradflow/step/solver/step_solver.py b/pygradflow/step/solver/step_solver.py index 5cbff39..dfd03a2 100644 --- a/pygradflow/step/solver/step_solver.py +++ b/pygradflow/step/solver/step_solver.py @@ -16,20 +16,45 @@ class StepResult: def __init__(self, orig_iterate, dx, dy, active_set, rcond=None): self.orig_iterate = orig_iterate - self.dx = dx self.dy = dy self.active_set = active_set self.rcond = rcond + self._compute_xn(dx) + + def _compute_xn(self, dx): + iterate = self.orig_iterate + problem = iterate.problem + + var_lb = problem.var_lb + var_ub = problem.var_ub + + xn = iterate.x - dx + dx = np.copy(dx) + + at_lb = xn < var_lb + xn[at_lb] = var_lb[at_lb] + dx[at_lb] = iterate.x[at_lb] - var_lb[at_lb] + + at_ub = xn > var_ub + xn[at_ub] = var_ub[at_ub] + dx[at_ub] = iterate.x[at_ub] - var_ub[at_ub] + + self.dx = dx + self.xn = xn + @functools.cached_property def iterate(self): iterate = self.orig_iterate + xn = self.xn.astype(iterate.x.dtype, copy=False) + yn = iterate.y - self.dy + return Iterate( iterate.problem, iterate.params, - iterate.x - self.dx, - iterate.y - self.dy, + xn, + yn, iterate.eval, ) From d69aede94c2c72b2a7718cc14e56f1441ee5fbb0 Mon Sep 17 00:00:00 2001 From: Christoph Hansknecht Date: Tue, 20 Aug 2024 16:54:07 +0200 Subject: [PATCH 2/2] Bump version --- docs/conf.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b356694..040e339 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,7 +14,7 @@ project = "pygradflow" copyright = "2023, Christoph Hansknecht" author = "Christoph Hansknecht" -release = "0.5.15" +release = "0.5.16" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/pyproject.toml b/pyproject.toml index bacb60d..36af5f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pygradflow" -version = "0.5.15" +version = "0.5.16" description = "PyGradFlow is a simple implementation of the sequential homotopy method to be used to solve general nonlinear programs." authors = ["Christoph Hansknecht "] readme = "README.md"