Report metrics
HyperOptimizer reads trial results from standard output. Your program can print normal logs too; each metric needs its own line with the hpo.metrics. prefix.
Report an objective
Section titled “Report an objective”hpo.metrics.loss=0.182hpo.metrics.accuracy=0.94hpo.metrics.duration_seconds=42.1Configure loss as Minimize or accuracy as Maximize, depending on what you want to improve. The objective name must exactly match the part after hpo.metrics.. Other metrics provide context without automatically becoming objectives.
Use a numeric helper
Section titled “Use a numeric helper”This helper rejects booleans, strings, and nonfinite numbers, then flushes each line immediately:
import jsonimport math
def emit_metric(name: str, value: int | float) -> None: if isinstance(value, bool) or not isinstance(value, (int, float)): raise TypeError(f"{name} must be a number") if not math.isfinite(value): raise ValueError(f"{name} must be finite") print(f"hpo.metrics.{name}={json.dumps(value, allow_nan=False)}", flush=True)
emit_metric("loss", 0.182)emit_metric("duration_seconds", 42.1)Convert a framework scalar to a Python float or int explicitly before passing it to the helper. Do not use default=str: it can turn an unsupported numeric value into a string that cannot serve as an objective.
Emit final results before exiting
Section titled “Emit final results before exiting”Calculate metrics from the actual evaluation. Emit every configured objective before the process exits successfully. For an initial integration, print each objective once after the calculation finishes; this avoids confusion between intermediate and final values.
If your evaluation fails or a required result is absent, log the reason and exit nonzero. Do not substitute 0 for a missing result: for a loss objective, that could look like your best trial.
Supporting metrics such as runtime, sample count, or validation accuracy help explain the outcome. They do not enforce automatic constraints unless you configure supported objective goals and conditions.
Verify collection
Section titled “Verify collection”- Run the exact container command locally.
- Confirm the metric appears on stdout as a number, without quotes or trailing commentary.
- Check the objective name and maximize/minimize direction in the experiment.
- Launch a small experiment and open one successful trial to inspect its metrics and logs.
See metric format for naming rules and nonnumeric context, or troubleshooting if the value does not appear.