File size: 74,048 Bytes
2955ecc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 | """staged observable algorithm for synthetic datacenter scenarios"""
from __future__ import annotations
from copy import deepcopy
from datetime import datetime, timezone
from math import inf
from typing import Any
POLICY_THRESHOLD_OPERATIONS = 1.0e25
ALGORITHM_VERSION = "observable_staged_v0.3"
ELECTRICAL_SERVICE_WATTS_PER_ACCELERATOR = 900.0
ELECTRICAL_SERVICE_COUNT_EPSILON_FRACTION = 1e-6
SUPPORTING_ELECTRICAL_SERVICE_STATES = {
"active",
"energized",
"approved",
"in_service",
"connected",
"commissioned",
}
SCOPED_ELECTRICAL_SERVICE_CLASSES = {
"synthetic_datacenter_service",
}
NORMALIZED_OPERATION_UNITS = {
"",
"synthetic_normalized_operations",
"normalized_operations_per_second",
"flop_per_second",
"flops_per_second",
"operations_per_second",
}
THRESHOLDS: dict[str, float] = {
"policy_threshold_operations": POLICY_THRESHOLD_OPERATIONS,
"min_capacity_ruleout_coverage_fraction": 0.90,
"min_capacity_clock_alignment_confidence": 0.80,
"min_capacity_possible_coverage_fraction": 0.60,
"min_large_compute_coverage_fraction": 0.75,
"min_primary_B_channel_coverage_fraction": 0.75,
"min_activity_screen_score": 0.50,
"min_activity_screen_duration_seconds": 600.0,
"min_activity_for_fabric_pair": 0.55,
"min_fabric_cadence_pair_score": 0.60,
"min_activity_fabric_overlap_fraction": 0.50,
"min_activity_fabric_duration_seconds": 1800.0,
"min_activity_for_checkpoint_pair": 0.50,
"min_checkpoint_pair_score": 0.55,
"min_checkpoint_activity_adjacency_fraction": 0.50,
"min_checkpoint_pair_burst_count": 2.0,
"min_fabric_strong_identity_score": 0.75,
"min_checkpoint_strong_identity_score": 0.70,
"min_non_serving_pair_score": 0.60,
"min_serving_channel_coverage_fraction": 0.80,
"min_serving_suppression_score": 0.70,
"min_serving_activity_overlap_fraction": 0.50,
"min_operation_activity_overlap_fraction": 0.80,
"min_bytes_explained_fraction": 0.70,
"min_benchmark_like_cadence_score": 0.75,
"min_benchmark_regularity_score": 0.90,
"max_benchmark_duration_seconds": 7200.0,
"min_sparse_hpc_fabric_cadence_score": 0.60,
"min_sparse_hpc_activity_score": 0.50,
"min_sparse_hpc_overlap_fraction": 0.50,
"min_negative_screen_primary_coverage_fraction": 0.75,
"min_negative_screen_identity_coverage_fraction": 0.75,
"min_negative_screen_scope_mapping_coverage_fraction": 0.75,
"min_negative_screen_clock_alignment_confidence": 0.80,
"min_unattributed_activity_score": 0.70,
"min_unattributed_activity_duration_seconds": 600.0,
"max_attribution_overlap_fraction": 0.05,
"min_attribution_channel_coverage_fraction": 0.80,
"benign_attribution_explanation_overlap_fraction": 0.80,
"max_sparse_achieved_to_capacity_ratio": 1.10,
"min_sparse_capacity_conflict_coverage_fraction": 0.75,
"unit_or_hidden_capacity_suppression_score": 0.70,
}
WEBSITE_CONTROL_KEYS = [
"accelerator_count",
"peak_rate_ops_per_second",
"duration_hours",
"capacity_coverage",
"activity_score",
"activity_coverage",
"achieved_operations",
"achieved_ops_coverage",
"fabric_cadence_score",
"fabric_coverage",
"participant_count",
"checkpoint_score",
"checkpoint_burst_count",
"storage_coverage",
"serving_counterevidence_score",
"serving_coverage",
"serving_activity_overlap_fraction",
"storage_operation_explained_fraction",
"storage_operation_overlap_fraction",
"storage_operation_coverage",
"benchmark_regularity_score",
"benchmark_duration_seconds",
"hpc_mpi_score",
"hpc_overlap_fraction",
"benchmark_hpc_coverage",
"attribution_coverage",
"attribution_overlap_fraction",
"scope_mapping_coverage",
"clock_alignment_confidence",
"hidden_or_unmonitored_capacity_possible",
"physical_timeline_conflict",
"health_throttle_conflict",
"topology_route_conflict",
"power_activity_conflict",
]
def evaluate_sites(sites: list[dict[str, Any]]) -> list[dict[str, Any]]:
return [evaluate_site(site) for site in sites]
def evaluate_site(site: dict[str, Any]) -> dict[str, Any]:
scenario = deepcopy(site)
audit_window = scenario["audit_window"]
duration_seconds = _window_seconds(audit_window)
raw_features = scenario.get("raw_features", {})
coverage = scenario.get("coverage", {})
signals = scenario.get("normalized_signals", {})
derived = _derive_signals(scenario, duration_seconds)
sparse_outputs = _sparse_outputs(scenario, derived)
stage_a = _capacity_gate(scenario, derived)
if stage_a["short_circuited"]:
stage_b = {
"stage": "B_training_candidate_detection",
"mode": "skipped_due_to_capacity_ruleout",
"labels": [],
"positive_evidence_paths": [],
"warning_height": "none",
"notes": ["B was not run because A emitted capacity_ruled_out_for_scope."],
}
stage_c = {
"stage": "C_discrepancy_and_explanation_review",
"mode": "skipped_due_to_capacity_ruleout",
"labels": [],
"suppressors": [],
"explanations": [],
"discrepancies": [],
"missing_channels": [],
"notes": ["General C was not run after the capacity rule-out short circuit."],
}
else:
stage_b = _candidate_detection(scenario, derived, stage_a)
stage_c = _targeted_c_review(scenario, derived, stage_a, stage_b)
final = _final_route(scenario, derived, stage_a, stage_b, stage_c)
demo_state = _demo_state(scenario, derived)
discrepancy_findings = list(stage_c["discrepancies"])
if stage_a.get("ruleout_capacity_claim_conflict") and "capacity_claim_conflict" not in discrepancy_findings:
discrepancy_findings.append("capacity_claim_conflict")
return {
"algorithm_version": ALGORITHM_VERSION,
"site_id": scenario["site_id"],
"scenario_key": scenario["scenario_key"],
"scenario_name": scenario["scenario_name"],
"scope": scenario["scope"],
"audit_window": audit_window,
"duration_seconds": duration_seconds,
"raw_feature_ids": sorted(raw_features),
"minimal_sparse_outputs": sparse_outputs,
"derived_signals": derived,
"stage_outputs": {
"A_capacity_gate": stage_a,
"B_training_candidate_detection": stage_b,
"C_discrepancy_and_explanation_review": stage_c,
"final_claim_routing": final,
},
"final_route": final["label"],
"positive_evidence_paths": stage_b["positive_evidence_paths"],
"suppressors_or_explanations": stage_c["suppressors"] + stage_c["explanations"],
"discrepancy_findings": discrepancy_findings,
"missing_channels": stage_c["missing_channels"],
"caveats": final["caveats"],
"reader_numbers": final["reader_numbers"],
"coverage": coverage,
"normalized_signals": signals,
"demo_state": demo_state,
}
def _derive_signals(site: dict[str, Any], duration_seconds: float) -> dict[str, Any]:
raw = site.get("raw_features", {})
coverage = site.get("coverage", {})
signals = site.get("normalized_signals", {})
count = _sum(raw.get("accelerator_count_by_family_sku", []), "count")
has_negative_count = any(
_number(record.get("count"), 0.0) < 0
for record in raw.get("accelerator_count_by_family_sku", []) or []
)
peak_rate = _max(raw.get("advertised_peak_rate_by_precision", []), "peak_rate")
capacity_factor = _number(signals.get("capacity_adjustment_factor"), 1.0)
invalid_capacity_adjustment_factor = capacity_factor < 0
invalid_audit_window = duration_seconds <= 0
raw_capacity_upper = count * peak_rate * duration_seconds
capacity_upper = raw_capacity_upper * capacity_factor
normalized_raw_rates = [
_number(record.get("operation_rate"), 0.0)
for record in raw.get("generic_achieved_operation_rate", []) or []
if str(record.get("operation_unit", "") or "").lower() in NORMALIZED_OPERATION_UNITS
]
ignored_raw_rate_unit = any(
_number(record.get("operation_rate"), 0.0) > 0
and str(record.get("operation_unit", "") or "").lower() not in NORMALIZED_OPERATION_UNITS
for record in raw.get("generic_achieved_operation_rate", []) or []
)
achieved_rate = max(normalized_raw_rates) if normalized_raw_rates else 0.0
achieved_operations_from_override = "achieved_operations" in signals
achieved_operations = _number(signals.get("achieved_operations"), achieved_rate * duration_seconds)
achieved_unit_normalized = bool(signals.get("achieved_operations_unit_normalized", True))
if not achieved_operations_from_override and ignored_raw_rate_unit and not normalized_raw_rates:
achieved_unit_normalized = False
activity_score = max(
_max(raw.get("accelerator_busy_or_utilization_fraction", []), "value"),
_max(raw.get("tensor_matrix_mxu_neuron_or_engine_active_fraction", []), "value"),
_number(signals.get("activity_score"), 0.0),
)
fabric_score = _number(signals.get("collective_cadence_score"), _counter(raw, "collective_cadence_score"))
participant_count = _number(signals.get("participant_count"), _counter(raw, "participant_count"))
checkpoint_score = _number(signals.get("checkpoint_periodicity_score"), 0.0)
checkpoint_bursts = _number(
signals.get("checkpoint_burst_count"),
float(len(raw.get("storage_write_operation_bytes", []))),
)
serving_score_present = "serving_counterevidence_score" in signals
serving_score = _number(signals.get("serving_counterevidence_score"), 0.0)
non_serving_default = max(0.0, 1.0 - serving_score) if serving_score_present else 0.0
non_serving_score = _number(signals.get("non_serving_score"), non_serving_default)
benchmark_regularity = _number(signals.get("benchmark_regularity_score"), _counter(raw, "regularity_score"))
benchmark_duration = _number(signals.get("benchmark_duration_seconds"), duration_seconds)
hpc_score = _number(signals.get("hpc_mpi_score"), 0.0)
capacity_coverage = _coverage_cert(coverage, "capacity")
primary_min = min(
_coverage_cert(coverage, "activity"),
_coverage_cert(coverage, "achieved_ops"),
)
identity_coverage = _coverage(
coverage,
"identity_shape",
min(_coverage(coverage, "fabric"), _coverage(coverage, "storage")),
)
suppressor_coverage = min(
_coverage_cert(coverage, "serving"),
_coverage_cert(coverage, "storage_operations"),
_coverage_cert(coverage, "benchmark_hpc"),
)
scope_mapping = _coverage_cert(coverage, "scope_mapping")
clock_alignment = _coverage_cert(coverage, "clock_alignment")
capacity_ratio = achieved_operations / capacity_upper if capacity_upper > 0 else (inf if achieved_operations > 0 else 0.0)
return {
"capacity_segment_window": {
"start_time": site["audit_window"]["start"],
"end_time": site["audit_window"]["end"],
"duration_seconds": duration_seconds,
"invalid_audit_window": invalid_audit_window,
"capacity_coverage_fraction": capacity_coverage,
},
"capacity_upper_bound_flop": {
"unit_normalized": bool(signals.get("capacity_unit_normalized", True)),
"capacity_upper_bound_operations": capacity_upper,
"unadjusted_capacity_upper_bound_operations": raw_capacity_upper,
"coverage_fraction": capacity_coverage,
"hidden_or_unmonitored_capacity_possible": bool(
signals.get("hidden_or_unmonitored_capacity_possible", False)
),
"missing_required_peak_rate": peak_rate <= 0,
"has_negative_count": has_negative_count,
"invalid_audit_window": invalid_audit_window,
"invalid_capacity_adjustment_factor": invalid_capacity_adjustment_factor,
"count": count,
"peak_rate_ops_per_second": peak_rate,
"capacity_adjustment_factor": capacity_factor,
},
"achieved_operation_integral": {
"operation_count": achieved_operations,
"coverage_fraction": _coverage_cert(coverage, "achieved_ops"),
"unit_normalized": achieved_unit_normalized,
"ignored_raw_rate_unit": ignored_raw_rate_unit,
"operation_count_to_capacity_upper_bound_ratio": capacity_ratio,
},
"accelerator_activity_score": {
"activity_score": activity_score,
"duration_seconds": _number(signals.get("activity_duration_seconds"), duration_seconds),
"coverage_fraction": _coverage_cert(coverage, "activity"),
},
"collective_cadence_score": {
"cadence_score": fabric_score,
"coverage_fraction": _coverage_cert(coverage, "fabric"),
"participant_count": participant_count,
"activity_fabric_overlap_fraction": _number(signals.get("activity_fabric_overlap_fraction"), 0.0),
},
"checkpoint_periodicity_score": {
"checkpoint_score": checkpoint_score,
"burst_count": checkpoint_bursts,
"coverage_fraction": _coverage_cert(coverage, "storage"),
"checkpoint_activity_adjacency_fraction": _number(
signals.get("checkpoint_activity_adjacency_fraction"),
0.0,
),
},
"non_serving_score": {
"non_serving_score": non_serving_score,
"serving_counterevidence_score": serving_score,
"serving_counterevidence_present": serving_score_present,
"non_serving_score_present": "non_serving_score" in signals,
"coverage_fraction": _coverage_cert(coverage, "serving"),
"serving_activity_overlap_fraction": _number(signals.get("serving_activity_overlap_fraction"), 0.0),
},
"storage_operation_explanation": {
"operation_overlap_fraction": _number(signals.get("storage_operation_overlap_fraction"), 0.0),
"bytes_explained_fraction": _number(signals.get("bytes_explained_fraction"), 0.0),
"coverage_fraction": _coverage_cert(coverage, "storage_operations"),
},
"benchmark_hpc_alternative": {
"benchmark_regularity_score": benchmark_regularity,
"benchmark_duration_seconds": benchmark_duration,
"hpc_mpi_score": hpc_score,
"hpc_overlap_fraction": _number(signals.get("hpc_overlap_fraction"), 0.0),
"coverage_fraction": _coverage_cert(coverage, "benchmark_hpc"),
},
"negative_screen_required_coverage_state": {
"primary_activity_coverage_fraction": _coverage_cert(coverage, "activity"),
"achieved_ops_coverage_fraction": _coverage_cert(coverage, "achieved_ops"),
"identity_shape_coverage_fraction": identity_coverage,
"suppressor_channel_coverage_fraction": suppressor_coverage,
"scope_mapping_coverage_fraction": scope_mapping,
"clock_alignment_confidence": clock_alignment,
"decision_blocking_missingness": bool(signals.get("decision_blocking_missingness", False))
or invalid_audit_window,
"invalid_audit_window": invalid_audit_window,
},
"telemetry_coverage_fraction": {
"primary_channel_min": primary_min,
"identity_shape_coverage_fraction": identity_coverage,
"suppressor_channel_coverage_fraction": suppressor_coverage,
"scope_mapping_coverage_fraction": scope_mapping,
"clock_alignment_confidence": clock_alignment,
"missing_primary_channels": _missing_channels_for_threshold(site, threshold=0.75),
},
"clock_aligned_overlap_window": {
"clock_alignment_confidence": clock_alignment,
},
}
def _sparse_outputs(site: dict[str, Any], derived: dict[str, Any]) -> list[dict[str, str]]:
outputs: list[dict[str, str]] = []
cap = derived["capacity_upper_bound_flop"]
activity = derived["accelerator_activity_score"]
achieved = derived["achieved_operation_integral"]
fabric = derived["collective_cadence_score"]
checkpoint = derived["checkpoint_periodicity_score"]
non_serving = derived["non_serving_score"]
storage_op = derived["storage_operation_explanation"]
alternative = derived["benchmark_hpc_alternative"]
if cap["count"] > 0:
outputs.append(_output("accelerator_count_capacity_screen", "accelerator_count_threshold_capacity_screen", "capacity_count_or_shape"))
if cap["peak_rate_ops_per_second"] > 0:
outputs.append(_output("peak_rate_capacity_screen", "peak_rate_capacity_screen", "capacity_peak_rate"))
if cap["capacity_upper_bound_operations"] >= POLICY_THRESHOLD_OPERATIONS:
outputs.append(_output("capacity_threshold_possible", "threshold_scale_capacity_possible", "capacity_policy_scale"))
elif cap["coverage_fraction"] >= THRESHOLDS["min_capacity_possible_coverage_fraction"]:
outputs.append(_output("capacity_threshold_ruled_out", "threshold_scale_capacity_not_supported_sparse", "capacity_policy_scale"))
if (
activity["activity_score"] >= THRESHOLDS["min_activity_screen_score"]
and activity["duration_seconds"] >= THRESHOLDS["min_activity_screen_duration_seconds"]
):
outputs.append(_output("activity_only_screen", "accelerator_activity_screen", "accelerator_activity_run_existence"))
if (
achieved["operation_count"] >= POLICY_THRESHOLD_OPERATIONS
and achieved["coverage_fraction"] >= THRESHOLDS["min_large_compute_coverage_fraction"]
and achieved["unit_normalized"]
):
outputs.append(_output("large_compute_screen", "large_compute_candidate", "large_compute_scale"))
if _activity_fabric_pair(derived):
outputs.append(_output("activity_fabric_cadence_candidate", "collective_like_training_candidate", "fabric_parameter_update_like"))
if _activity_checkpoint_pair(derived):
outputs.append(_output("activity_checkpoint_candidate", "checkpoint_like_training_candidate", "storage_checkpoint_state_like"))
if (
activity["activity_score"] >= THRESHOLDS["min_activity_for_fabric_pair"]
and non_serving["non_serving_score"] >= THRESHOLDS["min_non_serving_pair_score"]
and non_serving["coverage_fraction"] >= THRESHOLDS["min_serving_channel_coverage_fraction"]
):
outputs.append(_output("activity_nonserving_candidate", "non_serving_accelerator_compute_candidate", "non_serving_workload_shape"))
if non_serving["serving_counterevidence_score"] >= 0.65 and non_serving["coverage_fraction"] >= 0.60:
outputs.append(_output("serving_like_network_counterevidence_screen", "serving_like_counterevidence_screen", "serving_counterevidence"))
if (
storage_op["operation_overlap_fraction"] >= THRESHOLDS["min_operation_activity_overlap_fraction"]
and storage_op["bytes_explained_fraction"] >= THRESHOLDS["min_bytes_explained_fraction"]
):
outputs.append(_output("storage_operation_explanation_screen", "storage_operation_explanation_screen", "storage_operation_explanation"))
if (
alternative["benchmark_regularity_score"] >= 0.85
or alternative["hpc_mpi_score"] >= THRESHOLDS["min_sparse_hpc_fabric_cadence_score"]
):
outputs.append(_output("benchmark_hpc_alternative_screen", "benchmark_or_hpc_alternative_screen", "benchmark_hpc_alternative"))
return outputs
def _capacity_gate(site: dict[str, Any], derived: dict[str, Any]) -> dict[str, Any]:
cap = derived["capacity_upper_bound_flop"]
coverage = cap["coverage_fraction"]
clock = derived["clock_aligned_overlap_window"]["clock_alignment_confidence"]
missing_required = (
not cap["unit_normalized"]
or cap["missing_required_peak_rate"]
or cap["has_negative_count"]
or cap["invalid_audit_window"]
or cap["invalid_capacity_adjustment_factor"]
or cap["count"] <= 0
or coverage < THRESHOLDS["min_capacity_possible_coverage_fraction"]
or clock < THRESHOLDS["min_capacity_clock_alignment_confidence"]
)
ruleout_eligible = (
cap["capacity_upper_bound_operations"] < POLICY_THRESHOLD_OPERATIONS
and cap["count"] > 0
and coverage >= THRESHOLDS["min_capacity_ruleout_coverage_fraction"]
and clock >= THRESHOLDS["min_capacity_clock_alignment_confidence"]
and not cap["hidden_or_unmonitored_capacity_possible"]
and not cap["missing_required_peak_rate"]
and not cap["has_negative_count"]
and not cap["invalid_audit_window"]
and not cap["invalid_capacity_adjustment_factor"]
and cap["unit_normalized"]
)
ruleout_capacity_claim_conflict = ruleout_eligible and _capacity_claim_contradicted(derived, site)
if ruleout_eligible and not ruleout_capacity_claim_conflict:
label = "capacity_ruled_out_for_scope"
confidence = "conservative_bound"
short_circuited = True
elif ruleout_capacity_claim_conflict:
label = "capacity_claim_conflict_blocks_ruleout"
confidence = "conflict"
short_circuited = False
elif missing_required:
label = "capacity_unknown_due_to_missing_inputs"
confidence = "weak"
short_circuited = False
elif cap["capacity_upper_bound_operations"] >= POLICY_THRESHOLD_OPERATIONS:
label = "capacity_possible_for_scope"
confidence = "screen"
short_circuited = False
else:
label = "capacity_limited_but_not_ruled_out"
confidence = "weak"
short_circuited = False
return {
"stage": "A_capacity_gate",
"label": label,
"labels": [label],
"confidence": confidence,
"short_circuited": short_circuited,
"capacity_upper_bound_operations": cap["capacity_upper_bound_operations"],
"coverage_fraction": coverage,
"clock_alignment_confidence": clock,
"hidden_or_unmonitored_capacity_possible": cap["hidden_or_unmonitored_capacity_possible"],
"missing_inputs": _capacity_missing_inputs(cap, coverage, clock),
"ruleout_capacity_claim_conflict": ruleout_capacity_claim_conflict,
"notes": _capacity_notes(label),
}
def _candidate_detection(site: dict[str, Any], derived: dict[str, Any], stage_a: dict[str, Any]) -> dict[str, Any]:
labels: list[str] = []
evidence_paths: list[str] = []
notes: list[str] = []
achieved = derived["achieved_operation_integral"]
telemetry = derived["telemetry_coverage_fraction"]
primary_coverage = telemetry["primary_channel_min"]
suppressor_coverage = telemetry["suppressor_channel_coverage_fraction"]
if (
achieved["operation_count"] >= POLICY_THRESHOLD_OPERATIONS
and achieved["coverage_fraction"] >= THRESHOLDS["min_large_compute_coverage_fraction"]
and achieved["unit_normalized"]
):
labels.append("large_compute_candidate")
evidence_paths.append("large_compute_scale")
notes.append("Achieved-operation integral crosses T_sys; workload identity remains unresolved without independent identity-shape evidence.")
if _activity_fabric_pair(derived) and primary_coverage >= THRESHOLDS["min_primary_B_channel_coverage_fraction"]:
labels.append("distributed_training_like_candidate")
evidence_paths.extend(["accelerator_activity_run_existence", "fabric_parameter_update_like"])
if _activity_checkpoint_pair(derived) and primary_coverage >= THRESHOLDS["min_primary_B_channel_coverage_fraction"]:
labels.append("checkpoint_training_like_candidate")
evidence_paths.extend(["accelerator_activity_run_existence", "storage_checkpoint_state_like"])
if (
"large_compute_candidate" in labels
and ("distributed_training_like_candidate" in labels or "checkpoint_training_like_candidate" in labels)
):
labels.append("sparse_large_compute_training_like_candidate")
identity_count = _identity_category_count(derived, labels)
if not labels:
warning_height = "none"
elif suppressor_coverage < THRESHOLDS["min_primary_B_channel_coverage_fraction"]:
warning_height = "weak_training_like_candidate"
notes.append("Suppressor coverage is incomplete, so B cannot promote medium or high warning.")
elif identity_count >= 2 and primary_coverage >= 0.85:
warning_height = "high_training_like_warning"
elif "distributed_training_like_candidate" in labels or "checkpoint_training_like_candidate" in labels:
warning_height = "medium_training_like_warning"
else:
warning_height = "weak_training_like_candidate"
return {
"stage": "B_training_candidate_detection",
"mode": "candidate_detection",
"capacity_input_label": stage_a["label"],
"labels": _unique(labels),
"positive_evidence_paths": _unique(evidence_paths),
"identity_category_count": identity_count,
"warning_height": warning_height,
"primary_channel_coverage_fraction": primary_coverage,
"suppressor_channel_coverage_fraction": suppressor_coverage,
"notes": notes,
}
def _targeted_c_review(
site: dict[str, Any],
derived: dict[str, Any],
stage_a: dict[str, Any],
stage_b: dict[str, Any],
) -> dict[str, Any]:
labels: list[str] = []
suppressors: list[str] = []
explanations: list[str] = []
discrepancies: list[str] = []
missing_channels: list[str] = []
notes: list[str] = []
candidate_labels = set(stage_b["labels"])
has_candidate = bool(candidate_labels)
if not has_candidate:
neg = derived["negative_screen_required_coverage_state"]
missing_channels = _negative_screen_missing_channels(neg)
incoherence_discrepancies = _negative_screen_incoherence(derived, site)
if missing_channels or neg["decision_blocking_missingness"]:
labels.extend(["negative_screen_blocked_by_missingness", "inconclusive_due_to_missingness"])
notes.append("C1 ran only the coverage, scope, and clock checks needed to adjudicate the negative screen.")
elif incoherence_discrepancies:
labels.extend(["negative_screen_incoherence_conflict", "integrity_review_required"])
discrepancies.extend(incoherence_discrepancies)
notes.append("C1 found strong identity-shape evidence without aligned activity and no benign explanation.")
else:
labels.append("negative_screen_coverage_sufficient")
notes.append("C1 verified primary, identity-shape, scope-mapping, and clock coverage for the no-candidate segment.")
return {
"stage": "C_discrepancy_and_explanation_review",
"mode": "C1_negative_screen_integrity",
"labels": labels,
"suppressors": suppressors,
"explanations": explanations,
"discrepancies": discrepancies,
"missing_channels": missing_channels,
"notes": notes,
}
non_serving = derived["non_serving_score"]
storage_op = derived["storage_operation_explanation"]
alternative = derived["benchmark_hpc_alternative"]
activity = derived["accelerator_activity_score"]
achieved = derived["achieved_operation_integral"]
cap = derived["capacity_upper_bound_flop"]
telemetry = derived["telemetry_coverage_fraction"]
signals = site.get("normalized_signals", {})
coverage = site.get("coverage", {})
if (
non_serving["serving_counterevidence_score"] >= THRESHOLDS["min_serving_suppression_score"]
and non_serving["serving_activity_overlap_fraction"] >= THRESHOLDS["min_serving_activity_overlap_fraction"]
and non_serving["coverage_fraction"] >= 0.60
):
labels.append("candidate_explained_by_serving")
suppressors.append("serving_counterevidence")
explanations.append("serving-like network shape overlaps the activity window.")
if (
("checkpoint_training_like_candidate" in candidate_labels or "distributed_training_like_candidate" in candidate_labels)
and storage_op["operation_overlap_fraction"] >= THRESHOLDS["min_operation_activity_overlap_fraction"]
and storage_op["bytes_explained_fraction"] >= THRESHOLDS["min_bytes_explained_fraction"]
):
labels.append("candidate_explained_by_storage_operation")
suppressors.append("storage_operation_explanation")
explanations.append("Explicit storage operation explains most overlapping checkpoint/fabric bytes.")
if (
alternative["benchmark_regularity_score"] >= THRESHOLDS["min_benchmark_regularity_score"]
and alternative["benchmark_duration_seconds"] <= THRESHOLDS["max_benchmark_duration_seconds"]
and alternative["coverage_fraction"] >= 0.60
):
labels.append("candidate_benchmark_like")
suppressors.append("benchmark_hpc_alternative")
explanations.append("Regular short collective cadence is benchmark-like.")
if (
alternative["hpc_mpi_score"] >= THRESHOLDS["min_sparse_hpc_fabric_cadence_score"]
and activity["activity_score"] >= THRESHOLDS["min_sparse_hpc_activity_score"]
and alternative["hpc_overlap_fraction"] >= THRESHOLDS["min_sparse_hpc_overlap_fraction"]
):
labels.append("candidate_hpc_mpi_alternative")
suppressors.append("benchmark_hpc_alternative")
explanations.append("Fabric-heavy activity aligns with an HPC/MPI alternative.")
if _capacity_claim_conflict(derived, signals):
labels.append("capacity_claim_conflict")
discrepancies.append("capacity_claim_conflict")
if _activity_attribution_conflict(derived, coverage, signals):
labels.append("activity_attribution_conflict")
discrepancies.append("activity_attribution_conflict")
for key, label in [
("physical_timeline_conflict", "physical_timeline_conflict"),
("health_throttle_conflict", "health_throttle_conflict"),
("topology_route_conflict", "topology_route_conflict"),
("power_activity_conflict", "power_activity_conflict"),
]:
if signals.get(key):
labels.append(label)
discrepancies.append(label)
for channel in _candidate_missing_channels(derived, candidate_labels):
if channel not in missing_channels:
missing_channels.append(channel)
if missing_channels:
labels.append("inconclusive_due_to_missingness")
if discrepancies:
labels.append("integrity_review_required")
elif missing_channels:
labels.append("candidate_requires_manual_review")
elif not _checked_suppressors(derived):
labels.append("candidate_demoted_by_unresolved_suppressor")
suppressors.append("missing_suppressor_coverage")
if "large_compute_candidate" in candidate_labels and _identity_category_count(derived, list(candidate_labels)) == 0:
notes.append("Large compute candidate has no independent fabric/checkpoint/non-serving identity support.")
surviving_identity_pathway = (
("serving_counterevidence" in suppressors and _checkpoint_pathway_strong(derived))
or ("storage_operation_explanation" in suppressors and _fabric_pathway_strong(derived))
)
return {
"stage": "C_discrepancy_and_explanation_review",
"mode": "C2_candidate_conflict_adjudication",
"labels": _unique(labels),
"suppressors": _unique(suppressors),
"explanations": _unique(explanations),
"discrepancies": _unique(discrepancies),
"missing_channels": _unique(missing_channels),
"notes": notes,
"surviving_identity_pathway": surviving_identity_pathway,
"achieved_to_capacity_ratio": achieved["operation_count_to_capacity_upper_bound_ratio"],
"capacity_upper_bound_operations": cap["capacity_upper_bound_operations"],
"suppressor_channel_coverage_fraction": telemetry["suppressor_channel_coverage_fraction"],
}
def _final_route(
site: dict[str, Any],
derived: dict[str, Any],
stage_a: dict[str, Any],
stage_b: dict[str, Any],
stage_c: dict[str, Any],
) -> dict[str, Any]:
c_labels = set(stage_c["labels"])
b_labels = set(stage_b["labels"])
caveats: list[str] = []
if derived["capacity_segment_window"].get("invalid_audit_window"):
label = "inconclusive_due_to_missingness"
elif stage_a["label"] == "capacity_ruled_out_for_scope":
label = "capacity_ruled_out_for_scope"
elif stage_a.get("ruleout_capacity_claim_conflict"):
label = "integrity_review_required"
elif "integrity_review_required" in c_labels:
label = "integrity_review_required"
elif "inconclusive_due_to_missingness" in c_labels and not b_labels:
label = "inconclusive_due_to_missingness"
elif c_labels.intersection(
{
"candidate_explained_by_serving",
"candidate_explained_by_storage_operation",
"candidate_benchmark_like",
"candidate_hpc_mpi_alternative",
"candidate_demoted_by_unresolved_suppressor",
}
):
if stage_c.get("surviving_identity_pathway"):
if _identity_category_count(derived, list(b_labels)) >= 2:
label = "high_training_like_warning"
else:
label = "medium_training_like_warning"
else:
label = "candidate_explained_or_demoted"
elif "inconclusive_due_to_missingness" in c_labels:
label = "inconclusive_due_to_missingness"
elif stage_b["warning_height"] == "high_training_like_warning":
label = "high_training_like_warning"
elif stage_b["warning_height"] == "medium_training_like_warning":
label = "medium_training_like_warning"
elif b_labels:
label = "weak_training_like_candidate"
elif "negative_screen_coverage_sufficient" in c_labels:
label = "no_training_like_candidate_detected_in_covered_live_segment"
else:
label = "inconclusive_due_to_missingness"
if "large_compute_candidate" in b_labels and not (
{"distributed_training_like_candidate", "checkpoint_training_like_candidate"} & b_labels
):
caveats.append("large_compute_training_identity_unresolved")
if stage_c["missing_channels"]:
caveats.append("decision_blocking_missing_channels: " + ", ".join(stage_c["missing_channels"]))
if stage_c["suppressors"]:
caveats.append("candidate suppressors/explanations checked: " + ", ".join(stage_c["suppressors"]))
if stage_a["missing_inputs"]:
caveats.append("capacity missing inputs: " + ", ".join(stage_a["missing_inputs"]))
reader_numbers = {
"capacity_upper_bound_operations": derived["capacity_upper_bound_flop"]["capacity_upper_bound_operations"],
"achieved_operations": derived["achieved_operation_integral"]["operation_count"],
"achieved_to_capacity_ratio": derived["achieved_operation_integral"]["operation_count_to_capacity_upper_bound_ratio"],
"activity_score": derived["accelerator_activity_score"]["activity_score"],
"fabric_cadence_score": derived["collective_cadence_score"]["cadence_score"],
"checkpoint_score": derived["checkpoint_periodicity_score"]["checkpoint_score"],
"serving_counterevidence_score": derived["non_serving_score"]["serving_counterevidence_score"],
"capacity_coverage": derived["capacity_upper_bound_flop"]["coverage_fraction"],
"primary_channel_coverage": derived["telemetry_coverage_fraction"]["primary_channel_min"],
"identity_shape_coverage": derived["telemetry_coverage_fraction"]["identity_shape_coverage_fraction"],
"scope_mapping_coverage": derived["telemetry_coverage_fraction"]["scope_mapping_coverage_fraction"],
"clock_alignment_confidence": derived["clock_aligned_overlap_window"]["clock_alignment_confidence"],
}
return {
"stage": "final_claim_routing",
"label": label,
"warning_height": label if label.endswith("_warning") or label == "weak_training_like_candidate" else "none",
"caveats": caveats,
"reader_numbers": reader_numbers,
"statement": _final_statement(label),
}
def _demo_state(site: dict[str, Any], derived: dict[str, Any]) -> dict[str, Any]:
cap = derived["capacity_upper_bound_flop"]
achieved = derived["achieved_operation_integral"]
activity = derived["accelerator_activity_score"]
fabric = derived["collective_cadence_score"]
checkpoint = derived["checkpoint_periodicity_score"]
non_serving = derived["non_serving_score"]
storage_op = derived["storage_operation_explanation"]
alternative = derived["benchmark_hpc_alternative"]
negative = derived["negative_screen_required_coverage_state"]
signals = site.get("normalized_signals", {})
coverage = site.get("coverage", {})
return {
"accelerator_count": cap["count"],
"peak_rate_ops_per_second": cap["peak_rate_ops_per_second"],
"duration_hours": derived["capacity_segment_window"]["duration_seconds"] / 3600.0,
"capacity_coverage": cap["coverage_fraction"],
"activity_score": activity["activity_score"],
"activity_coverage": activity["coverage_fraction"],
"achieved_operations": achieved["operation_count"],
"achieved_ops_coverage": achieved["coverage_fraction"],
"fabric_cadence_score": fabric["cadence_score"],
"fabric_coverage": fabric["coverage_fraction"],
"participant_count": fabric["participant_count"],
"checkpoint_score": checkpoint["checkpoint_score"],
"checkpoint_burst_count": checkpoint["burst_count"],
"storage_coverage": checkpoint["coverage_fraction"],
"serving_counterevidence_score": non_serving["serving_counterevidence_score"],
"serving_coverage": non_serving["coverage_fraction"],
"serving_activity_overlap_fraction": non_serving["serving_activity_overlap_fraction"],
"storage_operation_explained_fraction": storage_op["bytes_explained_fraction"],
"storage_operation_overlap_fraction": storage_op["operation_overlap_fraction"],
"storage_operation_coverage": storage_op["coverage_fraction"],
"benchmark_regularity_score": alternative["benchmark_regularity_score"],
"benchmark_duration_seconds": alternative["benchmark_duration_seconds"],
"hpc_mpi_score": alternative["hpc_mpi_score"],
"hpc_overlap_fraction": alternative["hpc_overlap_fraction"],
"benchmark_hpc_coverage": alternative["coverage_fraction"],
"attribution_coverage": _coverage(coverage, "attribution"),
"attribution_overlap_fraction": _number(signals.get("attribution_overlap_fraction"), 1.0),
"scope_mapping_coverage": negative["scope_mapping_coverage_fraction"],
"clock_alignment_confidence": negative["clock_alignment_confidence"],
"hidden_or_unmonitored_capacity_possible": cap["hidden_or_unmonitored_capacity_possible"],
"physical_timeline_conflict": bool(signals.get("physical_timeline_conflict", False)),
"health_throttle_conflict": bool(signals.get("health_throttle_conflict", False)),
"topology_route_conflict": bool(signals.get("topology_route_conflict", False)),
"power_activity_conflict": bool(signals.get("power_activity_conflict", False)),
}
def _activity_fabric_pair(derived: dict[str, Any]) -> bool:
activity = derived["accelerator_activity_score"]
fabric = derived["collective_cadence_score"]
return (
activity["activity_score"] >= THRESHOLDS["min_activity_for_fabric_pair"]
and fabric["cadence_score"] >= THRESHOLDS["min_fabric_cadence_pair_score"]
and fabric["activity_fabric_overlap_fraction"] >= THRESHOLDS["min_activity_fabric_overlap_fraction"]
and activity["duration_seconds"] >= THRESHOLDS["min_activity_fabric_duration_seconds"]
)
def _activity_checkpoint_pair(derived: dict[str, Any]) -> bool:
activity = derived["accelerator_activity_score"]
checkpoint = derived["checkpoint_periodicity_score"]
return (
activity["activity_score"] >= THRESHOLDS["min_activity_for_checkpoint_pair"]
and checkpoint["checkpoint_score"] >= THRESHOLDS["min_checkpoint_pair_score"]
and checkpoint["checkpoint_activity_adjacency_fraction"] >= THRESHOLDS["min_checkpoint_activity_adjacency_fraction"]
and checkpoint["burst_count"] >= THRESHOLDS["min_checkpoint_pair_burst_count"]
)
def _fabric_pathway_strong(derived: dict[str, Any]) -> bool:
return (
_activity_fabric_pair(derived)
and derived["collective_cadence_score"]["coverage_fraction"] >= THRESHOLDS["min_negative_screen_identity_coverage_fraction"]
)
def _checkpoint_pathway_strong(derived: dict[str, Any]) -> bool:
return (
_activity_checkpoint_pair(derived)
and derived["checkpoint_periodicity_score"]["coverage_fraction"] >= THRESHOLDS["min_negative_screen_identity_coverage_fraction"]
)
def _benign_identity_explanation(derived: dict[str, Any]) -> bool:
storage_op = derived["storage_operation_explanation"]
non_serving = derived["non_serving_score"]
alternative = derived["benchmark_hpc_alternative"]
activity = derived["accelerator_activity_score"]
storage_explained = (
storage_op["operation_overlap_fraction"] >= THRESHOLDS["min_operation_activity_overlap_fraction"]
and storage_op["bytes_explained_fraction"] >= THRESHOLDS["min_bytes_explained_fraction"]
)
serving_explained = (
non_serving["serving_counterevidence_score"] >= THRESHOLDS["min_serving_suppression_score"]
and non_serving["serving_activity_overlap_fraction"] >= THRESHOLDS["min_serving_activity_overlap_fraction"]
and non_serving["coverage_fraction"] >= 0.60
)
benchmark_explained = (
alternative["benchmark_regularity_score"] >= THRESHOLDS["min_benchmark_regularity_score"]
and alternative["benchmark_duration_seconds"] <= THRESHOLDS["max_benchmark_duration_seconds"]
and alternative["coverage_fraction"] >= 0.60
)
hpc_explained = (
alternative["hpc_mpi_score"] >= THRESHOLDS["min_sparse_hpc_fabric_cadence_score"]
and activity["activity_score"] >= THRESHOLDS["min_sparse_hpc_activity_score"]
and alternative["hpc_overlap_fraction"] >= THRESHOLDS["min_sparse_hpc_overlap_fraction"]
)
return storage_explained or serving_explained or benchmark_explained or hpc_explained
def _negative_screen_incoherence(derived: dict[str, Any], site: dict[str, Any]) -> list[str]:
fabric = derived["collective_cadence_score"]
checkpoint = derived["checkpoint_periodicity_score"]
negative = derived["negative_screen_required_coverage_state"]
identity_cov = THRESHOLDS["min_negative_screen_identity_coverage_fraction"]
fabric_coherent = (
fabric["cadence_score"] >= THRESHOLDS["min_fabric_strong_identity_score"]
and fabric["coverage_fraction"] >= identity_cov
)
checkpoint_coherent = (
checkpoint["checkpoint_score"] >= THRESHOLDS["min_checkpoint_strong_identity_score"]
and checkpoint["burst_count"] >= THRESHOLDS["min_checkpoint_pair_burst_count"]
and checkpoint["coverage_fraction"] >= identity_cov
)
activity = derived["accelerator_activity_score"]
activity_low = activity["activity_score"] < THRESHOLDS["min_activity_for_fabric_pair"]
primary_covered = negative["primary_activity_coverage_fraction"] >= identity_cov
alignment_discrepancies = _negative_screen_alignment_incoherence(derived)
raw_rate_discrepancies = _negative_screen_raw_rate_incoherence(derived, site)
blocking_discrepancies = alignment_discrepancies + raw_rate_discrepancies
if not (
((fabric_coherent or checkpoint_coherent) and activity_low and primary_covered)
or blocking_discrepancies
):
return []
if blocking_discrepancies:
discrepancies = list(blocking_discrepancies)
elif _benign_identity_explanation(derived):
return []
else:
discrepancies = []
if fabric_coherent:
discrepancies.append("fabric_without_job_or_topology_mapping_conflict")
if checkpoint_coherent:
discrepancies.append("checkpoint_writes_without_activity_conflict")
return discrepancies
def _negative_screen_alignment_incoherence(derived: dict[str, Any]) -> list[str]:
activity = derived["accelerator_activity_score"]
fabric = derived["collective_cadence_score"]
checkpoint = derived["checkpoint_periodicity_score"]
negative = derived["negative_screen_required_coverage_state"]
identity_cov = THRESHOLDS["min_negative_screen_identity_coverage_fraction"]
if negative["primary_activity_coverage_fraction"] < identity_cov:
return []
discrepancies: list[str] = []
if (
activity["activity_score"] >= THRESHOLDS["min_activity_for_fabric_pair"]
and fabric["cadence_score"] >= THRESHOLDS["min_fabric_strong_identity_score"]
and fabric["coverage_fraction"] >= identity_cov
and fabric["activity_fabric_overlap_fraction"] < THRESHOLDS["min_activity_fabric_overlap_fraction"]
):
discrepancies.append("fabric_activity_alignment_incoherence_conflict")
if (
activity["activity_score"] >= THRESHOLDS["min_activity_for_checkpoint_pair"]
and checkpoint["checkpoint_score"] >= THRESHOLDS["min_checkpoint_strong_identity_score"]
and checkpoint["burst_count"] >= THRESHOLDS["min_checkpoint_pair_burst_count"]
and checkpoint["coverage_fraction"] >= identity_cov
and checkpoint["checkpoint_activity_adjacency_fraction"] < THRESHOLDS[
"min_checkpoint_activity_adjacency_fraction"
]
):
discrepancies.append("checkpoint_activity_alignment_incoherence_conflict")
return discrepancies
def _negative_screen_raw_rate_incoherence(derived: dict[str, Any], site: dict[str, Any]) -> list[str]:
raw_integral = _normalized_raw_rate_integral(site.get("raw_features", {}), derived)
if raw_integral < POLICY_THRESHOLD_OPERATIONS:
return []
return ["raw_rate_threshold_compute_without_candidate_conflict"]
def _identity_category_count(derived: dict[str, Any], labels: list[str]) -> int:
categories = set()
if "distributed_training_like_candidate" in labels:
categories.add("fabric_parameter_update_like")
if "checkpoint_training_like_candidate" in labels:
categories.add("storage_checkpoint_state_like")
non_serving = derived["non_serving_score"]
if (
non_serving["non_serving_score"] >= THRESHOLDS["min_non_serving_pair_score"]
and non_serving["coverage_fraction"] >= THRESHOLDS["min_serving_channel_coverage_fraction"]
):
categories.add("non_serving_workload_shape")
return len(categories)
def _checked_suppressors(derived: dict[str, Any]) -> bool:
return derived["telemetry_coverage_fraction"]["suppressor_channel_coverage_fraction"] >= THRESHOLDS[
"min_primary_B_channel_coverage_fraction"
]
def _capacity_claim_contradicted(derived: dict[str, Any], site: dict[str, Any]) -> bool:
"""A small claimed capacity is contradicted by independent telemetry.
Generalizes the F2 achieved-vs-capacity guard to the whole coordinated-forge
class (F3): under-reporting the accelerator count to drop the capacity bound
below T_sys while shading achieved-operations down in lockstep keeps the
achieved/capacity ratio below 1.0, but other, independently reported scale
signals (the distributed-training participant set, the allocated inventory,
and billed device-seconds) still exceed the claimed count and are physically
incoherent with it. It also closes the peak-rate/adjustment deflation variant
(F4): when the bound is shaded through peak_rate or capacity_adjustment_factor
while the achieved_operations override is masked down, the raw achieved
operation-rate witness still integrates above the claimed bound. Finally it
closes the remaining device-population witnesses the genuine positive emits but
the four count-comparison sub-checks never read (F5): the running-accelerator
interval count, the compute-shape accelerator count, the reserved/reservation
capacity counts, the local-fabric device count, and the scale-out fabric
node/switch counts (each a physical floor on the accelerator population). Each
sub-check is gated on PRESENT, usable evidence: an absent signal never fires the
guard, so honest small-scope rule-outs (which report none of these signals) are
untouched. Every additive device-population witness is aggregated by its CONCURRENT
physical meaning (overlap-aware peak for the interval lists, sum across concurrent
fabric/interconnect domains for the per-domain tables), not by the single largest
record (F6): an operator who reports a large pool honestly as many concurrent
sub-pool records each below the claimed count is therefore caught, while genuine
sequential reuse of the same devices is not over-counted. The forge therefore
requires coherently suppressing or falsifying EVERY enumerated scale witness at
once, which is the disclosed irreducible residual.
"""
return bool(_capacity_claim_contradictions(derived, site))
def _capacity_claim_contradictions(derived: dict[str, Any], site: dict[str, Any]) -> list[str]:
cap = derived["capacity_upper_bound_flop"]
achieved = derived["achieved_operation_integral"]
count = cap["count"]
raw = site.get("raw_features", {})
signals = site.get("normalized_signals", {})
contradictions: list[str] = []
# (i) achieved-operation integral exceeds the capacity bound (the F2 case).
if (
"achieved_operations" in signals
and bool(signals.get("achieved_operations_unit_normalized", True))
and cap["capacity_upper_bound_operations"] > 0
and achieved["operation_count"] > cap["capacity_upper_bound_operations"]
):
contradictions.append("achieved_operations_exceed_capacity_bound")
# (ii) participant set larger than the claimed accelerator inventory.
participant_count = max(
derived["collective_cadence_score"]["participant_count"],
_counter(raw, "participant_count"),
)
if participant_count > 0 and count > 0 and participant_count > count:
contradictions.append("participant_count_exceeds_capacity_count")
# (iii) allocated/reserved accelerators exceed the reported inventory.
allocated_count = _positive_sum(raw.get("allocated_accelerator_count_by_sku", []) or [], "count")
if allocated_count > 0 and count > 0 and allocated_count > count:
contradictions.append("allocated_count_exceeds_capacity_count")
# (iv) billed device-seconds imply more concurrent devices than reported.
implied, billing_present = _billing_implied_device_count(raw, derived)
if billing_present and implied > 0 and count > 0 and implied > count:
contradictions.append("billing_device_hours_exceed_capacity_count")
# (v) raw achieved operation-rate witness exceeds the bound even when the
# achieved_operations override is masked down (the F4 peak/adjust-deflation
# variant: the bound is shaded via peak_rate or capacity_adjustment_factor
# and the override is reported low, but the independent raw rate integrates
# above the claimed bound).
raw_integral = _normalized_raw_rate_integral(raw, derived)
bound = cap["capacity_upper_bound_operations"]
if (
raw_integral > 0
and bound > 0
and raw_integral > bound
):
contradictions.append("raw_achieved_rate_integral_exceeds_capacity_bound")
if _capacity_adjustment_deflates_threshold_capacity(derived):
contradictions.append("capacity_adjustment_deflates_raw_threshold_capacity")
implied_service_devices, service_present = _electrical_service_implied_device_floor(raw)
count_epsilon = ELECTRICAL_SERVICE_COUNT_EPSILON_FRACTION * max(1.0, count)
if service_present and count > 0 and implied_service_devices > count + count_epsilon:
contradictions.append("electrical_service_power_floor_exceeds_capacity_count")
# (vi)-(xii) every other device-population witness the telemetry emits. Each is a
# direct count of accelerators (or a physical floor on the accelerator
# population) that an honest large run reports and that the F2/F3 forge leaves
# standing while it shades the accelerator_count_by_family_sku down. A witness
# fires only when it is actually reported (> 0) and exceeds the claimed count,
# so absent evidence never fires and the strict floor (witness > count) flips
# none of the legitimate rule-outs (where every emitted population witness is
# <= count). This closes the schema rather than any single field: the only way
# to forge the rule-out is to suppress ALL of these at once. The fabric-graph
# node/switch counts are population FLOORS (each fabric node hosts at least one
# accelerator and each switch serves at least one node), so node_count and
# switch_count exceeding the claimed count is physically incoherent; link_count
# is deliberately NOT a witness because links scale super-linearly with the
# accelerator population and exceed an honest count by construction.
# Each witness is aggregated by its CONCURRENT physical semantics
# (overlap-aware peak for the interval lists, sum across spatial/concurrent
# fabric/interconnect domains for the per-domain tables), NOT `_max`: an
# operator who reports one large pool HONESTLY as N concurrent sub-pool records
# each below the claimed count is therefore caught (F6), while genuine
# sequential reuse of the same devices is not over-counted.
for label, value in _device_population_witnesses(raw):
if value > 0 and count > 0 and value > count:
contradictions.append(label)
return contradictions
def _capacity_adjustment_deflates_threshold_capacity(derived: dict[str, Any]) -> bool:
cap = derived["capacity_upper_bound_flop"]
factor = cap["capacity_adjustment_factor"]
return (
factor < 1.0
and cap["unadjusted_capacity_upper_bound_operations"] >= POLICY_THRESHOLD_OPERATIONS
and cap["capacity_upper_bound_operations"] < POLICY_THRESHOLD_OPERATIONS
)
def _normalized_raw_rate_integral(raw: dict[str, Any], derived: dict[str, Any]) -> float:
duration = derived["capacity_segment_window"]["duration_seconds"]
rates = []
for record in raw.get("generic_achieved_operation_rate", []) or []:
unit = str(record.get("operation_unit", "") or "").lower()
if unit not in NORMALIZED_OPERATION_UNITS:
continue
rates.append(_number(record.get("operation_rate"), 0.0))
return (max(rates) if rates else 0.0) * duration
def _electrical_service_implied_device_floor(raw: dict[str, Any]) -> tuple[float, bool]:
service_intervals: list[dict[str, Any]] = []
present = False
for record in raw.get("electrical_service_status_intervals", []) or []:
status = str(record.get("service_status", "") or "").lower()
service_class = str(record.get("service_class", "") or "").lower()
if status not in SUPPORTING_ELECTRICAL_SERVICE_STATES:
continue
if service_class not in SCOPED_ELECTRICAL_SERVICE_CLASSES:
continue
values = [
_number(record.get(key), 0.0)
for key in ("service_capacity_mw", "power_mw", "mean_power_mw", "max_power_mw")
]
record_mw = max(values) if values else 0.0
if record_mw > 0:
present = True
service_intervals.append(
{
"start_time": record.get("start_time"),
"end_time": record.get("end_time"),
"service_mw": record_mw,
}
)
peak_mw = _concurrent_peak(service_intervals, "service_mw")
implied = peak_mw * 1_000_000.0 / ELECTRICAL_SERVICE_WATTS_PER_ACCELERATOR
return implied, present
def _device_population_witnesses(raw: dict[str, Any]) -> list[tuple[str, float]]:
"""Every reported device-population/training-scale count not covered by sub-checks
(i)-(v), paired with its conflict label. Each value is either a direct accelerator
count or a physical floor on the accelerator population (a fabric node hosts at
least one accelerator, a switch serves at least one node). Only PRESENT records are
summarized so the caller stays evidence-present-gated. link_count is excluded on
purpose: it is not a device population and scales above an honest count.
Each witness is aggregated by its CORRECT physical (concurrent) semantics, not by
`_max`. `_max` reads only the single largest record, so an operator who reports one
large pool HONESTLY as N concurrent sub-pool records each below the claimed count
defeats it while the true concurrent population stands far above the claim (F6).
The aggregation per witness is:
- compute_running_intervals / capacity_reservation_intervals /
reservation_state_intervals are interval_lists (each carries start_time and
end_time): overlap-aware concurrent PEAK (max over time of the sum of the count
across temporally overlapping intervals). Concurrent sub-pools add up to the
true population, but sequential reuse of the same devices does NOT over-count.
- scaleout_fabric_domain_graph node_count / switch_count and
local_accelerator_interconnect_domain local_fabric_device_count are per-domain
capability records (one record PER spatial/concurrent fabric or interconnect
domain): SUM across domains. A multi-domain cluster honestly emits one record
per domain, and the domains coexist, so the device population is the sum.
- instance_type_shape_machine_type already uses `_sum` (a labeled inventory table
whose rows are additive); it is immune and kept as-is.
"""
fabric_graph = raw.get("scaleout_fabric_domain_graph", []) or []
return [
# direct accelerator counts the operator reports elsewhere in inventory.
# The interval lists use the overlap-aware concurrent peak so split-pool
# concurrent sub-records sum, while genuine sequential reuse does not.
("running_accelerator_count_exceeds_capacity_count", _concurrent_peak(raw.get("compute_running_intervals", []) or [], "accelerator_count")),
("instance_shape_accelerator_count_exceeds_capacity_count", _positive_sum(raw.get("instance_type_shape_machine_type", []) or [], "accelerator_count")),
("reserved_accelerator_count_exceeds_capacity_count", _concurrent_peak(raw.get("capacity_reservation_intervals", []) or [], "reserved_accelerator_count")),
("reservation_capacity_count_exceeds_capacity_count", _concurrent_peak(raw.get("reservation_state_intervals", []) or [], "reservation_capacity_count")),
# per-domain interconnect records are spatial/concurrent: sum across domains.
("local_fabric_device_count_exceeds_capacity_count", _positive_sum(raw.get("local_accelerator_interconnect_domain", []) or [], "local_fabric_device_count")),
# fabric-topology floors on the accelerator population. One graph record per
# fabric domain, so node/switch counts sum across distinct concurrent domains.
("fabric_node_count_exceeds_capacity_count", _positive_sum(fabric_graph, "node_count")),
("fabric_switch_count_exceeds_capacity_count", _positive_sum(fabric_graph, "switch_count")),
]
def _billing_implied_device_count(
raw: dict[str, Any], derived: dict[str, Any]
) -> tuple[float, bool]:
"""Device-seconds billed over the window / window seconds = implied concurrent
device count. Only counts intervals reported in accelerator_seconds (the unit
the synthetic feed and the provider-account billing analogue both use); any other unit is
treated as not-usable evidence so the sub-check stays evidence-present-gated."""
intervals = raw.get("accelerator_compute_billing_usage_intervals") or []
duration = derived["capacity_segment_window"]["duration_seconds"]
total_device_seconds = 0.0
present = False
for interval in intervals:
if interval.get("usage_unit") == "accelerator_seconds":
quantity = _number(interval.get("usage_quantity"), 0.0)
if quantity > 0:
total_device_seconds += quantity
present = True
implied = total_device_seconds / duration if duration > 0 else 0.0
return implied, present
def _capacity_claim_conflict(derived: dict[str, Any], signals: dict[str, Any]) -> bool:
achieved = derived["achieved_operation_integral"]
cap = derived["capacity_upper_bound_flop"]
suppression = _number(signals.get("unit_mismatch_or_hidden_capacity_explanation_score"), 0.0)
return (
achieved["unit_normalized"]
and achieved["operation_count_to_capacity_upper_bound_ratio"] > THRESHOLDS["max_sparse_achieved_to_capacity_ratio"]
and cap["coverage_fraction"] >= THRESHOLDS["min_sparse_capacity_conflict_coverage_fraction"]
and suppression < THRESHOLDS["unit_or_hidden_capacity_suppression_score"]
)
def _activity_attribution_conflict(
derived: dict[str, Any],
coverage: dict[str, Any],
signals: dict[str, Any],
) -> bool:
activity = derived["accelerator_activity_score"]
return (
activity["activity_score"] >= THRESHOLDS["min_unattributed_activity_score"]
and activity["duration_seconds"] >= THRESHOLDS["min_unattributed_activity_duration_seconds"]
and _number(signals.get("attribution_overlap_fraction"), 1.0) <= THRESHOLDS["max_attribution_overlap_fraction"]
and _coverage(coverage, "attribution") >= THRESHOLDS["min_attribution_channel_coverage_fraction"]
and _number(signals.get("benign_attribution_explanation_overlap_fraction"), 0.0)
< THRESHOLDS["benign_attribution_explanation_overlap_fraction"]
)
def _candidate_missing_channels(derived: dict[str, Any], labels: set[str]) -> list[str]:
missing = []
telemetry = derived["telemetry_coverage_fraction"]
if telemetry["primary_channel_min"] < THRESHOLDS["min_primary_B_channel_coverage_fraction"]:
missing.append("primary_activity_or_achieved_ops")
if (
{"distributed_training_like_candidate", "checkpoint_training_like_candidate", "sparse_large_compute_training_like_candidate"}
& labels
and telemetry["identity_shape_coverage_fraction"] < THRESHOLDS["min_primary_B_channel_coverage_fraction"]
):
missing.append("identity_shape")
if telemetry["scope_mapping_coverage_fraction"] < THRESHOLDS["min_negative_screen_scope_mapping_coverage_fraction"]:
missing.append("scope_mapping")
if telemetry["clock_alignment_confidence"] < THRESHOLDS["min_negative_screen_clock_alignment_confidence"]:
missing.append("clock_alignment")
if telemetry["suppressor_channel_coverage_fraction"] < THRESHOLDS["min_primary_B_channel_coverage_fraction"]:
missing.append("suppressor_channels")
return missing
def _negative_screen_missing_channels(negative: dict[str, Any]) -> list[str]:
missing = []
if negative.get("invalid_audit_window"):
missing.append("audit_window")
if negative["primary_activity_coverage_fraction"] < THRESHOLDS["min_negative_screen_primary_coverage_fraction"]:
missing.append("primary_activity")
if negative["achieved_ops_coverage_fraction"] < THRESHOLDS["min_negative_screen_primary_coverage_fraction"]:
missing.append("achieved_ops")
if negative["identity_shape_coverage_fraction"] < THRESHOLDS["min_negative_screen_identity_coverage_fraction"]:
missing.append("identity_shape")
if negative["scope_mapping_coverage_fraction"] < THRESHOLDS["min_negative_screen_scope_mapping_coverage_fraction"]:
missing.append("scope_mapping")
if negative["clock_alignment_confidence"] < THRESHOLDS["min_negative_screen_clock_alignment_confidence"]:
missing.append("clock_alignment")
return missing
def _missing_channels_for_threshold(site: dict[str, Any], threshold: float) -> list[str]:
coverage = site.get("coverage", {})
return sorted(key for key, value in coverage.items() if isinstance(value, (int, float)) and value < threshold)
def _capacity_missing_inputs(cap: dict[str, Any], coverage: float, clock: float) -> list[str]:
missing = []
if cap.get("invalid_audit_window"):
missing.append("audit_window")
if cap["count"] <= 0 or cap["has_negative_count"]:
missing.append("accelerator_count_by_family_sku")
if cap["missing_required_peak_rate"]:
missing.append("advertised_peak_rate_by_precision")
if cap.get("invalid_capacity_adjustment_factor"):
missing.append("capacity_adjustment_factor")
if coverage < THRESHOLDS["min_capacity_possible_coverage_fraction"]:
missing.append("capacity_coverage")
if clock < THRESHOLDS["min_capacity_clock_alignment_confidence"]:
missing.append("clock_alignment")
if cap["hidden_or_unmonitored_capacity_possible"]:
missing.append("hidden_or_unmonitored_capacity_possible")
if not cap["unit_normalized"]:
missing.append("capacity_unit_normalization")
return missing
def _capacity_notes(label: str) -> list[str]:
if label == "capacity_ruled_out_for_scope":
return ["Conservative capacity upper bound is below T_sys with high coverage; B and C are skipped."]
if label == "capacity_claim_conflict_blocks_ruleout":
return [
"Independent capacity-scale witnesses contradict the reported capacity inputs; the rule-out is "
"withheld and routed to integrity review.",
]
if label == "capacity_possible_for_scope":
return ["Capacity remains live; A does not imply workload identity."]
if label == "capacity_limited_but_not_ruled_out":
return ["Capacity is below T_sys under current inputs, but coverage is not strong enough for a rule-out."]
return ["Capacity inputs are missing or insufficiently aligned; B/C remain live with missingness caveats."]
def _final_statement(label: str) -> str:
statements = {
"capacity_ruled_out_for_scope": "Threshold-scale compute is conservatively ruled out for this monitored scope/window.",
"no_training_like_candidate_detected_in_covered_live_segment": "No training-like candidate was detected and C1 coverage is sufficient to trust the negative screen.",
"weak_training_like_candidate": "A sparse candidate remains, but evidence is too incomplete or underdetermined for medium/high warning.",
"medium_training_like_warning": "Aligned activity and one training-like identity pathway survive targeted C review.",
"high_training_like_warning": "Multiple independent aligned identity/support pathways survive targeted C review.",
"candidate_explained_or_demoted": "Candidate evidence is explained or demoted by serving, storage-operation, benchmark, or HPC counterevidence.",
"integrity_review_required": "Targeted C found an unresolved discrepancy that blocks ordinary warning routing.",
"inconclusive_due_to_missingness": "Decision-blocking telemetry, scope, or clock coverage prevents a trusted positive or negative route.",
}
return statements.get(label, label)
def _output(rule_id: str, label: str, category: str) -> dict[str, str]:
return {"rule_id": rule_id, "label": label, "category": category}
def _sum(records: list[dict[str, Any]], key: str) -> float:
return sum(_number(record.get(key), 0.0) for record in records)
def _positive_sum(records: list[dict[str, Any]], key: str) -> float:
return sum(max(0.0, _number(record.get(key), 0.0)) for record in records)
def _max(records: list[dict[str, Any]], key: str) -> float:
values = [_number(record.get(key), 0.0) for record in records]
return max(values) if values else 0.0
def _concurrent_peak(records: list[dict[str, Any]], key: str) -> float:
"""Overlap-aware concurrent peak of an additive interval-list witness.
Returns the maximum over time of the SUM of `key` across temporally
OVERLAPPING intervals. Concurrent sub-pools (each its own interval-list
record over the same or overlapping windows) therefore add up to the true
concurrent device population, while SEQUENTIAL reuse of the same devices
(back-to-back, non-overlapping intervals) does NOT over-count: at any
instant only the records active then contribute. This is the correct
aggregation for `compute_running_intervals` and the reservation interval
lists, which are physically additive across concurrent records (the guard's
old `_max` read only the single largest record and was defeated by an
operator who reported one large pool as N concurrent sub-pool records each
below the claimed count).
If a record is missing start/end timestamps it is treated as active over
the whole window (it overlaps everything), so its value always contributes
to the peak. With every record fully concurrent (identical windows, the
honest representation of a single large run split into sub-pools) this
reduces to plain `_sum`. Endpoints are treated as half-open so that an
interval ending exactly when another begins (genuine sequential reuse) does
NOT count as overlapping.
"""
open_events: list[tuple[tuple[int, datetime], float]] = []
close_events: list[tuple[tuple[int, datetime], float]] = []
for record in records:
value = _number(record.get(key), 0.0)
if value <= 0:
continue
start_key, start_parsed = _interval_endpoint_key(record.get("start_time"), is_start=True)
end_key, end_parsed = _interval_endpoint_key(record.get("end_time"), is_start=False)
if start_parsed is not None and end_parsed is not None and end_parsed <= start_parsed:
continue
open_events.append((start_key, value))
close_events.append((end_key, value))
if not open_events:
return 0.0
open_events.sort(key=lambda item: item[0])
close_events.sort(key=lambda item: item[0])
current = 0.0
peak = 0.0
oi = 0
ci = 0
n = len(open_events)
# Sweep: process all closes that occur at-or-before the next open BEFORE the
# open (half-open intervals), so touching intervals do not count as
# concurrent, but genuinely overlapping ones do.
while oi < n:
if ci < n and close_events[ci][0] <= open_events[oi][0]:
current -= close_events[ci][1]
ci += 1
continue
current += open_events[oi][1]
oi += 1
if current > peak:
peak = current
return peak
def _interval_endpoint_key(value: Any, *, is_start: bool) -> tuple[tuple[int, datetime], datetime | None]:
parsed = _parse_iso_datetime(value)
if parsed is None:
sentinel = datetime.min.replace(tzinfo=timezone.utc) if is_start else datetime.max.replace(tzinfo=timezone.utc)
return ((0 if is_start else 2), sentinel), None
return (1, parsed), parsed
def _parse_iso_datetime(value: Any) -> datetime | None:
if not isinstance(value, str) or not value:
return None
text = value[:-1] + "+00:00" if value.endswith("Z") else value
try:
parsed = datetime.fromisoformat(text)
except ValueError:
return None
if parsed.tzinfo is None:
return parsed.replace(tzinfo=timezone.utc)
return parsed.astimezone(timezone.utc)
def _counter(raw_features: dict[str, Any], counter_name: str) -> float:
values = []
for record in raw_features.get("fabric_port_device_sample_counters", []):
if record.get("counter_name") == counter_name:
values.append(_number(record.get("counter_value"), 0.0))
return max(values) if values else 0.0
def _coverage(coverage: dict[str, Any], key: str, default: float = 1.0) -> float:
return _clamp(_number(coverage.get(key), default))
def _coverage_present(coverage: dict[str, Any], key: str) -> bool:
value = coverage.get(key)
return isinstance(value, (int, float)) and value == value
def _coverage_cert(coverage: dict[str, Any], key: str) -> float:
if not _coverage_present(coverage, key):
return 0.0
return _clamp(_number(coverage.get(key), 0.0))
def _number(value: Any, default: float = 0.0) -> float:
try:
number = float(value)
except (TypeError, ValueError):
return default
if number != number:
return default
return number
def _clamp(value: float, low: float = 0.0, high: float = 1.0) -> float:
return min(high, max(low, value))
def _window_seconds(window: dict[str, str]) -> float:
start = _parse_time(window["start"])
end = _parse_time(window["end"])
return (end - start).total_seconds()
def _parse_time(value: str) -> datetime:
if value.endswith("Z"):
value = value[:-1] + "+00:00"
parsed = datetime.fromisoformat(value)
if parsed.tzinfo is None:
parsed = parsed.replace(tzinfo=timezone.utc)
return parsed
def _unique(values: list[str]) -> list[str]:
out: list[str] = []
for value in values:
if value not in out:
out.append(value)
return out
|