Skip to content

Metric format

HyperOptimizer collects metrics from stdout lines that match the hpo.metrics.<key>=<json> format.

hpo.metrics.<key>=<json>
Part Type Description
hpo.metrics. prefix Required prefix. The collector ignores lines without it.
<key> string Metric name, such as sharpe, loss, or max_drawdown.
<json> JSON value JSON-serializable value produced by your program.

Use JSON numbers, strings, booleans, arrays, or objects. Numeric objective metrics are the most useful for optimization.

hpo.metrics.loss=0.182
hpo.metrics.accuracy=0.94
hpo.metrics.valid=true
hpo.metrics.notes="completed"
import json
def emit_metric(key, value):
print(f"hpo.metrics.{key}={json.dumps(value, default=str)}")
emit_metric("objective", 0.84)
emit_metric("duration_seconds", 42.1)
stdout
hpo.metrics.objective=0.84
hpo.metrics.duration_seconds=42.1
hpo.metrics.status="completed"

Missing prefix

metrics.loss=0.2 will not be collected. Use hpo.metrics.loss=0.2.

Invalid JSON

hpo.metrics.loss=nan is not valid JSON. Convert special values before printing.

Wrong objective name

If the dashboard expects sharpe, printing sharp will not satisfy the objective.

Only writing files

Writing metrics to a JSON file is not enough for collection. Print them to stdout.