The versioned, machine-readable trace and metric specification (Deliverable 3).
trace_json_schema() / metric_json_schema() emit JSON Schemas generated from the
pydantic models, so the committed spec can never drift from the code (a test
regenerates and diffs them). generate_reference_corpus() produces the published
reference traces a third-party scheduler can consume without importing qnetbench.
SPEC_VERSION
module-attribute
trace_json_schema
trace_json_schema() -> dict[str, Any]
JSON Schema for a single trace event (the tagged union of event types).
Source code in qnetbench/spec.py
| def trace_json_schema() -> dict[str, Any]:
"""JSON Schema for a single trace event (the tagged union of event types)."""
return TypeAdapter(Event).json_schema()
|
metric_json_schema
metric_json_schema() -> dict[str, Any]
JSON Schema for the standard metric report.
Source code in qnetbench/spec.py
| def metric_json_schema() -> dict[str, Any]:
"""JSON Schema for the standard metric report."""
return Report.model_json_schema()
|
write_specs
write_specs(out_dir: str | Path) -> list[Path]
Write the trace and metric JSON Schemas to out_dir.
Source code in qnetbench/spec.py
| def write_specs(out_dir: str | Path) -> list[Path]:
"""Write the trace and metric JSON Schemas to `out_dir`."""
out = Path(out_dir)
out.mkdir(parents=True, exist_ok=True)
schemas = {
"trace-schema.json": trace_json_schema(),
"metric-schema.json": metric_json_schema(),
}
paths = []
for name, schema in schemas.items():
path = out / name
path.write_text(_dump(schema))
paths.append(path)
return paths
|
generate_reference_corpus
generate_reference_corpus(
out_dir: str | Path, seed: int = 0
) -> dict[str, Any]
Run every application once on the reference backend and write the JSONL
traces plus a manifest (spec version, seed, per-trace sha256 + event count).
Source code in qnetbench/spec.py
| def generate_reference_corpus(out_dir: str | Path, seed: int = 0) -> dict[str, Any]:
"""Run every application once on the reference backend and write the JSONL
traces plus a manifest (spec version, seed, per-trace sha256 + event count)."""
out = Path(out_dir)
out.mkdir(parents=True, exist_ok=True)
entries = []
for app in available_apps():
events = run_once(app, seed=seed, backend="reference")
path = out / f"{app}.jsonl"
write_trace(path, events)
digest = hashlib.sha256(path.read_bytes()).hexdigest()
entries.append({"app": app, "file": path.name, "n_events": len(events), "sha256": digest})
manifest = {
"spec_version": SPEC_VERSION,
"backend": "reference",
"seed": seed,
"traces": entries,
}
(out / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
return manifest
|