quantrs2_device/process_tomography/
config.rs

1//! Configuration types for process tomography
2
3use std::collections::HashMap;
4
5/// Configuration for SciRS2-enhanced process tomography
6#[derive(Debug, Clone)]
7pub struct SciRS2ProcessTomographyConfig {
8    /// Number of input states for process characterization
9    pub num_input_states: usize,
10    /// Number of measurement shots per state
11    pub shots_per_state: usize,
12    /// Reconstruction method
13    pub reconstruction_method: ReconstructionMethod,
14    /// Statistical confidence level
15    pub confidence_level: f64,
16    /// Enable compressed sensing reconstruction
17    pub enable_compressed_sensing: bool,
18    /// Enable maximum likelihood estimation
19    pub enable_mle: bool,
20    /// Enable Bayesian inference
21    pub enable_bayesian: bool,
22    /// Enable process structure analysis
23    pub enable_structure_analysis: bool,
24    /// Enable multi-process tomography
25    pub enable_multi_process: bool,
26    /// Optimization settings
27    pub optimization_config: OptimizationConfig,
28    /// Validation settings
29    pub validation_config: ProcessValidationConfig,
30}
31
32/// Process reconstruction methods
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub enum ReconstructionMethod {
35    /// Linear inversion (fast but can produce unphysical results)
36    LinearInversion,
37    /// Maximum likelihood estimation (physical but slower)
38    MaximumLikelihood,
39    /// Compressed sensing (sparse process assumption)
40    CompressedSensing,
41    /// Bayesian inference with priors
42    BayesianInference,
43    /// Ensemble methods combining multiple approaches
44    EnsembleMethods,
45    /// Machine learning based reconstruction
46    MachineLearning,
47}
48
49/// Optimization configuration for process reconstruction
50#[derive(Debug, Clone)]
51pub struct OptimizationConfig {
52    /// Maximum number of iterations
53    pub max_iterations: usize,
54    /// Convergence tolerance
55    pub tolerance: f64,
56    /// Optimization algorithm
57    pub algorithm: OptimizationAlgorithm,
58    /// Enable parallel optimization
59    pub enable_parallel: bool,
60    /// Enable adaptive step sizing
61    pub adaptive_step_size: bool,
62    /// Regularization parameters
63    pub regularization: RegularizationConfig,
64}
65
66/// Optimization algorithms
67#[derive(Debug, Clone, PartialEq, Eq)]
68pub enum OptimizationAlgorithm {
69    LBFGS,
70    ConjugateGradient,
71    TrustRegion,
72    DifferentialEvolution,
73    SimulatedAnnealing,
74    GeneticAlgorithm,
75    ParticleSwarm,
76}
77
78/// Regularization configuration
79#[derive(Debug, Clone)]
80pub struct RegularizationConfig {
81    /// L1 regularization strength (sparsity)
82    pub l1_strength: f64,
83    /// L2 regularization strength (smoothness)
84    pub l2_strength: f64,
85    /// Trace preservation constraint strength
86    pub trace_strength: f64,
87    /// Positivity constraint strength
88    pub positivity_strength: f64,
89}
90
91/// Process validation configuration
92#[derive(Debug, Clone)]
93pub struct ProcessValidationConfig {
94    /// Enable cross-validation
95    pub enable_cross_validation: bool,
96    /// Number of CV folds
97    pub cv_folds: usize,
98    /// Enable bootstrap validation
99    pub enable_bootstrap: bool,
100    /// Number of bootstrap samples
101    pub bootstrap_samples: usize,
102    /// Enable process benchmarking
103    pub enable_benchmarking: bool,
104    /// Benchmark processes to compare against
105    pub benchmark_processes: Vec<String>,
106}
107
108impl Default for SciRS2ProcessTomographyConfig {
109    fn default() -> Self {
110        Self {
111            num_input_states: 36, // 6^n for n qubits (standard set)
112            shots_per_state: 10000,
113            reconstruction_method: ReconstructionMethod::MaximumLikelihood,
114            confidence_level: 0.95,
115            enable_compressed_sensing: true,
116            enable_mle: true,
117            enable_bayesian: false,
118            enable_structure_analysis: true,
119            enable_multi_process: false,
120            optimization_config: OptimizationConfig::default(),
121            validation_config: ProcessValidationConfig::default(),
122        }
123    }
124}
125
126impl Default for OptimizationConfig {
127    fn default() -> Self {
128        Self {
129            max_iterations: 1000,
130            tolerance: 1e-8,
131            algorithm: OptimizationAlgorithm::LBFGS,
132            enable_parallel: true,
133            adaptive_step_size: true,
134            regularization: RegularizationConfig::default(),
135        }
136    }
137}
138
139impl Default for RegularizationConfig {
140    fn default() -> Self {
141        Self {
142            l1_strength: 0.001,
143            l2_strength: 0.01,
144            trace_strength: 1000.0,
145            positivity_strength: 100.0,
146        }
147    }
148}
149
150impl Default for ProcessValidationConfig {
151    fn default() -> Self {
152        Self {
153            enable_cross_validation: true,
154            cv_folds: 5,
155            enable_bootstrap: true,
156            bootstrap_samples: 100,
157            enable_benchmarking: true,
158            benchmark_processes: vec![
159                "identity".to_string(),
160                "pauli_x".to_string(),
161                "pauli_y".to_string(),
162                "pauli_z".to_string(),
163                "hadamard".to_string(),
164            ],
165        }
166    }
167}