Logger that outputs text, e.g. to log to a terminal. Parameters ---------- verbose : int Verbosity level of the logger. is_constrained : bool Whether the logger is associated with a constrained optimization instance.
| 14 | |
| 15 | |
| 16 | class ScreenLogger: |
| 17 | """Logger that outputs text, e.g. to log to a terminal. |
| 18 | |
| 19 | Parameters |
| 20 | ---------- |
| 21 | verbose : int |
| 22 | Verbosity level of the logger. |
| 23 | |
| 24 | is_constrained : bool |
| 25 | Whether the logger is associated with a constrained optimization |
| 26 | instance. |
| 27 | """ |
| 28 | |
| 29 | _default_cell_size = 9 |
| 30 | _default_precision = 4 |
| 31 | _color_new_max = Fore.MAGENTA |
| 32 | _color_regular_message = Fore.RESET |
| 33 | _color_reset = Fore.RESET |
| 34 | |
| 35 | def __init__(self, verbose: int = 2, is_constrained: bool = False) -> None: |
| 36 | self._verbose = verbose |
| 37 | self._is_constrained = is_constrained |
| 38 | self._header_length = None |
| 39 | self._iterations = 0 |
| 40 | self._previous_max = None |
| 41 | self._previous_max_params = None |
| 42 | self._start_time = None |
| 43 | self._previous_time = None |
| 44 | |
| 45 | @property |
| 46 | def verbose(self) -> int: |
| 47 | """Return the verbosity level.""" |
| 48 | return self._verbose |
| 49 | |
| 50 | @verbose.setter |
| 51 | def verbose(self, v: int) -> None: |
| 52 | """Set the verbosity level. |
| 53 | |
| 54 | Parameters |
| 55 | ---------- |
| 56 | v : int |
| 57 | New verbosity level of the logger. |
| 58 | """ |
| 59 | self._verbose = v |
| 60 | |
| 61 | @property |
| 62 | def is_constrained(self) -> bool: |
| 63 | """Return whether the logger is constrained.""" |
| 64 | return self._is_constrained |
| 65 | |
| 66 | def _format_number(self, x: float) -> str: |
| 67 | """Format a number. |
| 68 | |
| 69 | Parameters |
| 70 | ---------- |
| 71 | x : number |
| 72 | Value to format. |
| 73 |
no outgoing calls