optirs-learned 0.3.1

OptiRS learned optimizers and meta-learning
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
use std::fmt::Debug;
// Hardware-aware evaluation for neural architecture search
//
// This module provides evaluation methods that consider hardware-specific
// constraints such as latency, memory usage, energy consumption, and throughput.

#[allow(dead_code)]

use scirs2_core::ndarray::{Array1, Array2};
use scirs2_core::numeric::Float;
use std::collections::HashMap;

use crate::error::{OptimError, Result};

/// Configuration for hardware-aware evaluation
#[derive(Debug, Clone)]
pub struct HardwareAwareConfig<T: Float + Debug + Send + Sync + 'static> {
    /// Target hardware platforms
    pub target_platforms: Vec<HardwarePlatform>,
    
    /// Hardware constraints
    pub constraints: HardwareConstraints<T>,
    
    /// Performance models
    pub performance_models: HashMap<String, PerformanceModel<T>>,
    
    /// Measurement configuration
    pub measurement_config: MeasurementConfig,
    
    /// Optimization objectives
    pub optimization_objectives: Vec<HardwareObjective<T>>,
    
    /// Energy budget constraints
    pub energy_budget: Option<EnergyBudget<T>>,
    
    /// Thermal constraints
    pub thermal_constraints: Option<ThermalConstraints<T>>,
}

/// Hardware platform specifications
#[derive(Debug, Clone)]
pub struct HardwarePlatform {
    /// Platform identifier
    pub id: String,
    
    /// Platform name
    pub name: String,
    
    /// Hardware type
    pub hardware_type: HardwareType,
    
    /// Compute capabilities
    pub compute_capabilities: ComputeCapabilities,
    
    /// Memory specifications
    pub memory_specs: MemorySpecs,
    
    /// Power specifications
    pub power_specs: PowerSpecs,
    
    /// Hardware-specific optimizations
    pub optimizations: Vec<HardwareOptimization>,
}

/// Types of hardware platforms
#[derive(Debug, Clone, Copy)]
pub enum HardwareType {
    /// CPU-based platforms
    CPU { cores: usize, frequency_ghz: f64 },
    
    /// GPU-based platforms
    GPU { cuda_cores: usize, memory_gb: f64 },
    
    /// TPU-based platforms
    TPU { version: String, cores: usize },
    
    /// Edge devices
    Edge { chip: String, power_watts: f64 },
    
    /// Mobile devices
    Mobile { soc: String, battery_mah: f64 },
    
    /// FPGA platforms
    FPGA { logic_elements: usize, memory_gb: f64 },
    
    /// Custom accelerators
    Custom { accelerator_type: String, specs: HashMap<String, f64> },
}

/// Compute capabilities of hardware
#[derive(Debug, Clone)]
pub struct ComputeCapabilities {
    /// Peak FLOPS (floating-point operations per second)
    pub peak_flops: u64,
    
    /// Memory bandwidth (GB/s)
    pub memory_bandwidth: f64,
    
    /// Cache sizes (bytes)
    pub cache_sizes: Vec<usize>,
    
    /// Instruction set support
    pub instruction_sets: Vec<String>,
    
    /// Parallel execution units
    pub execution_units: usize,
    
    /// Clock frequency (Hz)
    pub clock_frequency: f64,
}

/// Memory specifications
#[derive(Debug, Clone)]
pub struct MemorySpecs {
    /// Total memory size (bytes)
    pub total_memory: usize,
    
    /// Available memory (bytes)
    pub available_memory: usize,
    
    /// Memory types (DDR4, GDDR6, HBM, etc.)
    pub memory_types: Vec<String>,
    
    /// Memory hierarchy latencies (cycles)
    pub access_latencies: HashMap<String, u32>,
    
    /// Memory bandwidth per type (GB/s)
    pub bandwidth_per_type: HashMap<String, f64>,
}

/// Power specifications
#[derive(Debug, Clone)]
pub struct PowerSpecs {
    /// Maximum power consumption (watts)
    pub max_power: f64,
    
    /// Idle power consumption (watts)
    pub idle_power: f64,
    
    /// Power efficiency (FLOPS/watt)
    pub efficiency: f64,
    
    /// Thermal design power (watts)
    pub tdp: f64,
    
    /// Power states and transitions
    pub power_states: Vec<PowerState>,
}

/// Power states for hardware
#[derive(Debug, Clone)]
pub struct PowerState {
    /// State name
    pub name: String,
    
    /// Power consumption (watts)
    pub power_consumption: f64,
    
    /// Performance scaling factor
    pub performance_scale: f64,
    
    /// Transition latency (microseconds)
    pub transition_latency: f64,
}

/// Hardware-specific optimizations
#[derive(Debug, Clone)]
pub enum HardwareOptimization {
    /// Instruction-level optimization
    InstructionLevel(String),
    
    /// Memory access optimization
    MemoryAccess(String),
    
    /// Parallel processing optimization
    Parallelization(String),
    
    /// Cache optimization
    Cache(String),
    
    /// Compiler optimization
    Compiler(String),
}

/// Hardware constraints
#[derive(Debug, Clone)]
pub struct HardwareConstraints<T: Float + Debug + Send + Sync + 'static> {
    /// Maximum latency (milliseconds)
    pub max_latency: Option<T>,
    
    /// Maximum memory usage (bytes)
    pub max_memory: Option<usize>,
    
    /// Maximum power consumption (watts)
    pub max_power: Option<T>,
    
    /// Maximum energy per inference (joules)
    pub max_energy_per_inference: Option<T>,
    
    /// Minimum throughput (inferences/second)
    pub min_throughput: Option<T>,
    
    /// Maximum model size (bytes)
    pub max_model_size: Option<usize>,
    
    /// Maximum temperature (Celsius)
    pub max_temperature: Option<T>,
}

/// Performance models for hardware prediction
#[derive(Debug, Clone)]
pub struct PerformanceModel<T: Float + Debug + Send + Sync + 'static> {
    /// Model identifier
    pub id: String,
    
    /// Model type
    pub model_type: ModelType,
    
    /// Model parameters
    pub parameters: Array1<T>,
    
    /// Feature extractors
    pub feature_extractors: Vec<FeatureExtractor>,
    
    /// Model accuracy metrics
    pub accuracy_metrics: ModelAccuracyMetrics<T>,
    
    /// Supported operations
    pub supported_operations: Vec<String>,
}

/// Types of performance models
#[derive(Debug, Clone)]
pub enum ModelType {
    /// Linear regression model
    LinearRegression,
    
    /// Polynomial regression model
    PolynomialRegression { degree: usize },
    
    /// Neural network model
    NeuralNetwork { layers: Vec<usize> },
    
    /// Lookup table model
    LookupTable,
    
    /// Analytical model
    Analytical,
    
    /// Profiling-based model
    ProfilingBased,
}

/// Feature extractors for performance models
#[derive(Debug, Clone)]
pub struct FeatureExtractor {
    /// Feature name
    pub name: String,
    
    /// Extraction method
    pub method: ExtractionMethod,
    
    /// Feature importance weight
    pub importance: f64,
}

/// Methods for feature extraction
#[derive(Debug, Clone)]
pub enum ExtractionMethod {
    /// Architecture-based features
    Architecture(ArchitectureFeatures),
    
    /// Operation-based features
    Operation(OperationFeatures),
    
    /// Graph-based features
    Graph(GraphFeatures),
    
    /// Statistical features
    Statistical(StatisticalFeatures),
}

/// Architecture-based features
#[derive(Debug, Clone)]
pub struct ArchitectureFeatures {
    /// Number of layers
    pub num_layers: bool,
    
    /// Layer types distribution
    pub layer_types: bool,
    
    /// Parameter count
    pub parameter_count: bool,
    
    /// Model depth
    pub depth: bool,
    
    /// Skip connections
    pub skip_connections: bool,
}

/// Operation-based features
#[derive(Debug, Clone)]
pub struct OperationFeatures {
    /// FLOPS count
    pub flops: bool,
    
    /// Memory access patterns
    pub memory_access: bool,
    
    /// Computation intensity
    pub compute_intensity: bool,
    
    /// Data dependencies
    pub dependencies: bool,
}

/// Graph-based features
#[derive(Debug, Clone)]
pub struct GraphFeatures {
    /// Graph connectivity
    pub connectivity: bool,
    
    /// Path lengths
    pub path_lengths: bool,
    
    /// Branching factor
    pub branching_factor: bool,
    
    /// Graph density
    pub density: bool,
}

/// Statistical features
#[derive(Debug, Clone)]
pub struct StatisticalFeatures {
    /// Mean activation sizes
    pub activation_stats: bool,
    
    /// Weight distributions
    pub weight_stats: bool,
    
    /// Gradient statistics
    pub gradient_stats: bool,
}

/// Model accuracy metrics
#[derive(Debug, Clone)]
pub struct ModelAccuracyMetrics<T: Float + Debug + Send + Sync + 'static> {
    /// Mean absolute error
    pub mae: T,
    
    /// Root mean square error
    pub rmse: T,
    
    /// R-squared value
    pub r_squared: T,
    
    /// Mean absolute percentage error
    pub mape: T,
    
    /// Prediction interval coverage
    pub coverage: T,
}

/// Measurement configuration
#[derive(Debug, Clone)]
pub struct MeasurementConfig {
    /// Number of warmup runs
    pub warmup_runs: usize,
    
    /// Number of measurement runs
    pub measurement_runs: usize,
    
    /// Measurement precision level
    pub precision_level: PrecisionLevel,
    
    /// Batch sizes for measurement
    pub batch_sizes: Vec<usize>,
    
    /// Input shapes for measurement
    pub input_shapes: Vec<Vec<usize>>,
    
    /// Measurement timeout (seconds)
    pub timeout_seconds: u32,
}

/// Precision levels for measurement
#[derive(Debug, Clone, Copy)]
pub enum PrecisionLevel {
    /// Quick approximate measurement
    Quick,
    
    /// Standard measurement
    Standard,
    
    /// High precision measurement
    HighPrecision,
    
    /// Exhaustive measurement
    Exhaustive,
}

/// Hardware optimization objectives
#[derive(Debug, Clone)]
pub struct HardwareObjective<T: Float + Debug + Send + Sync + 'static> {
    /// Objective identifier
    pub id: String,
    
    /// Objective type
    pub objective_type: HardwareObjectiveType,
    
    /// Target value
    pub target_value: Option<T>,
    
    /// Weight in multi-objective optimization
    pub weight: T,
    
    /// Constraint threshold
    pub constraint_threshold: Option<T>,
}

/// Types of hardware objectives
#[derive(Debug, Clone, Copy)]
pub enum HardwareObjectiveType {
    /// Minimize inference latency
    MinimizeLatency,
    
    /// Minimize memory usage
    MinimizeMemory,
    
    /// Minimize power consumption
    MinimizePower,
    
    /// Minimize energy per inference
    MinimizeEnergy,
    
    /// Maximize throughput
    MaximizeThroughput,
    
    /// Maximize efficiency (performance/power)
    MaximizeEfficiency,
    
    /// Minimize temperature
    MinimizeTemperature,
    
    /// Maximize utilization
    MaximizeUtilization,
}

/// Energy budget constraints
#[derive(Debug, Clone)]
pub struct EnergyBudget<T: Float + Debug + Send + Sync + 'static> {
    /// Total energy budget (joules)
    pub total_budget: T,
    
    /// Energy per inference limit (joules)
    pub per_inference_limit: T,
    
    /// Battery capacity (watt-hours)
    pub battery_capacity: Option<T>,
    
    /// Energy efficiency target (inferences/joule)
    pub efficiency_target: T,
}

/// Thermal constraints
#[derive(Debug, Clone)]
pub struct ThermalConstraints<T: Float + Debug + Send + Sync + 'static> {
    /// Maximum operating temperature (Celsius)
    pub max_temperature: T,
    
    /// Thermal throttling threshold (Celsius)
    pub throttling_threshold: T,
    
    /// Cooling capacity (watts)
    pub cooling_capacity: T,
    
    /// Thermal time constants (seconds)
    pub thermal_time_constants: Vec<T>,
}

/// Hardware-aware evaluator
#[derive(Debug)]
pub struct HardwareAwareEvaluator<T: Float + Debug + Send + Sync + 'static> {
    /// Configuration
    config: HardwareAwareConfig<T>,
    
    /// Performance measurements cache
    measurement_cache: HashMap<String, PerformanceMeasurement<T>>,
    
    /// Hardware profiling data
    profiling_data: HashMap<String, ProfilingData<T>>,
    
    /// Evaluation history
    evaluation_history: Vec<HardwareEvaluation<T>>,
    
    /// Current platform
    current_platform: Option<HardwarePlatform>,
}

/// Performance measurement result
#[derive(Debug, Clone)]
pub struct PerformanceMeasurement<T: Float + Debug + Send + Sync + 'static> {
    /// Architecture identifier
    pub architecture_id: String,
    
    /// Target platform
    pub platform_id: String,
    
    /// Latency measurements (milliseconds)
    pub latency_ms: Vec<T>,
    
    /// Memory usage (bytes)
    pub memory_usage: usize,
    
    /// Power consumption (watts)
    pub power_consumption: T,
    
    /// Energy per inference (joules)
    pub energy_per_inference: T,
    
    /// Throughput (inferences/second)
    pub throughput: T,
    
    /// Temperature measurements (Celsius)
    pub temperatures: Vec<T>,
    
    /// Utilization percentages
    pub utilizations: HashMap<String, T>,
    
    /// Measurement timestamp
    pub timestamp: u64,
    
    /// Measurement quality metrics
    pub quality_metrics: MeasurementQuality<T>,
}

/// Profiling data for hardware
#[derive(Debug, Clone)]
pub struct ProfilingData<T: Float + Debug + Send + Sync + 'static> {
    /// Operation-level timings
    pub operation_timings: HashMap<String, T>,
    
    /// Memory access patterns
    pub memory_patterns: MemoryAccessPattern<T>,
    
    /// Cache hit rates
    pub cache_stats: HashMap<String, T>,
    
    /// Power breakdown by component
    pub power_breakdown: HashMap<String, T>,
    
    /// Thermal profile
    pub thermal_profile: ThermalProfile<T>,
}

/// Memory access patterns
#[derive(Debug, Clone)]
pub struct MemoryAccessPattern<T: Float + Debug + Send + Sync + 'static> {
    /// Sequential access ratio
    pub sequential_ratio: T,
    
    /// Cache locality score
    pub locality_score: T,
    
    /// Memory bandwidth utilization
    pub bandwidth_utilization: T,
    
    /// Access stride patterns
    pub stride_patterns: Vec<usize>,
}

/// Thermal profile
#[derive(Debug, Clone)]
pub struct ThermalProfile<T: Float + Debug + Send + Sync + 'static> {
    /// Temperature over time
    pub temperature_timeline: Vec<(T, T)>, // (time, temperature)
    
    /// Hot spots identification
    pub hot_spots: Vec<String>,
    
    /// Thermal gradients
    pub thermal_gradients: HashMap<String, T>,
    
    /// Cooling effectiveness
    pub cooling_effectiveness: T,
}

/// Measurement quality metrics
#[derive(Debug, Clone)]
pub struct MeasurementQuality<T: Float + Debug + Send + Sync + 'static> {
    /// Measurement variance
    pub variance: T,
    
    /// Confidence interval
    pub confidence_interval: (T, T),
    
    /// Number of outliers removed
    pub outliers_removed: usize,
    
    /// Signal-to-noise ratio
    pub signal_noise_ratio: T,
}

/// Hardware evaluation result
#[derive(Debug, Clone)]
pub struct HardwareEvaluation<T: Float + Debug + Send + Sync + 'static> {
    /// Architecture identifier
    pub architecture_id: String,
    
    /// Evaluation results per platform
    pub platform_results: HashMap<String, PlatformEvaluationResult<T>>,
    
    /// Overall hardware score
    pub overall_score: T,
    
    /// Constraint violations
    pub constraint_violations: Vec<ConstraintViolation<T>>,
    
    /// Optimization recommendations
    pub recommendations: Vec<OptimizationRecommendation>,
    
    /// Evaluation timestamp
    pub timestamp: u64,
}

/// Evaluation result for a specific platform
#[derive(Debug, Clone)]
pub struct PlatformEvaluationResult<T: Float + Debug + Send + Sync + 'static> {
    /// Platform identifier
    pub platform_id: String,
    
    /// Performance measurements
    pub measurements: PerformanceMeasurement<T>,
    
    /// Predicted vs. actual performance
    pub prediction_accuracy: T,
    
    /// Resource utilization efficiency
    pub utilization_efficiency: T,
    
    /// Hardware-specific score
    pub platform_score: T,
    
    /// Bottleneck analysis
    pub bottlenecks: Vec<Bottleneck>,
}

/// Constraint violation
#[derive(Debug, Clone)]
pub struct ConstraintViolation<T: Float + Debug + Send + Sync + 'static> {
    /// Constraint type
    pub constraint_type: String,
    
    /// Expected value
    pub expected: T,
    
    /// Actual value
    pub actual: T,
    
    /// Violation severity
    pub severity: ViolationSeverity,
    
    /// Suggested fixes
    pub suggested_fixes: Vec<String>,
}

/// Severity of constraint violations
#[derive(Debug, Clone, Copy)]
pub enum ViolationSeverity {
    /// Warning level violation
    Warning,
    
    /// Error level violation
    Error,
    
    /// Critical violation
    Critical,
}

/// Optimization recommendations
#[derive(Debug, Clone)]
pub struct OptimizationRecommendation {
    /// Recommendation type
    pub recommendation_type: RecommendationType,
    
    /// Description
    pub description: String,
    
    /// Expected improvement
    pub expected_improvement: HashMap<String, f64>,
    
    /// Implementation difficulty
    pub difficulty: DifficultyLevel,
    
    /// Priority level
    pub priority: u8,
}

/// Types of optimization recommendations
#[derive(Debug, Clone)]
pub enum RecommendationType {
    /// Architecture modification
    ArchitectureModification,
    
    /// Operation fusion
    OperationFusion,
    
    /// Memory optimization
    MemoryOptimization,
    
    /// Quantization
    Quantization,
    
    /// Pruning
    Pruning,
    
    /// Hardware-specific optimization
    HardwareSpecific(String),
}

/// Implementation difficulty levels
#[derive(Debug, Clone, Copy)]
pub enum DifficultyLevel {
    Easy,
    Medium,
    Hard,
    Expert,
}

/// System bottlenecks
#[derive(Debug, Clone)]
pub struct Bottleneck {
    /// Bottleneck type
    pub bottleneck_type: BottleneckType,
    
    /// Severity (0.0 to 1.0)
    pub severity: f64,
    
    /// Description
    pub description: String,
    
    /// Affected operations
    pub affected_operations: Vec<String>,
}

/// Types of system bottlenecks
#[derive(Debug, Clone)]
pub enum BottleneckType {
    /// Compute-bound bottleneck
    Compute,
    
    /// Memory bandwidth bottleneck
    MemoryBandwidth,
    
    /// Memory capacity bottleneck
    MemoryCapacity,
    
    /// I/O bottleneck
    IO,
    
    /// Thermal throttling
    Thermal,
    
    /// Power limit
    Power,
    
    /// Cache miss bottleneck
    Cache,
}

impl<T: Float + Debug + Default + Clone + Send + Sync + 'static> HardwareAwareEvaluator<T> {
    /// Create new hardware-aware evaluator
    pub fn new(config: HardwareAwareConfig<T>) -> Self {
        Self {
            config,
            measurement_cache: HashMap::new(),
            profiling_data: HashMap::new(),
            evaluation_history: Vec::new(),
            current_platform: None,
        }
    }
    
    /// Set target platform for evaluation
    pub fn set_target_platform(&mut self, platform: HardwarePlatform) {
        self.current_platform = Some(platform);
    }
    
    /// Evaluate architecture on hardware platforms
    pub fn evaluate(&mut self, architecture_id: &str, architecture_data: &HashMap<String, f64>) -> Result<HardwareEvaluation<T>> {
        let mut platform_results = HashMap::new();
        let mut constraint_violations = Vec::new();
        let mut overall_score = T::zero();
        
        // Evaluate on each target platform
        for platform in &self.config.target_platforms {
            let result = self.evaluate_on_platform(architecture_id, architecture_data, platform)?;
            
            // Check constraints for this platform
            let violations = self.check_constraints(&result.measurements, platform)?;
            constraint_violations.extend(violations);
            
            // Update overall score
            overall_score = overall_score + result.platform_score;
            
            platform_results.insert(platform.id.clone(), result);
        }
        
        // Normalize overall score
        if !self.config.target_platforms.is_empty() {
            overall_score = overall_score / T::from(self.config.target_platforms.len() as f64).expect("unwrap failed");
        }
        
        // Generate optimization recommendations
        let recommendations = self.generate_recommendations(architecture_id, &platform_results)?;
        
        let evaluation = HardwareEvaluation {
            architecture_id: architecture_id.to_string(),
            platform_results,
            overall_score,
            constraint_violations,
            recommendations,
            timestamp: std::time::SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .unwrap_or_default()
                .as_secs(),
        };
        
        self.evaluation_history.push(evaluation.clone());
        
        Ok(evaluation)
    }
    
    /// Evaluate architecture on a specific platform
    fn evaluate_on_platform(&mut self, architecture_id: &str, 
                           architecture_data: &HashMap<String, f64>,
                           platform: &HardwarePlatform) -> Result<PlatformEvaluationResult<T>> {
        // Check cache for existing measurements
        let cache_key = format!("{}_{}", architecture_id, platform.id);
        if let Some(cached_measurement) = self.measurement_cache.get(&cache_key) {
            return Ok(PlatformEvaluationResult {
                platform_id: platform.id.clone(),
                measurements: cached_measurement.clone(),
                prediction_accuracy: scirs2_core::numeric::NumCast::from(0.9).unwrap_or_else(|| T::zero()), // Cached, assume good accuracy
                utilization_efficiency: self.compute_utilization_efficiency(cached_measurement, platform)?,
                platform_score: self.compute_platform_score(cached_measurement, platform)?,
                bottlenecks: self.identify_bottlenecks(cached_measurement, platform)?,
            });
        }
        
        // Perform actual measurement
        let measurement = self.measure_performance(architecture_id, architecture_data, platform)?;
        
        // Cache the measurement
        self.measurement_cache.insert(cache_key, measurement.clone());
        
        // Compute platform-specific metrics
        let prediction_accuracy = self.validate_prediction(architecture_data, &measurement, platform)?;
        let utilization_efficiency = self.compute_utilization_efficiency(&measurement, platform)?;
        let platform_score = self.compute_platform_score(&measurement, platform)?;
        let bottlenecks = self.identify_bottlenecks(&measurement, platform)?;
        
        Ok(PlatformEvaluationResult {
            platform_id: platform.id.clone(),
            measurements: measurement,
            prediction_accuracy,
            utilization_efficiency,
            platform_score,
            bottlenecks,
        })
    }
    
    /// Measure performance on hardware platform
    fn measure_performance(&self, architecture_id: &str,
                          architecture_data: &HashMap<String, f64>,
                          platform: &HardwarePlatform) -> Result<PerformanceMeasurement<T>> {
        // Simulate performance measurement
        // In practice, this would run actual benchmarks on the hardware
        
        let base_latency = architecture_data.get("estimated_latency").unwrap_or(&50.0);
        let base_memory = architecture_data.get("estimated_memory").unwrap_or(&1024.0) as usize;
        let base_power = architecture_data.get("estimated_power").unwrap_or(&100.0);
        
        // Apply platform-specific scaling factors
        let platform_factor = match platform.hardware_type {
            HardwareType::GPU { .. } => 0.3, // GPUs are typically faster
            HardwareType::TPU { .. } => 0.2, // TPUs are even faster for ML workloads
            HardwareType::Edge { .. } => 2.0, // Edge devices are slower
            HardwareType::Mobile { .. } => 3.0, // Mobile devices are much slower
            _ => 1.0,
        };
        
        // Generate latency measurements with some variance
        let mut latency_measurements = Vec::new();
        for _ in 0..self.config.measurement_config.measurement_runs {
            let variance = 1.0 + (scirs2_core::random::random::<f64>() - 0.5) * 0.2; // ±10% variance
            let latency = scirs2_core::numeric::NumCast::from(base_latency * platform_factor * variance).unwrap_or_else(|| T::zero());
            latency_measurements.push(latency);
        }
        
        // Compute derived metrics
        let avg_latency = latency_measurements.iter().cloned().fold(T::zero(), |acc, x| acc + x) /
                         T::from(latency_measurements.len() as f64).expect("unwrap failed");
        let throughput = scirs2_core::numeric::NumCast::from(1000.0).unwrap_or_else(|| T::zero()) / avg_latency; // inferences per second
        let power_consumption = scirs2_core::numeric::NumCast::from(base_power * platform_factor).unwrap_or_else(|| T::zero());
        let energy_per_inference = power_consumption * avg_latency / scirs2_core::numeric::NumCast::from(1000.0).unwrap_or_else(|| T::zero());
        
        // Generate temperature measurements
        let base_temp = 40.0 + base_power * platform_factor * 0.3;
        let temperatures = vec![
            scirs2_core::numeric::NumCast::from(base_temp).unwrap_or_else(|| T::zero()),
            scirs2_core::numeric::NumCast::from(base_temp + 5.0).unwrap_or_else(|| T::zero()),
            scirs2_core::numeric::NumCast::from(base_temp + 2.0).unwrap_or_else(|| T::zero()),
        ];
        
        // Generate utilization data
        let mut utilizations = HashMap::new();
        utilizations.insert("compute".to_string(), scirs2_core::numeric::NumCast::from(0.75).unwrap_or_else(|| T::zero()));
        utilizations.insert("memory".to_string(), scirs2_core::numeric::NumCast::from(0.60).unwrap_or_else(|| T::zero()));
        utilizations.insert("bandwidth".to_string(), scirs2_core::numeric::NumCast::from(0.45).unwrap_or_else(|| T::zero()));
        
        // Compute quality metrics
        let variance = latency_measurements.iter()
            .map(|&x| (x - avg_latency) * (x - avg_latency))
            .fold(T::zero(), |acc, x| acc + x) / T::from(latency_measurements.len() as f64).expect("unwrap failed");
        
        let quality_metrics = MeasurementQuality {
            variance,
            confidence_interval: (avg_latency * scirs2_core::numeric::NumCast::from(0.95).unwrap_or_else(|| T::zero()), avg_latency * scirs2_core::numeric::NumCast::from(1.05).unwrap_or_else(|| T::zero())),
            outliers_removed: 0,
            signal_noise_ratio: scirs2_core::numeric::NumCast::from(20.0).unwrap_or_else(|| T::zero()),
        };
        
        Ok(PerformanceMeasurement {
            architecture_id: architecture_id.to_string(),
            platform_id: platform.id.clone(),
            latency_ms: latency_measurements,
            memory_usage: (base_memory as f64 * platform_factor) as usize,
            power_consumption,
            energy_per_inference,
            throughput,
            temperatures,
            utilizations,
            timestamp: std::time::SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .unwrap_or_default()
                .as_secs(),
            quality_metrics,
        })
    }
    
    /// Check hardware constraints
    fn check_constraints(&self, measurement: &PerformanceMeasurement<T>, 
                        platform: &HardwarePlatform) -> Result<Vec<ConstraintViolation<T>>> {
        let mut violations = Vec::new();
        let constraints = &self.config.constraints;
        
        // Check latency constraint
        if let Some(max_latency) = constraints.max_latency {
            let avg_latency = measurement.latency_ms.iter().cloned().fold(T::zero(), |acc, x| acc + x) /
                             T::from(measurement.latency_ms.len() as f64).expect("unwrap failed");
            if avg_latency > max_latency {
                violations.push(ConstraintViolation {
                    constraint_type: "max_latency".to_string(),
                    expected: max_latency,
                    actual: avg_latency,
                    severity: if avg_latency > max_latency * scirs2_core::numeric::NumCast::from(2.0).unwrap_or_else(|| T::zero()) {
                        ViolationSeverity::Critical
                    } else {
                        ViolationSeverity::Error
                    },
                    suggested_fixes: vec![
                        "Reduce model complexity".to_string(),
                        "Use model quantization".to_string(),
                        "Optimize operations".to_string(),
                    ],
                });
            }
        }
        
        // Check memory constraint
        if let Some(max_memory) = constraints.max_memory {
            if measurement.memory_usage > max_memory {
                violations.push(ConstraintViolation {
                    constraint_type: "max_memory".to_string(),
                    expected: scirs2_core::numeric::NumCast::from(max_memory as f64).unwrap_or_else(|| T::zero()),
                    actual: scirs2_core::numeric::NumCast::from(measurement.memory_usage as f64).unwrap_or_else(|| T::zero()),
                    severity: ViolationSeverity::Error,
                    suggested_fixes: vec![
                        "Reduce batch size".to_string(),
                        "Use gradient checkpointing".to_string(),
                        "Apply model pruning".to_string(),
                    ],
                });
            }
        }
        
        // Check power constraint
        if let Some(max_power) = constraints.max_power {
            if measurement.power_consumption > max_power {
                violations.push(ConstraintViolation {
                    constraint_type: "max_power".to_string(),
                    expected: max_power,
                    actual: measurement.power_consumption,
                    severity: ViolationSeverity::Warning,
                    suggested_fixes: vec![
                        "Reduce clock frequency".to_string(),
                        "Use power-efficient operations".to_string(),
                        "Enable power saving modes".to_string(),
                    ],
                });
            }
        }
        
        // Check throughput constraint
        if let Some(min_throughput) = constraints.min_throughput {
            if measurement.throughput < min_throughput {
                violations.push(ConstraintViolation {
                    constraint_type: "min_throughput".to_string(),
                    expected: min_throughput,
                    actual: measurement.throughput,
                    severity: ViolationSeverity::Error,
                    suggested_fixes: vec![
                        "Increase parallelism".to_string(),
                        "Optimize memory access".to_string(),
                        "Use batch processing".to_string(),
                    ],
                });
            }
        }
        
        Ok(violations)
    }
    
    /// Compute utilization efficiency
    fn compute_utilization_efficiency(&self, measurement: &PerformanceMeasurement<T>,
                                     platform: &HardwarePlatform) -> Result<T> {
        let compute_util = measurement.utilizations.get("compute").unwrap_or(&T::zero());
        let memory_util = measurement.utilizations.get("memory").unwrap_or(&T::zero());
        let bandwidth_util = measurement.utilizations.get("bandwidth").unwrap_or(&T::zero());
        
        // Weighted average of utilizations
        let efficiency = (*compute_util * scirs2_core::numeric::NumCast::from(0.5).unwrap_or_else(|| T::zero()) + 
                         *memory_util * scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()) + 
                         *bandwidth_util * scirs2_core::numeric::NumCast::from(0.2).unwrap_or_else(|| T::zero()));
        
        Ok(efficiency)
    }
    
    /// Compute platform-specific score
    fn compute_platform_score(&self, measurement: &PerformanceMeasurement<T>,
                             platform: &HardwarePlatform) -> Result<T> {
        // Simple scoring based on multiple factors
        let latency_score = scirs2_core::numeric::NumCast::from(100.0).unwrap_or_else(|| T::zero()) / measurement.latency_ms.iter().cloned().fold(T::zero(), |acc, x| acc + x);
        let throughput_score = measurement.throughput / scirs2_core::numeric::NumCast::from(100.0).unwrap_or_else(|| T::zero());
        let efficiency_score = self.compute_utilization_efficiency(measurement, platform)?;
        
        let overall_score = (latency_score + throughput_score + efficiency_score) / scirs2_core::numeric::NumCast::from(3.0).unwrap_or_else(|| T::zero());
        Ok(overall_score.min(scirs2_core::numeric::NumCast::from(100.0).unwrap_or_else(|| T::zero())))
    }
    
    /// Identify system bottlenecks
    fn identify_bottlenecks(&self, measurement: &PerformanceMeasurement<T>,
                           platform: &HardwarePlatform) -> Result<Vec<Bottleneck>> {
        let mut bottlenecks = Vec::new();
        
        // Check compute utilization
        if let Some(&compute_util) = measurement.utilizations.get("compute") {
            if compute_util < scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()) {
                bottlenecks.push(Bottleneck {
                    bottleneck_type: BottleneckType::Compute,
                    severity: (scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()) - compute_util).to_f64().unwrap_or(0.0) * 3.33,
                    description: "Low compute utilization detected".to_string(),
                    affected_operations: vec!["conv2d".to_string(), "matmul".to_string()],
                });
            }
        }
        
        // Check memory utilization
        if let Some(&memory_util) = measurement.utilizations.get("memory") {
            if memory_util > scirs2_core::numeric::NumCast::from(0.9).unwrap_or_else(|| T::zero()) {
                bottlenecks.push(Bottleneck {
                    bottleneck_type: BottleneckType::MemoryCapacity,
                    severity: (memory_util - scirs2_core::numeric::NumCast::from(0.9).unwrap_or_else(|| T::zero())).to_f64().unwrap_or(0.0) * 10.0,
                    description: "High memory utilization detected".to_string(),
                    affected_operations: vec!["large_tensors".to_string(), "activations".to_string()],
                });
            }
        }
        
        // Check thermal issues
        let max_temp = measurement.temperatures.iter().cloned().fold(T::zero(), T::max);
        if max_temp > scirs2_core::numeric::NumCast::from(80.0).unwrap_or_else(|| T::zero()) {
            bottlenecks.push(Bottleneck {
                bottleneck_type: BottleneckType::Thermal,
                severity: (max_temp - scirs2_core::numeric::NumCast::from(80.0).unwrap_or_else(|| T::zero())).to_f64().unwrap_or(0.0) / 20.0,
                description: "High temperature detected".to_string(),
                affected_operations: vec!["all_operations".to_string()],
            });
        }
        
        Ok(bottlenecks)
    }
    
    /// Validate prediction accuracy
    fn validate_prediction(&self, architecture_data: &HashMap<String, f64>,
                          measurement: &PerformanceMeasurement<T>,
                          platform: &HardwarePlatform) -> Result<T> {
        // Compare predicted vs actual performance
        let predicted_latency = architecture_data.get("estimated_latency").unwrap_or(&50.0);
        let actual_latency = measurement.latency_ms.iter().cloned().fold(T::zero(), |acc, x| acc + x) /
                           T::from(measurement.latency_ms.len() as f64).expect("unwrap failed");
        
        let error = (scirs2_core::numeric::NumCast::from(*predicted_latency).unwrap_or_else(|| T::zero()) - actual_latency).abs() / actual_latency;
        let accuracy = T::one() - error.min(T::one());
        
        Ok(accuracy.max(T::zero()))
    }
    
    /// Generate optimization recommendations
    fn generate_recommendations(&self, architecture_id: &str,
                               platform_results: &HashMap<String, PlatformEvaluationResult<T>>) -> Result<Vec<OptimizationRecommendation>> {
        let mut recommendations = Vec::new();
        
        // Analyze common bottlenecks across platforms
        for (platform_id, result) in platform_results {
            for bottleneck in &result.bottlenecks {
                match bottleneck.bottleneck_type {
                    BottleneckType::MemoryBandwidth => {
                        recommendations.push(OptimizationRecommendation {
                            recommendation_type: RecommendationType::MemoryOptimization,
                            description: "Optimize memory access patterns to improve bandwidth utilization".to_string(),
                            expected_improvement: {
                                let mut improvements = HashMap::new();
                                improvements.insert("latency".to_string(), 0.15);
                                improvements.insert("throughput".to_string(), 0.20);
                                improvements
                            },
                            difficulty: DifficultyLevel::Medium,
                            priority: 8,
                        });
                    }
                    BottleneckType::Compute => {
                        recommendations.push(OptimizationRecommendation {
                            recommendation_type: RecommendationType::OperationFusion,
                            description: "Fuse operations to improve compute utilization".to_string(),
                            expected_improvement: {
                                let mut improvements = HashMap::new();
                                improvements.insert("latency".to_string(), 0.25);
                                improvements.insert("utilization".to_string(), 0.30);
                                improvements
                            },
                            difficulty: DifficultyLevel::Hard,
                            priority: 9,
                        });
                    }
                    BottleneckType::MemoryCapacity => {
                        recommendations.push(OptimizationRecommendation {
                            recommendation_type: RecommendationType::Quantization,
                            description: "Apply quantization to reduce memory footprint".to_string(),
                            expected_improvement: {
                                let mut improvements = HashMap::new();
                                improvements.insert("memory".to_string(), 0.50);
                                improvements.insert("latency".to_string(), 0.10);
                                improvements
                            },
                            difficulty: DifficultyLevel::Easy,
                            priority: 7,
                        });
                    }
                    _ => {}
                }
            }
        }
        
        Ok(recommendations)
    }
    
    /// Get evaluation history
    pub fn get_evaluation_history(&self) -> &[HardwareEvaluation<T>] {
        &self.evaluation_history
    }
    
    /// Get cached measurements
    pub fn get_cached_measurements(&self) -> &HashMap<String, PerformanceMeasurement<T>> {
        &self.measurement_cache
    }
    
    /// Get profiling data
    pub fn get_profiling_data(&self) -> &HashMap<String, ProfilingData<T>> {
        &self.profiling_data
    }
}

impl Default for MeasurementConfig {
    fn default() -> Self {
        Self {
            warmup_runs: 5,
            measurement_runs: 20,
            precision_level: PrecisionLevel::Standard,
            batch_sizes: vec![1, 4, 8, 16, 32],
            input_shapes: vec![vec![224, 224, 3], vec![512, 512, 3]],
            timeout_seconds: 300,
        }
    }
}

impl<T: Float + Debug + Default + Clone + Send + Sync + 'static> Default for HardwareConstraints<T> {
    fn default() -> Self {
        Self {
            max_latency: Some(scirs2_core::numeric::NumCast::from(100.0).unwrap_or_else(|| T::zero())), // 100ms
            max_memory: Some(2_000_000_000), // 2GB
            max_power: Some(scirs2_core::numeric::NumCast::from(150.0).unwrap_or_else(|| T::zero())), // 150W
            max_energy_per_inference: Some(scirs2_core::numeric::NumCast::from(1.0).unwrap_or_else(|| T::zero())), // 1J
            min_throughput: Some(scirs2_core::numeric::NumCast::from(10.0).unwrap_or_else(|| T::zero())), // 10 inferences/sec
            max_model_size: Some(100_000_000), // 100MB
            max_temperature: Some(scirs2_core::numeric::NumCast::from(85.0).unwrap_or_else(|| T::zero())), // 85°C
        }
    }
}

impl<T: Float + Debug + Default + Clone + Send + Sync + 'static> Default for HardwareAwareConfig<T> {
    fn default() -> Self {
        Self {
            target_platforms: vec![
                HardwarePlatform {
                    id: "gpu_v100".to_string(),
                    name: "NVIDIA V100".to_string(),
                    hardware_type: HardwareType::GPU { cuda_cores: 5120, memory_gb: 32.0 },
                    compute_capabilities: ComputeCapabilities {
                        peak_flops: 15_000_000_000_000, // 15 TFLOPS
                        memory_bandwidth: 900.0, // GB/s
                        cache_sizes: vec![128*1024, 1024*1024], // L1, L2 cache
                        instruction_sets: vec!["CUDA".to_string(), "Tensor".to_string()],
                        execution_units: 80,
                        clock_frequency: 1530_000_000.0, // Hz
                    },
                    memory_specs: MemorySpecs {
                        total_memory: 34_000_000_000, // 34GB HBM2
                        available_memory: 32_000_000_000, // 32GB available
                        memory_types: vec!["HBM2".to_string()],
                        access_latencies: {
                            let mut latencies = HashMap::new();
                            latencies.insert("HBM2".to_string(), 350);
                            latencies
                        },
                        bandwidth_per_type: {
                            let mut bandwidths = HashMap::new();
                            bandwidths.insert("HBM2".to_string(), 900.0);
                            bandwidths
                        },
                    },
                    power_specs: PowerSpecs {
                        max_power: 300.0,
                        idle_power: 50.0,
                        efficiency: 50_000_000.0, // FLOPS/watt
                        tdp: 300.0,
                        power_states: vec![
                            PowerState {
                                name: "High Performance".to_string(),
                                power_consumption: 300.0,
                                performance_scale: 1.0,
                                transition_latency: 0.0,
                            },
                            PowerState {
                                name: "Balanced".to_string(),
                                power_consumption: 200.0,
                                performance_scale: 0.8,
                                transition_latency: 1000.0,
                            },
                        ],
                    },
                    optimizations: vec![
                        HardwareOptimization::Compiler("TensorRT".to_string()),
                        HardwareOptimization::MemoryAccess("Unified Memory".to_string()),
                    ],
                }
            ],
            constraints: HardwareConstraints::default(),
            performance_models: HashMap::new(),
            measurement_config: MeasurementConfig::default(),
            optimization_objectives: vec![
                HardwareObjective {
                    id: "latency".to_string(),
                    objective_type: HardwareObjectiveType::MinimizeLatency,
                    target_value: Some(scirs2_core::numeric::NumCast::from(50.0).unwrap_or_else(|| T::zero())),
                    weight: scirs2_core::numeric::NumCast::from(0.4).unwrap_or_else(|| T::zero()),
                    constraint_threshold: Some(scirs2_core::numeric::NumCast::from(100.0).unwrap_or_else(|| T::zero())),
                },
                HardwareObjective {
                    id: "throughput".to_string(),
                    objective_type: HardwareObjectiveType::MaximizeThroughput,
                    target_value: Some(scirs2_core::numeric::NumCast::from(100.0).unwrap_or_else(|| T::zero())),
                    weight: scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()),
                    constraint_threshold: Some(scirs2_core::numeric::NumCast::from(10.0).unwrap_or_else(|| T::zero())),
                },
                HardwareObjective {
                    id: "efficiency".to_string(),
                    objective_type: HardwareObjectiveType::MaximizeEfficiency,
                    target_value: None,
                    weight: scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()),
                    constraint_threshold: None,
                },
            ],
            energy_budget: None,
            thermal_constraints: None,
        }
    }
}