nlsq.streaming.telemetry¶
Telemetry and monitoring for the defense layer strategy.
Added in version 1.2.0: Extracted from nlsq.streaming.adaptive_hybrid for modularity.
This module provides telemetry infrastructure for the 4-layer defense strategy used in adaptive hybrid streaming optimization. It tracks activation counts, timing, and effectiveness metrics for each defense layer.
Defense Layers¶
The telemetry system monitors four defense layers:
Layer 1 - Warm Start: Detects when initial parameters are close to optimal
Layer 2 - Adaptive Step Size: Monitors step size adjustments
Layer 3 - Cost Guard: Tracks cost increase rejections
Layer 4 - Step Clipping: Records step size limiting events
Classes¶
DefenseLayerTelemetry¶
Main telemetry class that collects and reports on defense layer activity.
Module Contents¶
Telemetry for monitoring defense layer activations.
This module provides telemetry tracking for the 4-layer defense strategy used during L-BFGS warmup in the adaptive hybrid streaming optimizer.
- class nlsq.streaming.telemetry.DefenseLayerTelemetry[source]¶
Bases:
objectTelemetry for monitoring 4-layer defense strategy activations.
Tracks when each defense layer is triggered during warmup to help with production monitoring and tuning. This class maintains thread-safe statistics that can be queried or exported for monitoring dashboards.
- The 4 layers tracked are:
Layer 1: Warm start detection (skips warmup)
Layer 2: Adaptive step size selection (refinement/careful/exploration)
Layer 3: Cost-increase guard (aborts warmup if loss increases)
Layer 4: Step clipping (limits update magnitude)
- layer2_lr_mode_counts¶
Counts per LR mode: {“refinement”: n, “careful”: m, “exploration”: k}
- record_layer1_trigger(relative_loss, threshold)[source]¶
Record Layer 1 warm start detection trigger.
- record_layer3_trigger(cost_ratio, tolerance, iteration)[source]¶
Record Layer 3 cost-increase guard trigger.
- record_lbfgs_history_fill(iteration)[source]¶
Record L-BFGS history buffer fill event.
Called when the L-BFGS history buffer becomes fully populated, signaling transition from cold start to full L-BFGS mode.
- Parameters:
iteration (int) – Iteration number when history buffer filled
- record_lbfgs_line_search_failure(iteration, reason='')[source]¶
Record L-BFGS line search failure event.
Called when the L-BFGS line search fails to find an acceptable step.
- get_summary()[source]¶
Get summary statistics for all defense layers.
- Returns:
Summary with counts and rates for each layer
- Return type:
Usage Example¶
from nlsq.streaming.telemetry import DefenseLayerTelemetry
# Create telemetry instance
telemetry = DefenseLayerTelemetry()
# Record layer activations during optimization
telemetry.record_layer1_activation(cost_reduction=0.05)
telemetry.record_layer3_rejection(cost_increase=0.02)
# Get summary report
report = telemetry.get_summary()
print(f"Layer 1 activations: {report['layer1_count']}")
print(f"Layer 3 rejections: {report['layer3_count']}")
See Also¶
nlsq.adaptive_hybrid_streaming module - Main hybrid optimizer
nlsq.hybrid_streaming_config module - Configuration options