Skip to content

Commit

Permalink
Merge pull request #38 from chrhansk/feature-remove-iteration-limit
Browse files Browse the repository at this point in the history
Remove iteration limit by default
  • Loading branch information
chrhansk authored Jan 23, 2024
2 parents 4f94a42 + 35c7123 commit 3ce183a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 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.3.8"
release = "0.3.9"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
3 changes: 2 additions & 1 deletion pygradflow/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import enum
from dataclasses import dataclass
from enum import Enum, Flag, auto
from typing import Optional

import numpy as np

Expand Down Expand Up @@ -167,7 +168,7 @@ class Params:

validate_input: bool = True

iteration_limit: int = 1000
iteration_limit: Optional[int] = None
time_limit: float = np.inf
display_interval: float = 0.1

Expand Down
5 changes: 5 additions & 0 deletions pygradflow/runners/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def try_solve_instance(instance, params, log_filename):
logger.addHandler(handler)
logger.setLevel(logging.INFO)

logging.captureWarnings(True)
warn_logger = logging.getLogger("py.warnings")
warn_logger.addHandler(handler)
warn_logger.setLevel(logging.WARN)

def solve():
return instance.solve(params)

Expand Down
40 changes: 23 additions & 17 deletions pygradflow/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,25 +265,25 @@ def print_result(
) -> None:
rho = self.rho

desc = "{:>30s}".format(SolverStatus.description(status))
desc = "{:>45s}".format(SolverStatus.description(status))

status_desc = Format.redgreen(desc, SolverStatus.success(status), bold=True)
status_name = Format.bold("{:>30s}".format("Status"))
status_name = Format.bold("{:>20s}".format("Status"))

logger.info("%30s: %30s", status_name, status_desc)
logger.info("%30s: %30s", "Time", f"{total_time:.2f}s")
logger.info("%30s: %30d", "Iterations", iterations)
logger.info("%30s: %30d", "Accepted steps", accepted_steps)
logger.info("%20s: %45s", status_name, status_desc)
logger.info("%20s: %45s", "Time", f"{total_time:.2f}s")
logger.info("%20s: %45d", "Iterations", iterations)
logger.info("%20s: %45d", "Accepted steps", accepted_steps)

logger.info("%30s: %30e", "Distance factor", dist_factor)
logger.info("%20s: %45e", "Distance factor", dist_factor)

logger.info("%30s: %30e", "Objective", iterate.obj)
logger.info("%30s: %30e", "Aug Lag violation", iterate.aug_lag_violation(rho))
logger.info("%30s: %30e", "Aug Lag dual", iterate.aug_lag_dual())
logger.info("%20s: %45e", "Objective", iterate.obj)
logger.info("%20s: %45e", "Aug Lag violation", iterate.aug_lag_violation(rho))
logger.info("%20s: %45e", "Aug Lag dual", iterate.aug_lag_dual())

logger.info("%30s: %30e", "Bound violation", iterate.bound_violation)
logger.info("%30s: %30e", "Constraint violation", iterate.cons_violation)
logger.info("%30s: %30e", "Dual violation", iterate.stat_res)
logger.info("%20s: %45e", "Bound violation", iterate.bound_violation)
logger.info("%20s: %45e", "Constraint violation", iterate.cons_violation)
logger.info("%20s: %45e", "Dual violation", iterate.stat_res)

def solve(
self, x0: Optional[np.ndarray] = None, y0: Optional[np.ndarray] = None
Expand Down Expand Up @@ -356,8 +356,9 @@ def solve(
path_dist = 0.0
initial_iterate = iterate
accepted_steps = 0
iteration = 0

for iteration in range(params.iteration_limit):
while True:
if line_diff == header_interval:
line_diff = 0
logger.info(display.header)
Expand Down Expand Up @@ -442,9 +443,14 @@ def solve(
status = SolverStatus.Optimal
break

else:
status = SolverStatus.IterationLimit
logger.debug("Iteration limit reached")
iteration += 1

if (params.iteration_limit is not None) and (
iteration >= params.iteration_limit
):
status = SolverStatus.IterationLimit
logger.debug("Iteration limit reached")
break

curr_time = time.time()
total_time = curr_time - start_time
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.3.8"
version = "0.3.9"
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 3ce183a

Please sign in to comment.