Print a step. Parameters ---------- result : dict[str, Any] The result dictionary for the most recent step. keys : list[str] The parameter keys. params_config : Mapping[str, ParamsType] The configuration to map the key to
(
self,
keys: list[str],
result: dict[str, Any],
params_config: Mapping[str, ParamsType],
color: str = _color_regular_message,
)
| 136 | return s |
| 137 | |
| 138 | def _print_step( |
| 139 | self, |
| 140 | keys: list[str], |
| 141 | result: dict[str, Any], |
| 142 | params_config: Mapping[str, ParamsType], |
| 143 | color: str = _color_regular_message, |
| 144 | ) -> str: |
| 145 | """Print a step. |
| 146 | |
| 147 | Parameters |
| 148 | ---------- |
| 149 | result : dict[str, Any] |
| 150 | The result dictionary for the most recent step. |
| 151 | |
| 152 | keys : list[str] |
| 153 | The parameter keys. |
| 154 | |
| 155 | params_config : Mapping[str, ParamsType] |
| 156 | The configuration to map the key to the parameter for correct formatting. |
| 157 | |
| 158 | color : str, optional |
| 159 | Color to use for the output. |
| 160 | (Default value = _color_regular_message, equivalent to Fore.RESET) |
| 161 | |
| 162 | Returns |
| 163 | ------- |
| 164 | A stringified, formatted version of the most recent optimization step. |
| 165 | """ |
| 166 | # iter, target, allowed [, *params] |
| 167 | cells: list[str | None] = [None] * (3 + len(keys)) |
| 168 | |
| 169 | cells[:2] = self._format_number(self._iterations), self._format_number(result["target"]) |
| 170 | if self._is_constrained: |
| 171 | cells[2] = self._format_bool(result["allowed"]) |
| 172 | params = result.get("params", {}) |
| 173 | cells[3:] = [ |
| 174 | self._format_number(val) |
| 175 | if isinstance(val, (int, float)) |
| 176 | else params_config[key].to_string(val, self._default_cell_size) |
| 177 | for key, val in params.items() |
| 178 | ] |
| 179 | return "| " + " | ".join(color + x + self._color_reset for x in cells if x is not None) + " |" |
| 180 | |
| 181 | def _print_header(self, keys: list[str]) -> str: |
| 182 | """Print the header of the log. |