Skip to main content

quantrs2_device/telemetry/
functions.rs

1//! Auto-generated module
2//!
3//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
4
5use crate::{
6    backend_traits::BackendCapabilities, calibration::DeviceCalibration,
7    topology::HardwareTopology, DeviceError, DeviceResult,
8};
9#[cfg(not(feature = "scirs2"))]
10use fallback_scirs2::*;
11use quantrs2_circuit::prelude::*;
12use scirs2_core::ndarray::{Array1, Array2, ArrayView1};
13use std::collections::{BTreeMap, HashMap, VecDeque};
14use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
15
16use super::types::{
17    Alert, AlertConfig, AlertSeverity, AnalyticsConfig, AnomalyDetectorConfig, AnomalyResult,
18    ExportConfig, Metric, MetricConfig, MetricType, MonitoringConfig, QuantumTelemetrySystem,
19    RetentionConfig, TelemetryConfig,
20};
21
22#[cfg(not(feature = "scirs2"))]
23mod fallback_scirs2 {
24    use scirs2_core::ndarray::{Array1, ArrayView1};
25    pub fn mean(_data: &ArrayView1<f64>) -> Result<f64, String> {
26        Ok(0.0)
27    }
28    pub fn std(_data: &ArrayView1<f64>, _ddof: i32) -> Result<f64, String> {
29        Ok(1.0)
30    }
31    pub fn var(_data: &ArrayView1<f64>, _ddof: i32) -> Result<f64, String> {
32        Ok(1.0)
33    }
34    pub fn percentile(_data: &ArrayView1<f64>, _q: f64) -> Result<f64, String> {
35        Ok(0.0)
36    }
37}
38/// Metric collector trait
39pub trait MetricCollector: Send + Sync {
40    /// Collect metrics
41    fn collect(&self) -> DeviceResult<Vec<Metric>>;
42    /// Get collector name
43    fn name(&self) -> &str;
44    /// Get collection interval
45    fn interval(&self) -> Duration;
46    /// Check if collector is enabled
47    fn is_enabled(&self) -> bool;
48}
49/// Anomaly detector trait
50pub trait AnomalyDetector: Send + Sync {
51    /// Detect anomalies in metric data
52    fn detect(&self, data: &[f64]) -> Vec<AnomalyResult>;
53    /// Update detector with new data
54    fn update(&mut self, data: &[f64]);
55    /// Get detector configuration
56    fn config(&self) -> AnomalyDetectorConfig;
57}
58/// Notification channel trait
59pub trait NotificationChannel: Send + Sync {
60    /// Send notification
61    fn send(&self, alert: &Alert) -> DeviceResult<()>;
62    /// Get channel name
63    fn name(&self) -> &str;
64    /// Check if channel is enabled
65    fn is_enabled(&self) -> bool;
66}
67/// Create a default telemetry system
68pub fn create_telemetry_system() -> QuantumTelemetrySystem {
69    QuantumTelemetrySystem::new(TelemetryConfig::default())
70}
71/// Create a high-performance telemetry configuration
72pub fn create_high_performance_telemetry_config() -> TelemetryConfig {
73    TelemetryConfig {
74        enabled: true,
75        collection_interval: 10,
76        enable_realtime_monitoring: true,
77        enable_analytics: true,
78        enable_alerting: true,
79        retention_config: RetentionConfig {
80            realtime_retention_hours: 48,
81            historical_retention_days: 90,
82            aggregated_retention_months: 24,
83            enable_compression: true,
84            archive_threshold_gb: 50.0,
85        },
86        metric_config: MetricConfig {
87            enable_performance_metrics: true,
88            enable_resource_metrics: true,
89            enable_error_metrics: true,
90            enable_cost_metrics: true,
91            enable_custom_metrics: true,
92            sampling_rate: 1.0,
93            batch_size: 500,
94        },
95        monitoring_config: MonitoringConfig {
96            dashboard_refresh_rate: 1,
97            health_check_interval: 30,
98            anomaly_sensitivity: 0.9,
99            enable_trend_analysis: true,
100            monitoring_targets: Vec::new(),
101        },
102        analytics_config: AnalyticsConfig {
103            enable_statistical_analysis: true,
104            enable_predictive_analytics: true,
105            enable_correlation_analysis: true,
106            processing_interval_minutes: 5,
107            confidence_level: 0.99,
108            prediction_horizon_hours: 72,
109        },
110        alert_config: AlertConfig {
111            enable_email_alerts: true,
112            enable_sms_alerts: true,
113            enable_webhook_alerts: true,
114            enable_slack_alerts: true,
115            thresholds: HashMap::new(),
116            escalation_rules: Vec::new(),
117            suppression_rules: Vec::new(),
118        },
119        export_config: ExportConfig {
120            enable_prometheus: true,
121            enable_influxdb: true,
122            enable_grafana: true,
123            enable_custom_exports: true,
124            export_endpoints: HashMap::new(),
125        },
126    }
127}
128#[cfg(test)]
129mod tests {
130    use super::*;
131    #[test]
132    fn test_telemetry_config_default() {
133        let config = TelemetryConfig::default();
134        assert!(config.enabled);
135        assert_eq!(config.collection_interval, 30);
136        assert!(config.enable_realtime_monitoring);
137        assert!(config.enable_analytics);
138        assert!(config.enable_alerting);
139    }
140    #[test]
141    fn test_metric_creation() {
142        let metric = Metric {
143            name: "test_metric".to_string(),
144            value: 42.0,
145            unit: "units".to_string(),
146            metric_type: MetricType::Gauge,
147            timestamp: SystemTime::now(),
148            labels: HashMap::new(),
149            metadata: HashMap::new(),
150        };
151        assert_eq!(metric.name, "test_metric");
152        assert_eq!(metric.value, 42.0);
153        assert_eq!(metric.metric_type, MetricType::Gauge);
154    }
155    #[test]
156    fn test_telemetry_system_creation() {
157        let config = TelemetryConfig::default();
158        let system = QuantumTelemetrySystem::new(config);
159    }
160    #[test]
161    fn test_alert_severity_ordering() {
162        assert!(AlertSeverity::Info < AlertSeverity::Warning);
163        assert!(AlertSeverity::Warning < AlertSeverity::Critical);
164        assert!(AlertSeverity::Critical < AlertSeverity::Emergency);
165    }
166    #[tokio::test]
167    async fn test_telemetry_start_stop() {
168        let config = TelemetryConfig::default();
169        let system = QuantumTelemetrySystem::new(config);
170        let start_result = system.start().await;
171        assert!(start_result.is_ok());
172        let stop_result = system.stop().await;
173        assert!(stop_result.is_ok());
174    }
175}