Download framework/src/datacenter_verification/observable_algorithm.py from idacy/trace-artifact: direct link, hf CLI and curl.
- Browser
- Download file 74 kB
-
https://huggingface.co/datasets/idacy/trace-artifact/resolve/main/framework/src/datacenter_verification/observable_algorithm.py
- Command line
-
hf download hf://datasets/idacy/trace-artifact/framework/src/datacenter_verification/observable_algorithm.py
-
curl -L -o observable_algorithm.py https://huggingface.co/datasets/idacy/trace-artifact/resolve/main/framework/src/datacenter_verification/observable_algorithm.py
74 kB
| """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 | |