1 from __future__
import annotations
3 from copy
import deepcopy
4 from functools
import lru_cache
6 from collections
import defaultdict
8 from benchmarks.density_matrix.planner_calibration.calibration_records
import (
9 build_planner_calibration_calibration_records,
12 PLANNER_CALIBRATION_CLAIM_SELECTION_SCHEMA_VERSION =
"phase3_planner_calibration_claim_selection_v1" 13 PLANNER_CALIBRATION_CLAIM_SELECTION_RULE = (
14 "min_median_density_aware_score_then_min_p90_then_smaller_span_budget" 16 PLANNER_CALIBRATION_CLAIM_STATUS_SUPPORTED =
"supported_claim" 17 PLANNER_CALIBRATION_CLAIM_STATUS_COMPARISON =
"comparison_baseline" 20 def _p90(values: list[float]) -> float:
21 ordered = sorted(values)
22 index =
int(0.9 * (len(ordered) - 1))
23 return float(ordered[index])
27 density_scores = [record[
"density_aware_score"]
for record
in records]
28 runtime_values = [record[
"runtime_ms"]
for record
in records]
29 planning_values = [record[
"planning_time_ms"]
for record
in records]
30 peak_rss_values = [record[
"peak_rss_mb"]
for record
in records]
32 "candidate_id": candidate_id,
33 "planner_family": records[0][
"planner_family"],
34 "planner_variant": records[0][
"planner_variant"],
35 "max_partition_qubits": records[0][
"max_partition_qubits"],
36 "total_cases": len(records),
37 "counted_cases": sum(record[
"counted_calibration_case"]
for record
in records),
38 "median_density_aware_score": float(statistics.median(density_scores)),
39 "p90_density_aware_score":
_p90(density_scores),
40 "max_density_aware_score": float(max(density_scores)),
41 "mean_runtime_ms": float(statistics.mean(runtime_values)),
42 "mean_planning_time_ms": float(statistics.mean(planning_values)),
43 "mean_peak_rss_mb": float(statistics.mean(peak_rss_values)),
51 summary[
"median_density_aware_score"],
52 summary[
"p90_density_aware_score"],
53 summary[
"max_partition_qubits"],
54 summary[
"candidate_id"],
62 grouped_records: dict[str, list[dict]] = defaultdict(list)
63 for record
in records:
64 grouped_records[record[
"candidate_id"]].append(record)
66 candidate_summaries = [
68 for candidate_id
in sorted(grouped_records)
71 selected_candidate_id = selected_summary[
"candidate_id"]
73 annotated_records = []
74 for record
in records:
75 annotated_record = dict(record)
76 annotated_record[
"claim_selection_schema_version"] = (
77 PLANNER_CALIBRATION_CLAIM_SELECTION_SCHEMA_VERSION
79 annotated_record[
"claim_selection_rule"] = PLANNER_CALIBRATION_CLAIM_SELECTION_RULE
80 annotated_record[
"selected_candidate_id"] = selected_candidate_id
81 annotated_record[
"claim_status"] = (
82 PLANNER_CALIBRATION_CLAIM_STATUS_SUPPORTED
83 if record[
"candidate_id"] == selected_candidate_id
84 else PLANNER_CALIBRATION_CLAIM_STATUS_COMPARISON
86 annotated_records.append(annotated_record)
89 "schema_version": PLANNER_CALIBRATION_CLAIM_SELECTION_SCHEMA_VERSION,
90 "claim_selection_rule": PLANNER_CALIBRATION_CLAIM_SELECTION_RULE,
91 "selected_candidate": selected_summary,
92 "candidate_summaries": candidate_summaries,
93 "cases": annotated_records,
def _build_planner_calibration_claim_selection_payload_cached()
def build_planner_calibration_calibration_records()
def select_supported_candidate
def build_planner_calibration_claim_selection_payload()
def _build_candidate_summary
def build_claim_selection_payload()