Skip to content

Commit

Permalink
Merge pull request #114 from chrhansk/feature-active-set-display
Browse files Browse the repository at this point in the history
Fix several errors in display
  • Loading branch information
chrhansk authored Aug 28, 2024
2 parents e044811 + 7a863a8 commit 791f136
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions pygradflow/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -219,7 +221,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:
Expand Down
2 changes: 1 addition & 1 deletion pygradflow/integration/integration_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions pygradflow/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 791f136

Please sign in to comment.