quantrs2_device/process_tomography/
results.rs

1//! Result and data structures for process tomography
2
3use super::config::SciRS2ProcessTomographyConfig;
4use scirs2_core::ndarray::{Array1, Array2, Array3, Array4};
5use scirs2_core::Complex64;
6use std::collections::HashMap;
7use std::time::{Duration, SystemTime};
8
9// Type placeholders for missing complex types
10pub type DistributionType = String;
11
12/// Comprehensive process tomography result with SciRS2 analysis
13#[derive(Debug, Clone)]
14pub struct SciRS2ProcessTomographyResult {
15    /// Device identifier
16    pub device_id: String,
17    /// Configuration used
18    pub config: SciRS2ProcessTomographyConfig,
19    /// Reconstructed process matrix (Chi representation)
20    pub process_matrix: Array4<Complex64>,
21    /// Process matrix in Pauli transfer representation
22    pub pauli_transfer_matrix: Array2<f64>,
23    /// Statistical analysis of the reconstruction
24    pub statistical_analysis: ProcessStatisticalAnalysis,
25    /// Process characterization metrics
26    pub process_metrics: ProcessMetrics,
27    /// Validation results
28    pub validation_results: ProcessValidationResults,
29    /// Structure analysis
30    pub structure_analysis: Option<ProcessStructureAnalysis>,
31    /// Uncertainty quantification
32    pub uncertainty_quantification: ProcessUncertaintyQuantification,
33    /// Comparison with known processes
34    pub process_comparisons: ProcessComparisons,
35}
36
37/// Statistical analysis of process reconstruction
38#[derive(Debug, Clone)]
39pub struct ProcessStatisticalAnalysis {
40    /// Reconstruction quality metrics
41    pub reconstruction_quality: ReconstructionQuality,
42    /// Statistical tests on the process
43    pub statistical_tests: HashMap<String, StatisticalTest>,
44    /// Distribution analysis of process elements
45    pub distribution_analysis: DistributionAnalysis,
46    /// Correlation analysis
47    pub correlation_analysis: CorrelationAnalysis,
48}
49
50/// Process characterization metrics
51#[derive(Debug, Clone)]
52pub struct ProcessMetrics {
53    /// Process fidelity with ideal process
54    pub process_fidelity: f64,
55    /// Average gate fidelity
56    pub average_gate_fidelity: f64,
57    /// Unitarity measure
58    pub unitarity: f64,
59    /// Entangling power
60    pub entangling_power: f64,
61    /// Non-unitality measure
62    pub non_unitality: f64,
63    /// Channel capacity
64    pub channel_capacity: f64,
65    /// Coherent information
66    pub coherent_information: f64,
67    /// Diamond norm distance
68    pub diamond_norm_distance: f64,
69    /// Process spectrum (eigenvalues of the process)
70    pub process_spectrum: Array1<f64>,
71}
72
73/// Process validation results
74#[derive(Debug, Clone)]
75pub struct ProcessValidationResults {
76    /// Cross-validation results
77    pub cross_validation: Option<CrossValidationResults>,
78    /// Bootstrap validation results
79    pub bootstrap_results: Option<BootstrapResults>,
80    /// Benchmark comparison results
81    pub benchmark_results: Option<BenchmarkResults>,
82    /// Model selection results
83    pub model_selection: ModelSelectionResults,
84}
85
86/// Process structure analysis
87#[derive(Debug, Clone)]
88pub struct ProcessStructureAnalysis {
89    /// Kraus decomposition
90    pub kraus_decomposition: KrausDecomposition,
91    /// Noise decomposition
92    pub noise_decomposition: NoiseDecomposition,
93    /// Coherence analysis
94    pub coherence_analysis: CoherenceAnalysis,
95    /// Symmetry analysis
96    pub symmetry_analysis: SymmetryAnalysis,
97    /// Process graph representation
98    pub process_graph: ProcessGraph,
99}
100
101/// Uncertainty quantification for process estimates
102#[derive(Debug, Clone)]
103pub struct ProcessUncertaintyQuantification {
104    /// Confidence intervals for process elements
105    pub confidence_intervals: Array4<(f64, f64)>,
106    /// Bootstrap uncertainty estimates
107    pub bootstrap_uncertainty: Array4<f64>,
108    /// Fisher information matrix
109    pub fisher_information: Array2<f64>,
110}
111
112/// Comparison with known process models
113#[derive(Debug, Clone)]
114pub struct ProcessComparisons {
115    /// Fidelities with standard processes
116    pub standard_process_fidelities: HashMap<String, f64>,
117    /// Distance measures to known processes
118    pub process_distances: HashMap<String, f64>,
119    /// Model selection criteria
120    pub model_selection_scores: HashMap<String, f64>,
121}
122
123/// Reconstruction quality metrics
124#[derive(Debug, Clone)]
125pub struct ReconstructionQuality {
126    /// Log-likelihood of the reconstruction
127    pub log_likelihood: f64,
128    /// Physical validity metrics
129    pub physical_validity: PhysicalValidityMetrics,
130    /// Numerical stability indicators
131    pub condition_number: f64,
132}
133
134/// Physical validity metrics for reconstructed processes
135#[derive(Debug, Clone)]
136pub struct PhysicalValidityMetrics {
137    /// Is the process completely positive?
138    pub is_completely_positive: bool,
139    /// Is the process trace preserving?
140    pub is_trace_preserving: bool,
141    /// Positivity measure (0-1, 1 = perfectly positive)
142    pub positivity_measure: f64,
143    /// Trace preservation measure (0-1, 1 = perfectly trace preserving)
144    pub trace_preservation_measure: f64,
145}
146
147/// Statistical test result
148#[derive(Debug, Clone)]
149pub struct StatisticalTest {
150    /// Test statistic value
151    pub statistic: f64,
152    /// P-value
153    pub p_value: f64,
154    /// Critical value at specified confidence level
155    pub critical_value: f64,
156    /// Whether the test is significant
157    pub is_significant: bool,
158    /// Effect size (if applicable)
159    pub effect_size: Option<f64>,
160}
161
162/// Distribution analysis of process matrix elements
163#[derive(Debug, Clone)]
164pub struct DistributionAnalysis {
165    /// Distribution fits for real and imaginary parts
166    pub element_distributions: HashMap<String, ElementDistribution>,
167    /// Global distribution properties
168    pub global_properties: GlobalDistributionProperties,
169}
170
171/// Distribution fit for a specific element or set of elements
172#[derive(Debug, Clone)]
173pub struct ElementDistribution {
174    /// Type of distribution (normal, gamma, etc.)
175    pub distribution_type: DistributionType,
176    /// Distribution parameters
177    pub parameters: Vec<f64>,
178    /// Goodness of fit measure
179    pub goodness_of_fit: f64,
180    /// Confidence interval
181    pub confidence_interval: (f64, f64),
182}
183
184/// Global properties of the distribution of process elements
185#[derive(Debug, Clone)]
186pub struct GlobalDistributionProperties {
187    /// Overall skewness
188    pub skewness: f64,
189    /// Overall kurtosis
190    pub kurtosis: f64,
191    /// Entropy of the distribution
192    pub entropy: f64,
193}
194
195/// Correlation analysis between process elements
196#[derive(Debug, Clone)]
197pub struct CorrelationAnalysis {
198    /// Pairwise correlations between elements
199    pub element_correlations: HashMap<String, f64>,
200    /// Principal component analysis
201    pub principal_components: Array2<f64>,
202    /// Correlation network structure
203    pub correlation_network: CorrelationNetwork,
204}
205
206/// Correlation network structure
207#[derive(Debug, Clone)]
208pub struct CorrelationNetwork {
209    /// Adjacency matrix of significant correlations
210    pub adjacency_matrix: Array2<f64>,
211    /// Network centrality measures
212    pub centrality_measures: HashMap<String, f64>,
213}
214
215/// Cross-validation results
216#[derive(Debug, Clone)]
217pub struct CrossValidationResults {
218    /// CV scores for different folds
219    pub fold_scores: Vec<f64>,
220    /// Mean CV score
221    pub mean_score: f64,
222    /// Standard deviation of CV scores
223    pub std_score: f64,
224    /// Confidence interval for the mean score
225    pub confidence_interval: (f64, f64),
226}
227
228/// Bootstrap validation results
229#[derive(Debug, Clone)]
230pub struct BootstrapResults {
231    /// Bootstrap samples of process metrics
232    pub bootstrap_samples: Vec<ProcessMetrics>,
233    /// Bootstrap confidence intervals
234    pub confidence_intervals: HashMap<String, (f64, f64)>,
235    /// Bootstrap bias estimates
236    pub bias_estimates: HashMap<String, f64>,
237}
238
239/// Benchmark comparison results
240#[derive(Debug, Clone)]
241pub struct BenchmarkResults {
242    /// Scores against benchmark processes
243    pub benchmark_scores: HashMap<String, f64>,
244    /// Rankings among benchmark processes
245    pub rankings: HashMap<String, usize>,
246}
247
248/// Model selection results
249#[derive(Debug, Clone)]
250pub struct ModelSelectionResults {
251    /// AIC scores for different models
252    pub aic_scores: HashMap<String, f64>,
253    /// BIC scores for different models
254    pub bic_scores: HashMap<String, f64>,
255    /// Cross-validation scores for different models
256    pub cross_validation_scores: HashMap<String, f64>,
257    /// Best model according to selection criteria
258    pub best_model: String,
259    /// Model weights for ensemble methods
260    pub model_weights: HashMap<String, f64>,
261}
262
263/// Kraus decomposition of the quantum process
264#[derive(Debug, Clone)]
265pub struct KrausDecomposition {
266    /// Kraus operators
267    pub kraus_operators: Vec<Array2<Complex64>>,
268    /// Decomposition fidelity
269    pub decomposition_fidelity: f64,
270    /// Number of significant Kraus operators
271    pub rank: usize,
272}
273
274/// Noise decomposition analysis
275#[derive(Debug, Clone)]
276pub struct NoiseDecomposition {
277    /// Coherent error component
278    pub coherent_error: Array2<Complex64>,
279    /// Incoherent error components
280    pub incoherent_errors: HashMap<String, f64>,
281    /// Overall error strength
282    pub total_error_strength: f64,
283}
284
285/// Coherence analysis of the process
286#[derive(Debug, Clone)]
287pub struct CoherenceAnalysis {
288    /// Coherence measures
289    pub coherence_measures: HashMap<String, f64>,
290    /// Decoherence time estimates
291    pub decoherence_times: HashMap<String, f64>,
292    /// Coherence matrix
293    pub coherence_matrix: Array2<f64>,
294}
295
296/// Symmetry analysis of the process
297#[derive(Debug, Clone)]
298pub struct SymmetryAnalysis {
299    /// Detected symmetries
300    pub symmetries: Vec<String>,
301    /// Symmetry violation measures
302    pub symmetry_violations: HashMap<String, f64>,
303    /// Symmetry preservation scores
304    pub preservation_scores: HashMap<String, f64>,
305}
306
307/// Graph representation of the process
308#[derive(Debug, Clone)]
309pub struct ProcessGraph {
310    /// Adjacency matrix of the process graph
311    pub adjacency_matrix: Array2<f64>,
312    /// Node properties
313    pub node_properties: Vec<NodeProperties>,
314    /// Graph metrics
315    pub graph_metrics: GraphMetrics,
316}
317
318/// Properties of nodes in the process graph
319#[derive(Debug, Clone)]
320pub struct NodeProperties {
321    /// Node index
322    pub index: usize,
323    /// Node strength (sum of connections)
324    pub strength: f64,
325    /// Clustering coefficient
326    pub clustering_coefficient: f64,
327    /// Betweenness centrality
328    pub betweenness_centrality: f64,
329}
330
331/// Graph-level metrics
332#[derive(Debug, Clone)]
333pub struct GraphMetrics {
334    /// Number of nodes
335    pub num_nodes: usize,
336    /// Number of edges
337    pub num_edges: usize,
338    /// Graph density
339    pub density: f64,
340    /// Average clustering coefficient
341    pub average_clustering: f64,
342    /// Average path length
343    pub average_path_length: f64,
344}
345
346/// Experimental data collected for process tomography
347#[derive(Debug, Clone)]
348pub struct ExperimentalData {
349    /// Input quantum states
350    pub input_states: Vec<Array2<Complex64>>,
351    /// Measurement operators
352    pub measurement_operators: Vec<Array2<Complex64>>,
353    /// Measurement outcomes (probabilities or counts)
354    pub measurement_results: Vec<f64>,
355    /// Measurement uncertainties
356    pub measurement_uncertainties: Vec<f64>,
357}
358
359/// Anomaly detection for process monitoring
360#[derive(Debug, Clone)]
361pub struct ProcessAnomalyDetector {
362    /// Historical process data
363    pub historical_data: Vec<ProcessMetrics>,
364    /// Anomaly detection threshold
365    pub threshold: f64,
366    /// Detection algorithm
367    pub algorithm: AnomalyDetectionAlgorithm,
368}
369
370/// Anomaly detection algorithms
371#[derive(Debug, Clone)]
372pub enum AnomalyDetectionAlgorithm {
373    StatisticalThreshold,
374    IsolationForest,
375    OneClassSVM,
376    LocalOutlierFactor,
377}
378
379/// Drift detection for process stability monitoring
380#[derive(Debug, Clone)]
381pub struct ProcessDriftDetector {
382    /// Reference process metrics
383    pub reference_metrics: ProcessMetrics,
384    /// Drift detection sensitivity
385    pub sensitivity: f64,
386    /// Drift detection method
387    pub method: DriftDetectionMethod,
388}
389
390/// Drift detection methods
391#[derive(Debug, Clone)]
392pub enum DriftDetectionMethod {
393    StatisticalTest,
394    ChangePointDetection,
395    KLDivergence,
396    WassersteinDistance,
397}
398
399/// Process monitoring result
400#[derive(Debug, Clone)]
401pub struct ProcessMonitoringResult {
402    /// Current process metrics
403    pub current_metrics: ProcessMetrics,
404    /// Experimental conditions
405    pub experimental_conditions: ExperimentalConditions,
406    /// Anomaly score (0-1, higher = more anomalous)
407    pub anomaly_score: f64,
408    /// Drift indicator (0-1, higher = more drift)
409    pub drift_indicator: f64,
410    /// Alert level
411    pub alert_level: AlertLevel,
412}
413
414/// Experimental conditions during measurement
415#[derive(Debug, Clone)]
416pub struct ExperimentalConditions {
417    /// Temperature (if available)
418    pub temperature: Option<f64>,
419    /// Estimated noise level
420    pub noise_level: f64,
421    /// Time since last calibration
422    pub calibration_age: Duration,
423    /// Number of gates in the process
424    pub gate_count: usize,
425    /// Circuit depth
426    pub circuit_depth: usize,
427}
428
429/// Alert levels for process monitoring
430#[derive(Debug, Clone, PartialEq, Eq)]
431pub enum AlertLevel {
432    Normal,
433    Warning,
434    Critical,
435}
436
437impl Default for ProcessMetrics {
438    fn default() -> Self {
439        Self {
440            process_fidelity: 1.0,
441            average_gate_fidelity: 1.0,
442            unitarity: 1.0,
443            entangling_power: 0.0,
444            non_unitality: 0.0,
445            channel_capacity: 1.0,
446            coherent_information: 1.0,
447            diamond_norm_distance: 0.0,
448            process_spectrum: Array1::ones(2),
449        }
450    }
451}
452
453impl Default for StatisticalTest {
454    fn default() -> Self {
455        Self {
456            statistic: 0.0,
457            p_value: 1.0,
458            critical_value: 0.0,
459            is_significant: false,
460            effect_size: None,
461        }
462    }
463}
464
465impl Default for ElementDistribution {
466    fn default() -> Self {
467        Self {
468            distribution_type: "normal".to_string(),
469            parameters: vec![0.0, 1.0],
470            goodness_of_fit: 1.0,
471            confidence_interval: (0.0, 1.0),
472        }
473    }
474}
475
476impl Default for GlobalDistributionProperties {
477    fn default() -> Self {
478        Self {
479            skewness: 0.0,
480            kurtosis: 0.0,
481            entropy: 1.0,
482        }
483    }
484}
485
486impl Default for CorrelationNetwork {
487    fn default() -> Self {
488        Self {
489            adjacency_matrix: Array2::zeros((2, 2)),
490            centrality_measures: HashMap::new(),
491        }
492    }
493}
494
495impl Default for GraphMetrics {
496    fn default() -> Self {
497        Self {
498            num_nodes: 0,
499            num_edges: 0,
500            density: 0.0,
501            average_clustering: 0.0,
502            average_path_length: 0.0,
503        }
504    }
505}