Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scipy/optimize/_trustregion_constr/report.py: 75%

32 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-12 06:31 +0000

1"""Progress report printers.""" 

2 

3from __future__ import annotations 

4from typing import List 

5 

6class ReportBase: 

7 COLUMN_NAMES: List[str] = NotImplemented 

8 COLUMN_WIDTHS: List[int] = NotImplemented 

9 ITERATION_FORMATS: List[str] = NotImplemented 

10 

11 @classmethod 

12 def print_header(cls): 

13 fmt = ("|" 

14 + "|".join(["{{:^{}}}".format(x) for x in cls.COLUMN_WIDTHS]) 

15 + "|") 

16 separators = ['-' * x for x in cls.COLUMN_WIDTHS] 

17 print(fmt.format(*cls.COLUMN_NAMES)) 

18 print(fmt.format(*separators)) 

19 

20 @classmethod 

21 def print_iteration(cls, *args): 

22 iteration_format = ["{{:{}}}".format(x) for x in cls.ITERATION_FORMATS] 

23 fmt = "|" + "|".join(iteration_format) + "|" 

24 print(fmt.format(*args)) 

25 

26 @classmethod 

27 def print_footer(cls): 

28 print() 

29 

30 

31class BasicReport(ReportBase): 

32 COLUMN_NAMES = ["niter", "f evals", "CG iter", "obj func", "tr radius", 

33 "opt", "c viol"] 

34 COLUMN_WIDTHS = [7, 7, 7, 13, 10, 10, 10] 

35 ITERATION_FORMATS = ["^7", "^7", "^7", "^+13.4e", 

36 "^10.2e", "^10.2e", "^10.2e"] 

37 

38 

39class SQPReport(ReportBase): 

40 COLUMN_NAMES = ["niter", "f evals", "CG iter", "obj func", "tr radius", 

41 "opt", "c viol", "penalty", "CG stop"] 

42 COLUMN_WIDTHS = [7, 7, 7, 13, 10, 10, 10, 10, 7] 

43 ITERATION_FORMATS = ["^7", "^7", "^7", "^+13.4e", "^10.2e", "^10.2e", 

44 "^10.2e", "^10.2e", "^7"] 

45 

46 

47class IPReport(ReportBase): 

48 COLUMN_NAMES = ["niter", "f evals", "CG iter", "obj func", "tr radius", 

49 "opt", "c viol", "penalty", "barrier param", "CG stop"] 

50 COLUMN_WIDTHS = [7, 7, 7, 13, 10, 10, 10, 10, 13, 7] 

51 ITERATION_FORMATS = ["^7", "^7", "^7", "^+13.4e", "^10.2e", "^10.2e", 

52 "^10.2e", "^10.2e", "^13.2e", "^7"]