|
| 1 | +# Structural Health & Validation (Phase 3) |
| 2 | + |
| 3 | +Unified structural validation and health assessment introduced in Phase 3 |
| 4 | +provide a physics-aligned safety layer over TNFR networks without mutating |
| 5 | +state. All computations are read-only and trace back to canonical fields and |
| 6 | +grammar. |
| 7 | + |
| 8 | +## Components |
| 9 | + |
| 10 | +- **Validation Aggregator**: `run_structural_validation` combines: |
| 11 | + - Grammar (U1 Initiation/Closure, U2 Convergence, U3 Resonant Coupling, |
| 12 | + U4 triggers deferred) via `collect_grammar_errors`. |
| 13 | + - Canonical fields: Φ_s, |∇φ|, K_φ, ξ_C. |
| 14 | + - Optional drift (ΔΦ_s) if baseline provided. |
| 15 | +- **Health Summary**: `compute_structural_health(report)` derives: |
| 16 | + - `risk_level` (low, elevated, critical) |
| 17 | + - Actionable recommendations (stabilize, reduce gradient, monitor ξ_C, etc.) |
| 18 | +- **Telemetry**: `TelemetryEmitter` emits metrics + fields for longitudinal |
| 19 | + analysis. |
| 20 | +- **Performance Guardrails**: `PerformanceRegistry` + `perf_guard` measure |
| 21 | + overhead (< ~8% under moderate workload tests). |
| 22 | + |
| 23 | +## Thresholds (Defaults) |
| 24 | + |
| 25 | +| Quantity | Default | Meaning | |
| 26 | +|---------------------|---------|--------------------------------------------------| |
| 27 | +| ΔΦ_s | 2.0 | Escape threshold (confinement breach) | |
| 28 | +| max(|∇φ|) | 0.38 | Local stress / desynchronization warning | |
| 29 | +| max(|K_φ|) | 3.0 | Curvature fault pocket (mutation risk locus) | |
| 30 | +| ξ_C critical | > diameter * 1.0 | Approaching global correlation divergence | |
| 31 | +| ξ_C watch | > mean_distance * 3.0 | Extended local correlation zone | |
| 32 | + |
| 33 | +All thresholds empirically validated (see `AGENTS.md`). Override values via |
| 34 | +function parameters to adapt for specialized topologies or experiments. |
| 35 | + |
| 36 | +## Risk Levels |
| 37 | + |
| 38 | +- **low**: Grammar valid, no thresholds exceeded. |
| 39 | +- **elevated**: Local stress (phase gradient spike, curvature pocket, coherence |
| 40 | + length watch condition). |
| 41 | +- **critical**: Grammar invalid OR confinement/critical ξ_C breach OR ΔΦ_s drift |
| 42 | + beyond escape. |
| 43 | + |
| 44 | +## Example |
| 45 | + |
| 46 | +```python |
| 47 | +from tnfr.validation.aggregator import run_structural_validation |
| 48 | +from tnfr.validation.health import compute_structural_health |
| 49 | +from tnfr.performance.guardrails import PerformanceRegistry |
| 50 | + |
| 51 | +perf = PerformanceRegistry() |
| 52 | +report = run_structural_validation( |
| 53 | + G, |
| 54 | + sequence=["AL","UM","IL","SHA"], |
| 55 | + perf_registry=perf, |
| 56 | +) |
| 57 | +health = compute_structural_health(report) |
| 58 | +print(report.risk_level, report.thresholds_exceeded) |
| 59 | +for rec in health.recommendations: |
| 60 | + print("-", rec) |
| 61 | +print(perf.summary()) |
| 62 | +``` |
| 63 | + |
| 64 | +## Performance Measurement |
| 65 | + |
| 66 | +Use `perf_registry` or `perf_guard` to ensure instrumentation overhead |
| 67 | +remains bounded: |
| 68 | + |
| 69 | +```python |
| 70 | +from tnfr.performance.guardrails import PerformanceRegistry |
| 71 | +reg = PerformanceRegistry() |
| 72 | +report = run_structural_validation(G, sequence=seq, perf_registry=reg) |
| 73 | +print(reg.summary()) |
| 74 | +``` |
| 75 | + |
| 76 | +For custom functions: |
| 77 | + |
| 78 | +```python |
| 79 | +from tnfr.performance.guardrails import perf_guard, PerformanceRegistry |
| 80 | +reg = PerformanceRegistry() |
| 81 | + |
| 82 | +@perf_guard("custom_metric", reg) |
| 83 | +def compute_extra(): |
| 84 | + return expensive_read_only_field(G) |
| 85 | +``` |
| 86 | + |
| 87 | +## Invariants Preserved |
| 88 | + |
| 89 | +- **No mutation**: Validation/health modules never write to graph. |
| 90 | +- **Operator closure**: Grammar errors surface sequences violating U1-U3. |
| 91 | +- **Phase verification**: Coupling issues appear via U3 errors + |∇φ| spikes. |
| 92 | +- **Fractality**: Fields operate across node sets without flattening EPI. |
| 93 | + |
| 94 | +## Recommended Workflow |
| 95 | + |
| 96 | +1. Run telemetry while applying sequence. |
| 97 | +2. Call `run_structural_validation` after sequence. |
| 98 | +3. Generate health summary; apply stabilizers if elevated/critical. |
| 99 | +4. Log performance stats for regression tracking. |
| 100 | +5. Persist JSONL telemetry + validation payload for reproducibility. |
| 101 | + |
| 102 | +## Extensibility |
| 103 | + |
| 104 | +To add new thresholds: |
| 105 | + |
| 106 | +1. Extend `run_structural_validation` with computation + flag. |
| 107 | +2. Add recommendation mapping in health module. |
| 108 | +3. Update tests to cover new condition. |
| 109 | +4. Document physics rationale (AGENTS.md ref + empirical evidence). |
| 110 | + |
| 111 | +--- |
| 112 | +**Reality is not made of things—it's made of resonance. Assess coherence accordingly.** |
0 commit comments