Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to reduce the amount of text printed when displaying optimization results #395

Merged
merged 11 commits into from
May 8, 2024
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 @@

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 @@
con_opt = self._mapContoOpt(con)
return self.processContoDict(con_opt, scaled=False, natural=True)

def __str__(self):
def summary_str(self, minimal_print=False):

Check warning on line 1580 in pyoptsparse/pyOpt_optimization.py

View check run for this annotation

Codecov / codecov/patch

pyoptsparse/pyOpt_optimization.py#L1580

Added line #L1580 was not covered by tests
"""
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.
"""
crecine marked this conversation as resolved.
Show resolved Hide resolved
TOL = 1.0e-6

Expand Down Expand Up @@ -1642,7 +1650,8 @@
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 @@
# 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):

Check warning on line 1718 in pyoptsparse/pyOpt_optimization.py

View check run for this annotation

Codecov / codecov/patch

pyoptsparse/pyOpt_optimization.py#L1718

Added line #L1718 was not covered by tests
return self.summary_str(minimal_print=False)

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