Skip to content

Commit

Permalink
Adding ability to reduce the amount of text printed when displaying o…
Browse files Browse the repository at this point in the history
…ptimization results (#395)

* Adding ability to reduce the amount of text printed

When minimal_print it True, only variables and constraints with a
non-empty status (for example a violated bound)

* pep8 fix

* pep8 fix

* feedback from ewu63

* removed arg from __str__

* updated logic

* fixed second usage of logic

* updated docstring

* docstring case

---------

Co-authored-by: Sabet Seraj <[email protected]>
  • Loading branch information
crecine and sseraj authored May 8, 2024
1 parent e17f1ee commit 0fd3dd7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions pyoptsparse/pyOpt_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ def processContoDict(
scaled : bool
Flag specifying if the returned array should be scaled by
the pyOpt scaling. The only type this is not true is
the pyOpt scaling. The only time this is not true is
when the automatic derivatives are used
dtype : str
Expand Down Expand Up @@ -1577,9 +1577,17 @@ def _mapContoOpt_Dict(self, conDict: Dict1DType) -> Dict1DType:
con_opt = self._mapContoOpt(con)
return self.processContoDict(con_opt, scaled=False, natural=True)

def __str__(self):
def summary_str(self, minimal_print=False):
"""
Print Structured Optimization Problem
Parameters
----------
minimal_print : bool
Flag to specify if the printed results should only include
variables and constraints with a non-empty status
(for example a violated bound).
This defaults to False, which will print all results.
"""
TOL = 1.0e-6

Expand Down Expand Up @@ -1642,7 +1650,8 @@ def __str__(self):
else:
raise ValueError(f"Unrecognized type for variable {var.name}: {var.type}")

text += fmt.format(idx, var.name, var.type, lower, value, upper, status, width=num_c)
if not minimal_print or status:
text += fmt.format(idx, var.name, var.type, lower, value, upper, status, width=num_c)
idx += 1

if len(self.constraints) > 0:
Expand Down Expand Up @@ -1698,13 +1707,17 @@ def __str__(self):
# Active upper bound
status += "u"

text += fmt.format(
idx, c.name, typ, lower, value, upper, status, lambdaStar[con_name][j], width=num_c
)
if not minimal_print or status:
text += fmt.format(
idx, c.name, typ, lower, value, upper, status, lambdaStar[con_name][j], width=num_c
)
idx += 1

return text

def __str__(self):
return self.summary_str(minimal_print=False)

def __getstate__(self) -> dict:
"""
This is used for serializing class instances.
Expand Down

0 comments on commit 0fd3dd7

Please sign in to comment.