quantrs2_tytan/advanced_performance_analysis/
config.rs

1//! Configuration for performance analysis
2
3use super::*;
4
5/// Configuration for performance analysis
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct AnalysisConfig {
8    /// Enable real-time monitoring
9    pub real_time_monitoring: bool,
10    /// Monitoring frequency (Hz)
11    pub monitoring_frequency: f64,
12    /// Metrics collection level
13    pub collection_level: MetricsLevel,
14    /// Analysis depth
15    pub analysis_depth: AnalysisDepth,
16    /// Enable comparative analysis
17    pub comparative_analysis: bool,
18    /// Enable performance prediction
19    pub performance_prediction: bool,
20    /// Statistical analysis settings
21    pub statistical_analysis: StatisticalAnalysisConfig,
22    /// Visualization settings
23    pub visualization: VisualizationConfig,
24}
25
26/// Levels of metrics collection
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28pub enum MetricsLevel {
29    /// Basic metrics only
30    Basic,
31    /// Detailed metrics
32    Detailed,
33    /// Comprehensive metrics with overhead
34    Comprehensive,
35    /// Custom metric selection
36    Custom { metrics: Vec<String> },
37}
38
39/// Analysis depth levels
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
41pub enum AnalysisDepth {
42    /// Surface-level analysis
43    Surface,
44    /// Deep analysis with statistical tests
45    Deep,
46    /// Exhaustive analysis with ML models
47    Exhaustive,
48    /// Real-time adaptive analysis
49    Adaptive,
50}
51
52/// Statistical analysis configuration
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct StatisticalAnalysisConfig {
55    /// Confidence level for intervals
56    pub confidence_level: f64,
57    /// Number of bootstrap samples
58    pub bootstrap_samples: usize,
59    /// Enable hypothesis testing
60    pub hypothesis_testing: bool,
61    /// Significance level
62    pub significance_level: f64,
63    /// Enable outlier detection
64    pub outlier_detection: bool,
65    /// Outlier detection method
66    pub outlier_method: OutlierDetectionMethod,
67}
68
69/// Outlier detection methods
70#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
71pub enum OutlierDetectionMethod {
72    /// Z-score based
73    ZScore { threshold: f64 },
74    /// Interquartile range
75    IQR { multiplier: f64 },
76    /// Isolation forest
77    IsolationForest,
78    /// Local outlier factor
79    LocalOutlierFactor,
80    /// Statistical tests
81    StatisticalTests,
82}
83
84/// Visualization configuration
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct VisualizationConfig {
87    /// Enable real-time plots
88    pub real_time_plots: bool,
89    /// Plot update frequency
90    pub plot_update_frequency: f64,
91    /// Export formats
92    pub export_formats: Vec<ExportFormat>,
93    /// Dashboard settings
94    pub dashboard: DashboardConfig,
95}
96
97/// Export formats for results
98#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
99pub enum ExportFormat {
100    CSV,
101    JSON,
102    PNG,
103    SVG,
104    PDF,
105    HTML,
106}
107
108/// Dashboard configuration
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct DashboardConfig {
111    /// Enable web dashboard
112    pub enable_web_dashboard: bool,
113    /// Dashboard port
114    pub port: u16,
115    /// Update interval (seconds)
116    pub update_interval: f64,
117    /// Enable alerts
118    pub enable_alerts: bool,
119    /// Alert thresholds
120    pub alert_thresholds: HashMap<String, f64>,
121}
122
123/// Create default analysis configuration
124pub fn create_default_analysis_config() -> AnalysisConfig {
125    AnalysisConfig {
126        real_time_monitoring: true,
127        monitoring_frequency: 1.0, // 1 Hz
128        collection_level: MetricsLevel::Detailed,
129        analysis_depth: AnalysisDepth::Deep,
130        comparative_analysis: true,
131        performance_prediction: true,
132        statistical_analysis: StatisticalAnalysisConfig {
133            confidence_level: 0.95,
134            bootstrap_samples: 1000,
135            hypothesis_testing: true,
136            significance_level: 0.05,
137            outlier_detection: true,
138            outlier_method: OutlierDetectionMethod::IQR { multiplier: 1.5 },
139        },
140        visualization: VisualizationConfig {
141            real_time_plots: true,
142            plot_update_frequency: 0.5, // 0.5 Hz
143            export_formats: vec![ExportFormat::PNG, ExportFormat::CSV, ExportFormat::HTML],
144            dashboard: DashboardConfig {
145                enable_web_dashboard: true,
146                port: 8080,
147                update_interval: 2.0, // 2 seconds
148                enable_alerts: true,
149                alert_thresholds: {
150                    let mut thresholds = HashMap::new();
151                    thresholds.insert("cpu_utilization".to_string(), 80.0);
152                    thresholds.insert("memory_utilization".to_string(), 85.0);
153                    thresholds.insert("io_utilization".to_string(), 90.0);
154                    thresholds
155                },
156            },
157        },
158    }
159}
160
161/// Create lightweight configuration for basic monitoring
162pub fn create_lightweight_config() -> AnalysisConfig {
163    let mut config = create_default_analysis_config();
164    config.collection_level = MetricsLevel::Basic;
165    config.analysis_depth = AnalysisDepth::Surface;
166    config.comparative_analysis = false;
167    config.performance_prediction = false;
168    config
169}