From 0a6b7613cf40a4ff7009f2d3fda9985635861d39 Mon Sep 17 00:00:00 2001 From: Christoph Hansknecht Date: Wed, 28 Aug 2024 15:10:25 +0200 Subject: [PATCH 1/3] Only display dual step when constraints are present --- pygradflow/display.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygradflow/display.py b/pygradflow/display.py index bd5c10b..8b7fb6a 100644 --- a/pygradflow/display.py +++ b/pygradflow/display.py @@ -219,7 +219,12 @@ def solver_display(problem: Problem, params: Params): cols.append( AttrColumn("Primal step", 16, "{:16.8e}", StateAttr("primal_step_norm")) ) - cols.append(AttrColumn("Dual step", 16, "{:16.8e}", StateAttr("dual_step_norm"))) + + if problem.num_cons > 0: + cols.append( + AttrColumn("Dual step", 16, "{:16.8e}", StateAttr("dual_step_norm")) + ) + cols.append(AttrColumn("Lambda", 16, "{:16.8e}", StateAttr("lamb"))) if problem.var_bounded: From b69b9201bde8bd66ba3697a4480783d5e81b32b5 Mon Sep 17 00:00:00 2001 From: Christoph Hansknecht Date: Wed, 28 Aug 2024 15:19:13 +0200 Subject: [PATCH 2/3] Fix bug during display involving previous state --- pygradflow/display.py | 6 +++-- pygradflow/integration/integration_solver.py | 2 +- pygradflow/solver.py | 26 +++++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pygradflow/display.py b/pygradflow/display.py index 8b7fb6a..760083b 100644 --- a/pygradflow/display.py +++ b/pygradflow/display.py @@ -11,7 +11,9 @@ class StateData: - def __init__(self): + def __init__(self, iterate, step_result): + self.iterate = iterate + self.step_result = step_result self._entries = dict() def __setitem__(self, key, value): @@ -21,7 +23,7 @@ def __getitem__(self, key): try: entry = self._entries[key] if callable(entry): - return entry() + return entry(self.iterate, self.step_result) return entry except Exception: return None diff --git a/pygradflow/integration/integration_solver.py b/pygradflow/integration/integration_solver.py index 84c4025..319a24c 100644 --- a/pygradflow/integration/integration_solver.py +++ b/pygradflow/integration/integration_solver.py @@ -432,7 +432,7 @@ def solve(self, x0: Optional[np.ndarray] = None, y0: Optional[np.ndarray] = None path_dist += result.dist if display.should_display(): - state = StateData() + state = StateData(curr_it, step_result=None) curr_x, curr_y = self.flow.split_states(curr_z) iterate = curr_it state["iterate"] = iterate diff --git a/pygradflow/solver.py b/pygradflow/solver.py index 730a935..e17d25c 100644 --- a/pygradflow/solver.py +++ b/pygradflow/solver.py @@ -305,24 +305,26 @@ def solve( self.callbacks(CallbackType.ComputedStep, iterate, next_iterate, accept) if display_iterate: - state = StateData() + state = StateData(iterate, step_result) state["iterate"] = iterate - state["active_set"] = lambda: step_result.active_set - state["obj_nonlin"] = lambda: iterate.obj_nonlin(next_iterate) + state["active_set"] = lambda _, step_result: step_result.active_set + state["obj_nonlin"] = lambda iterate, _: iterate.obj_nonlin( + step_result.iterate + ) if problem.num_cons > 0: - state["cons_nonlin"] = lambda: np.linalg.norm( - iterate.cons_nonlin(next_iterate), ord=np.inf + state["cons_nonlin"] = lambda iterate, _: np.linalg.norm( + iterate.cons_nonlin(step_result.iterate), ord=np.inf ) - state["aug_lag"] = lambda: iterate.aug_lag(self.rho) - state["obj"] = lambda: iterate.obj() + state["aug_lag"] = lambda iterate, _: iterate.aug_lag(self.rho) + state["obj"] = lambda iterate, _: iterate.obj() state["iter"] = iteration + 1 - state["primal_step_norm"] = lambda: primal_step_norm - state["dual_step_norm"] = lambda: dual_step_norm - state["lamb"] = lambda: lamb - state["step_accept"] = lambda: accept - state["rcond"] = lambda: step_result.rcond + state["primal_step_norm"] = primal_step_norm + state["dual_step_norm"] = dual_step_norm + state["lamb"] = lamb + state["step_accept"] = accept + state["rcond"] = lambda _, step_result: step_result.rcond logger.info(display.row(state)) From 7a863a8e9a52333c6884bf95fac80307ac68b0e7 Mon Sep 17 00:00:00 2001 From: Christoph Hansknecht Date: Wed, 28 Aug 2024 15:20:40 +0200 Subject: [PATCH 3/3] 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 d11eca2..5032041 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.19" +release = "0.5.20" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/pyproject.toml b/pyproject.toml index 8b52a91..61782a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pygradflow" -version = "0.5.19" +version = "0.5.20" 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"