report.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """Progress report printers."""
  2. class ReportBase(object):
  3. COLUMN_NAMES = NotImplemented
  4. COLUMN_WIDTHS = NotImplemented
  5. ITERATION_FORMATS = NotImplemented
  6. @classmethod
  7. def print_header(cls):
  8. fmt = ("|"
  9. + "|".join(["{{:^{}}}".format(x) for x in cls.COLUMN_WIDTHS])
  10. + "|")
  11. separators = ['-' * x for x in cls.COLUMN_WIDTHS]
  12. print(fmt.format(*cls.COLUMN_NAMES))
  13. print(fmt.format(*separators))
  14. @classmethod
  15. def print_iteration(cls, *args):
  16. iteration_format = ["{{:{}}}".format(x) for x in cls.ITERATION_FORMATS]
  17. fmt = "|" + "|".join(iteration_format) + "|"
  18. print(fmt.format(*args))
  19. @classmethod
  20. def print_footer(cls):
  21. print()
  22. class BasicReport(ReportBase):
  23. COLUMN_NAMES = ["niter", "f evals", "CG iter", "obj func", "tr radius",
  24. "opt", "c viol"]
  25. COLUMN_WIDTHS = [7, 7, 7, 13, 10, 10, 10]
  26. ITERATION_FORMATS = ["^7", "^7", "^7", "^+13.4e",
  27. "^10.2e", "^10.2e", "^10.2e"]
  28. class SQPReport(ReportBase):
  29. COLUMN_NAMES = ["niter", "f evals", "CG iter", "obj func", "tr radius",
  30. "opt", "c viol", "penalty", "CG stop"]
  31. COLUMN_WIDTHS = [7, 7, 7, 13, 10, 10, 10, 10, 7]
  32. ITERATION_FORMATS = ["^7", "^7", "^7", "^+13.4e", "^10.2e", "^10.2e",
  33. "^10.2e", "^10.2e", "^7"]
  34. class IPReport(ReportBase):
  35. COLUMN_NAMES = ["niter", "f evals", "CG iter", "obj func", "tr radius",
  36. "opt", "c viol", "penalty", "barrier param", "CG stop"]
  37. COLUMN_WIDTHS = [7, 7, 7, 13, 10, 10, 10, 10, 13, 7]
  38. ITERATION_FORMATS = ["^7", "^7", "^7", "^+13.4e", "^10.2e", "^10.2e",
  39. "^10.2e", "^10.2e", "^13.2e", "^7"]