2 """Validation: Phase 3 planner-calibration density-aware signal surface. 4 Builds a representative contrast matrix across supported span-budget planner 5 candidates, records state-vector-style proxy scores alongside benchmark-grounded 6 density-aware scores, and shows that explicit noise placement changes the 7 recorded density-aware score on real noisy mixed-state workloads. 10 python benchmarks/density_matrix/planner_calibration/density_signal_validation.py 13 from __future__
import annotations
18 from collections
import defaultdict
19 from pathlib
import Path
21 REPO_ROOT = Path(__file__).resolve().parents[3]
22 if str(REPO_ROOT)
not in sys.path:
23 sys.path.insert(0, str(REPO_ROOT))
25 from benchmarks.density_matrix.partitioned_runtime.common
import (
26 execute_partitioned_with_reference,
28 from benchmarks.density_matrix.planner_calibration.signals
import (
29 PLANNER_CALIBRATION_DENSITY_AWARE_OBJECTIVE_NAME,
30 PLANNER_CALIBRATION_DENSITY_SIGNAL_SCHEMA_VERSION,
31 apply_density_scores_and_rankings,
32 build_density_signal_record,
34 from benchmarks.density_matrix.planner_calibration.case_selection
import (
35 iter_density_signal_cases,
37 from benchmarks.density_matrix.planner_surface.common
import build_software_metadata
38 from squander.partitioning.noisy_runtime
import PHASE3_RUNTIME_PATH_BASELINE
40 SUITE_NAME =
"phase3_planner_calibration_density_signal" 41 ARTIFACT_FILENAME =
"density_signal_bundle.json" 42 DEFAULT_OUTPUT_DIR = (
47 /
"planner_calibration" 50 ARTIFACT_CORE_FIELDS = (
53 "signal_schema_version",
60 def _signal_case(metadata: dict, descriptor_set, parameters) -> dict:
62 descriptor_set, parameters, allow_fusion=
False 74 records, objective_name=PLANNER_CALIBRATION_DENSITY_AWARE_OBJECTIVE_NAME
76 for record
in records:
77 record[
"density_signal_pass"] = (
78 record[
"signal_schema_version"] == PLANNER_CALIBRATION_DENSITY_SIGNAL_SCHEMA_VERSION
79 and record[
"runtime_path"] == PHASE3_RUNTIME_PATH_BASELINE
80 and record[
"partition_count"] > 0
81 and record[
"state_vector_proxy_score"] > 0.0
82 and record[
"density_aware_score"] > 0.0
83 and record[
"density_aware_rank"] >= 1
84 and record[
"state_vector_proxy_rank"] >= 1
90 grouped_scores: dict[tuple[str, str, int], dict[str, float]] = defaultdict(dict)
91 for record
in records:
92 if record[
"noise_pattern"]
is None:
95 record[
"candidate_id"],
96 record[
"family_name"]
or record[
"workload_family"],
99 grouped_scores[key][record[
"noise_pattern"]] = record[
"density_aware_score"]
102 len(score_by_pattern) > 1
103 and len({round(score, 12)
for score
in score_by_pattern.values()}) > 1
104 for score_by_pattern
in grouped_scores.values()
117 density_signal_passes = sum(case[
"density_signal_pass"]
for case
in cases)
120 "suite_name": SUITE_NAME,
122 if density_signal_passes == len(cases)
and noise_sensitive_slices >= 1
124 "signal_schema_version": PLANNER_CALIBRATION_DENSITY_SIGNAL_SCHEMA_VERSION,
127 "total_cases": len(cases),
128 "density_signal_passes": density_signal_passes,
129 "candidate_ids": sorted({case[
"candidate_id"]
for case
in cases}),
130 "workload_ids": sorted({case[
"workload_id"]
for case
in cases}),
131 "noise_patterns": sorted(
132 {case[
"noise_pattern"]
for case
in cases
if case[
"noise_pattern"]
is not None}
134 "noise_sensitive_slices": noise_sensitive_slices,
135 "calibrated_memory_weight": cases[0][
"calibrated_memory_weight"]
141 missing = [field
for field
in ARTIFACT_CORE_FIELDS
if field
not in bundle]
144 "Density-signal validation bundle missing required fields: {}".format(
152 output_dir.mkdir(parents=
True, exist_ok=
True)
153 output_path = output_dir / ARTIFACT_FILENAME
154 output_path.write_text(json.dumps(bundle, indent=2, sort_keys=
True) +
"\n")
158 def main(argv: list[str] |
None =
None) -> int:
159 parser = argparse.ArgumentParser(description=__doc__)
163 default=DEFAULT_OUTPUT_DIR,
164 help=
"Directory to write the density-signal validation bundle into.",
169 help=
"Suppress per-case console output.",
171 args = parser.parse_args(argv)
180 "{workload_id} {candidate_id}: density_score={density_aware_score:.3f}, proxy_score={state_vector_proxy_score:.3f}, rank={density_aware_rank}".format(
184 print(
"Wrote {}".format(output_path))
186 return 0
if bundle[
"status"] ==
"pass" else 1
189 if __name__ ==
"__main__":
190 raise SystemExit(
main())
def iter_density_signal_cases
def build_artifact_bundle
def apply_density_scores_and_rankings
def write_artifact_bundle
def _finalize_signal_records
def build_software_metadata()
def execute_partitioned_with_reference
def _noise_sensitive_slice_count
def build_density_signal_record