diff --git a/pyoptsparse/pyOpt_optimization.py b/pyoptsparse/pyOpt_optimization.py index a15ffa93..ee1c8926 100644 --- a/pyoptsparse/pyOpt_optimization.py +++ b/pyoptsparse/pyOpt_optimization.py @@ -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 @@ -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 @@ -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: @@ -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.