quantrs2_device/hardware_parallelization/
config_defaults.rs

1//! Default implementations for configuration types
2
3use super::config::*;
4use quantrs2_core::platform::PlatformCapabilities;
5use std::time::Duration;
6
7impl Default for ParallelizationConfig {
8    fn default() -> Self {
9        Self {
10            strategy: ParallelizationStrategy::Hybrid,
11            resource_allocation: ResourceAllocationConfig::default(),
12            scheduling_config: ParallelSchedulingConfig::default(),
13            hardware_awareness: HardwareAwarenessConfig::default(),
14            performance_config: PerformanceOptimizationConfig::default(),
15            load_balancing: LoadBalancingConfig::default(),
16            monitoring_config: ResourceMonitoringConfig::default(),
17        }
18    }
19}
20
21impl Default for ResourceAllocationConfig {
22    fn default() -> Self {
23        Self {
24            max_concurrent_circuits: PlatformCapabilities::detect().cpu.logical_cores,
25            max_concurrent_gates: 16,
26            cpu_allocation: CpuAllocationStrategy::PercentageCores(0.8),
27            memory_limits: MemoryLimits::default(),
28            qpu_allocation: QpuAllocationConfig::default(),
29            network_allocation: NetworkAllocationConfig::default(),
30        }
31    }
32}
33
34impl Default for MemoryLimits {
35    fn default() -> Self {
36        Self {
37            max_total_memory_mb: 8192.0, // 8GB
38            max_per_circuit_mb: 1024.0,  // 1GB
39            allocation_strategy: MemoryAllocationStrategy::Dynamic,
40            enable_pooling: true,
41            gc_threshold: 0.8,
42        }
43    }
44}
45
46impl Default for QpuAllocationConfig {
47    fn default() -> Self {
48        Self {
49            max_qpu_time_per_circuit: Duration::from_secs(300), // 5 minutes
50            sharing_strategy: QpuSharingStrategy::HybridSlicing,
51            queue_management: QueueManagementConfig::default(),
52            fairness_config: FairnessConfig::default(),
53        }
54    }
55}
56
57impl Default for QueueManagementConfig {
58    fn default() -> Self {
59        Self {
60            algorithm: QueueSchedulingAlgorithm::Priority,
61            max_queue_size: 1000,
62            priority_levels: 5,
63            enable_preemption: true,
64            timeout_config: TimeoutConfig::default(),
65        }
66    }
67}
68
69impl Default for TimeoutConfig {
70    fn default() -> Self {
71        Self {
72            execution_timeout: Duration::from_secs(3600), // 1 hour
73            queue_timeout: Duration::from_secs(1800),     // 30 minutes
74            resource_timeout: Duration::from_secs(300),   // 5 minutes
75            adaptive_timeouts: true,
76        }
77    }
78}
79
80impl Default for FairnessConfig {
81    fn default() -> Self {
82        Self {
83            algorithm: FairnessAlgorithm::ProportionalFair,
84            resource_quotas: ResourceQuotas::default(),
85            aging_factor: 1.1,
86            enable_burst_allowances: true,
87        }
88    }
89}
90
91impl Default for ResourceQuotas {
92    fn default() -> Self {
93        Self {
94            cpu_quota: Some(Duration::from_secs(3600 * 24)), // 24 hours per day
95            qpu_quota: Some(Duration::from_secs(3600)),      // 1 hour per day
96            memory_quota: Some(16384.0),                     // 16GB
97            circuit_quota: Some(1000),                       // 1000 circuits per day
98        }
99    }
100}
101
102impl Default for NetworkAllocationConfig {
103    fn default() -> Self {
104        Self {
105            max_bandwidth_per_circuit: 100.0, // 100 Mbps
106            qos_class: NetworkQoSClass::BestEffort,
107            compression_config: CompressionConfig::default(),
108            latency_optimization: true,
109        }
110    }
111}
112
113impl Default for CompressionConfig {
114    fn default() -> Self {
115        Self {
116            enabled: true,
117            algorithm: CompressionAlgorithm::Zstd,
118            level: 3,
119            size_threshold: 1024, // 1KB
120        }
121    }
122}
123
124impl Default for ParallelSchedulingConfig {
125    fn default() -> Self {
126        Self {
127            algorithm: ParallelSchedulingAlgorithm::WorkStealing,
128            work_stealing: WorkStealingConfig::default(),
129            load_balancing_params: LoadBalancingParams::default(),
130            thread_pool_config: ThreadPoolConfig::default(),
131        }
132    }
133}
134
135impl Default for WorkStealingConfig {
136    fn default() -> Self {
137        Self {
138            enabled: true,
139            strategy: WorkStealingStrategy::LoadBased,
140            queue_size: 1000,
141            stealing_threshold: 0.5,
142        }
143    }
144}
145
146impl Default for LoadBalancingParams {
147    fn default() -> Self {
148        Self {
149            rebalancing_frequency: Duration::from_secs(30),
150            load_threshold: 0.8,
151            migration_cost_factor: 0.1,
152            adaptive_balancing: true,
153        }
154    }
155}
156
157impl Default for ThreadPoolConfig {
158    fn default() -> Self {
159        Self {
160            core_threads: PlatformCapabilities::detect().cpu.logical_cores,
161            max_threads: PlatformCapabilities::detect().cpu.logical_cores * 2,
162            keep_alive_time: Duration::from_secs(60),
163            thread_priority: ThreadPriority::Normal,
164            affinity_config: ThreadAffinityConfig::default(),
165        }
166    }
167}
168
169impl Default for ThreadAffinityConfig {
170    fn default() -> Self {
171        Self {
172            enabled: false,
173            assignment_strategy: CoreAssignmentStrategy::Automatic,
174            numa_preference: NumaPreference::None,
175        }
176    }
177}
178
179impl Default for HardwareAwarenessConfig {
180    fn default() -> Self {
181        Self {
182            topology_awareness: TopologyAwarenessLevel::Connectivity,
183            calibration_integration: CalibrationIntegrationConfig::default(),
184            error_rate_config: ErrorRateConfig::default(),
185            connectivity_config: ConnectivityConfig::default(),
186            resource_tracking: ResourceTrackingConfig::default(),
187        }
188    }
189}
190
191impl Default for CalibrationIntegrationConfig {
192    fn default() -> Self {
193        Self {
194            use_realtime_calibration: true,
195            update_frequency: Duration::from_secs(300),
196            quality_threshold: 0.95,
197            enable_predictive: true,
198        }
199    }
200}
201
202impl Default for ErrorRateConfig {
203    fn default() -> Self {
204        Self {
205            consider_error_rates: true,
206            error_threshold: 0.01,
207            mitigation_strategy: ErrorMitigationStrategy::Composite,
208            prediction_model: ErrorPredictionModel::MachineLearning,
209        }
210    }
211}
212
213impl Default for ConnectivityConfig {
214    fn default() -> Self {
215        Self {
216            enforce_constraints: true,
217            swap_strategy: SwapInsertionStrategy::Lookahead,
218            routing_preference: RoutingPreference::QualityAware,
219            optimization_config: ConnectivityOptimizationConfig::default(),
220        }
221    }
222}
223
224impl Default for ConnectivityOptimizationConfig {
225    fn default() -> Self {
226        Self {
227            enable_parallel_routing: true,
228            optimization_level: OptimizationLevel::Moderate,
229            use_ml_routing: true,
230            precompute_tables: true,
231        }
232    }
233}
234
235impl Default for ResourceTrackingConfig {
236    fn default() -> Self {
237        Self {
238            track_cpu_usage: true,
239            track_memory_usage: true,
240            track_qpu_usage: true,
241            track_network_usage: true,
242            tracking_granularity: TrackingGranularity::Medium,
243            reporting_frequency: Duration::from_secs(60),
244        }
245    }
246}
247
248impl Default for PerformanceOptimizationConfig {
249    fn default() -> Self {
250        Self {
251            objectives: vec![OptimizationObjective::Balanced],
252            caching_config: CachingConfig::default(),
253            prefetching_config: PrefetchingConfig::default(),
254            batch_config: BatchProcessingConfig::default(),
255            adaptive_config: AdaptiveOptimizationConfig::default(),
256        }
257    }
258}
259
260impl Default for CachingConfig {
261    fn default() -> Self {
262        Self {
263            enable_result_caching: true,
264            enable_compilation_caching: true,
265            size_limits: CacheSizeLimits::default(),
266            eviction_policy: CacheEvictionPolicy::LRU,
267            warming_strategies: vec![CacheWarmingStrategy::PreloadCommon],
268        }
269    }
270}
271
272impl Default for CacheSizeLimits {
273    fn default() -> Self {
274        Self {
275            max_entries: 10000,
276            max_memory_mb: 1024.0,
277            max_disk_mb: 5120.0,
278            per_user_limits: None,
279        }
280    }
281}
282
283impl Default for PrefetchingConfig {
284    fn default() -> Self {
285        Self {
286            enabled: true,
287            strategy: PrefetchingStrategy::Adaptive,
288            prefetch_distance: 3,
289            confidence_threshold: 0.7,
290        }
291    }
292}
293
294impl Default for BatchProcessingConfig {
295    fn default() -> Self {
296        Self {
297            enabled: true,
298            size_limits: BatchSizeLimits::default(),
299            strategy: BatchingStrategy::Adaptive,
300            timeout: Duration::from_secs(30),
301        }
302    }
303}
304
305impl Default for BatchSizeLimits {
306    fn default() -> Self {
307        Self {
308            min_size: 1,
309            max_size: 100,
310            optimal_size: 10,
311            dynamic_sizing: true,
312        }
313    }
314}
315
316impl Default for AdaptiveOptimizationConfig {
317    fn default() -> Self {
318        Self {
319            enabled: true,
320            adaptation_frequency: Duration::from_secs(300),
321            monitoring_window: Duration::from_secs(900),
322            sensitivity: 0.1,
323            ml_config: AdaptiveMLConfig::default(),
324        }
325    }
326}
327
328impl Default for AdaptiveMLConfig {
329    fn default() -> Self {
330        Self {
331            enabled: true,
332            model_type: MLModelType::RandomForest,
333            training_frequency: Duration::from_secs(3600),
334            feature_config: FeatureEngineeringConfig::default(),
335        }
336    }
337}
338
339impl Default for FeatureEngineeringConfig {
340    fn default() -> Self {
341        Self {
342            circuit_features: vec![
343                CircuitFeature::QubitCount,
344                CircuitFeature::Depth,
345                CircuitFeature::GateCount,
346            ],
347            hardware_features: vec![
348                HardwareFeature::AvailableQubits,
349                HardwareFeature::ErrorRates,
350                HardwareFeature::QueueStatus,
351            ],
352            performance_features: vec![
353                PerformanceFeature::ExecutionTime,
354                PerformanceFeature::Throughput,
355                PerformanceFeature::ResourceEfficiency,
356            ],
357            normalization: FeatureNormalization::ZScore,
358        }
359    }
360}
361
362impl Default for LoadBalancingConfig {
363    fn default() -> Self {
364        Self {
365            algorithm: LoadBalancingAlgorithm::ResourceBased,
366            monitoring: LoadMonitoringConfig::default(),
367            rebalancing_triggers: RebalancingTriggers::default(),
368            migration_policies: MigrationPolicies::default(),
369        }
370    }
371}
372
373impl Default for LoadMonitoringConfig {
374    fn default() -> Self {
375        Self {
376            frequency: Duration::from_secs(30),
377            metrics: vec![
378                LoadMetric::CpuUtilization,
379                LoadMetric::MemoryUtilization,
380                LoadMetric::QpuUtilization,
381                LoadMetric::QueueLength,
382            ],
383            thresholds: LoadThresholds::default(),
384            retention_period: Duration::from_secs(3600 * 24),
385        }
386    }
387}
388
389impl Default for LoadThresholds {
390    fn default() -> Self {
391        Self {
392            cpu_threshold: 0.8,
393            memory_threshold: 0.85,
394            qpu_threshold: 0.9,
395            network_threshold: 0.8,
396            queue_threshold: 100,
397            response_time_threshold: Duration::from_secs(30),
398        }
399    }
400}
401
402impl Default for RebalancingTriggers {
403    fn default() -> Self {
404        Self {
405            cpu_imbalance_threshold: 0.3,
406            memory_imbalance_threshold: 0.3,
407            queue_imbalance_threshold: 0.4,
408            time_interval: Some(Duration::from_secs(300)),
409            event_triggers: vec![
410                RebalancingEvent::NodeFailure,
411                RebalancingEvent::LoadSpike,
412                RebalancingEvent::PerformanceDegradation,
413            ],
414        }
415    }
416}
417
418impl Default for MigrationPolicies {
419    fn default() -> Self {
420        Self {
421            cost_threshold: 0.1,
422            max_migrations_per_period: 10,
423            migration_period: Duration::from_secs(3600),
424            circuit_migration_strategy: CircuitMigrationStrategy::CheckpointRestart,
425            data_migration_strategy: DataMigrationStrategy::Copy,
426        }
427    }
428}
429
430impl Default for ResourceMonitoringConfig {
431    fn default() -> Self {
432        Self {
433            real_time_monitoring: true,
434            granularity: MonitoringGranularity::Circuit,
435            metrics_collection: MetricsCollectionConfig::default(),
436            alerting: AlertingConfig::default(),
437            reporting: ReportingConfig::default(),
438        }
439    }
440}
441
442impl Default for MetricsCollectionConfig {
443    fn default() -> Self {
444        Self {
445            frequency: Duration::from_secs(60),
446            metrics: vec![
447                MonitoringMetric::ResourceUtilization,
448                MonitoringMetric::Performance,
449                MonitoringMetric::Quality,
450            ],
451            retention_policy: RetentionPolicy::default(),
452            storage_config: StorageConfig::default(),
453        }
454    }
455}
456
457impl Default for RetentionPolicy {
458    fn default() -> Self {
459        Self {
460            raw_data_retention: Duration::from_secs(3600 * 24 * 7), // 1 week
461            aggregated_data_retention: Duration::from_secs(3600 * 24 * 30), // 1 month
462            archive_policy: ArchivePolicy::TimeBased(Duration::from_secs(3600 * 24 * 365)), // 1 year
463            compression: CompressionConfig::default(),
464        }
465    }
466}
467
468impl Default for StorageConfig {
469    fn default() -> Self {
470        Self {
471            backend: StorageBackend::LocalFilesystem,
472            location: "/tmp/quantrs_metrics".to_string(),
473            encryption: EncryptionConfig::default(),
474            replication: ReplicationConfig::default(),
475        }
476    }
477}
478
479impl Default for EncryptionConfig {
480    fn default() -> Self {
481        Self {
482            enabled: true,
483            algorithm: EncryptionAlgorithm::AES256,
484            key_management: KeyManagementConfig::default(),
485        }
486    }
487}
488
489impl Default for KeyManagementConfig {
490    fn default() -> Self {
491        Self {
492            rotation_frequency: Duration::from_secs(3600 * 24 * 30), // 1 month
493            key_derivation: KeyDerivationFunction::Argon2,
494            storage_backend: KeyStorageBackend::Local,
495        }
496    }
497}
498
499impl Default for ReplicationConfig {
500    fn default() -> Self {
501        Self {
502            replication_factor: 1,
503            strategy: ReplicationStrategy::Synchronous,
504            consistency_level: ConsistencyLevel::Strong,
505        }
506    }
507}
508
509impl Default for AlertingConfig {
510    fn default() -> Self {
511        Self {
512            enabled: true,
513            rules: vec![],
514            channels: vec![],
515            aggregation: AlertAggregationConfig::default(),
516        }
517    }
518}
519
520impl Default for AlertAggregationConfig {
521    fn default() -> Self {
522        Self {
523            enabled: true,
524            window: Duration::from_secs(300),
525            strategy: AlertAggregationStrategy::SeverityBased,
526            max_alerts_per_window: 10,
527        }
528    }
529}
530
531impl Default for ReportingConfig {
532    fn default() -> Self {
533        Self {
534            enabled: true,
535            report_types: vec![ReportType::Performance, ReportType::ResourceUtilization],
536            frequency: Duration::from_secs(3600 * 24), // Daily reports
537            format: ReportFormat::JSON,
538            distribution: ReportDistribution::default(),
539        }
540    }
541}
542
543impl Default for ReportDistribution {
544    fn default() -> Self {
545        Self {
546            email_recipients: vec![],
547            file_location: Some("/tmp/quantrs_reports".to_string()),
548            cloud_location: None,
549            api_endpoints: vec![],
550        }
551    }
552}