quantrs2-device 0.1.3

Quantum device connectors for the QuantRS2 framework
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
//! Platform types and compilation targets

use std::collections::{HashMap, HashSet};
use std::time::{Duration, SystemTime};

use super::config::HardwareConstraints;
use crate::backend_traits::BackendCapabilities;

/// Multi-platform compilation target specifications
#[derive(Debug, Clone, PartialEq)]
pub enum CompilationTarget {
    /// IBM Quantum platform with specific backend
    IBMQuantum {
        backend_name: String,
        coupling_map: Vec<(usize, usize)>,
        native_gates: HashSet<String>,
        basis_gates: Vec<String>,
        max_shots: usize,
        simulator: bool,
    },
    /// AWS Braket platform
    AWSBraket {
        device_arn: String,
        provider: BraketProvider,
        supported_gates: HashSet<String>,
        max_shots: usize,
        cost_per_shot: f64,
    },
    /// Azure Quantum platform
    AzureQuantum {
        workspace: String,
        target: String,
        provider: AzureProvider,
        supported_operations: HashSet<String>,
        resource_estimation: bool,
    },
    /// IonQ platform
    IonQ {
        backend: String,
        all_to_all: bool,
        native_gates: HashSet<String>,
        noise_model: Option<String>,
    },
    /// Google Quantum AI
    GoogleQuantumAI {
        processor_id: String,
        gate_set: GoogleGateSet,
        topology: GridTopology,
    },
    /// Rigetti QCS
    Rigetti {
        qpu_id: String,
        lattice: RigettiLattice,
        supported_gates: HashSet<String>,
    },
    /// Custom hardware platform
    Custom {
        name: String,
        capabilities: BackendCapabilities,
        constraints: HardwareConstraints,
    },
}

/// AWS Braket provider types
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BraketProvider {
    IonQ,
    Rigetti,
    OQC,
    QuEra,
    Simulator,
}

/// Azure Quantum provider types
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AzureProvider {
    IonQ,
    Quantinuum,
    Pasqal,
    Rigetti,
    Microsoft,
}

/// Google Quantum AI gate sets
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GoogleGateSet {
    Sycamore,
    SqrtISwap,
    SYC,
}

/// Grid topology for Google devices
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GridTopology {
    pub rows: usize,
    pub cols: usize,
    pub connectivity: ConnectivityPattern,
}

/// Connectivity patterns
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConnectivityPattern {
    NearestNeighbor,
    Square,
    Hexagonal,
    Custom(Vec<(usize, usize)>),
}

/// Rigetti lattice types
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RigettiLattice {
    Aspen,
    Ankaa,
    Custom(Vec<(usize, usize)>),
}

/// Pass information with timing and metrics
#[derive(Debug, Clone)]
pub struct PassInfo {
    /// Pass name
    pub name: String,
    /// Execution time
    pub execution_time: Duration,
    /// Number of gates modified
    pub gates_modified: usize,
    /// Improvement metric
    pub improvement: f64,
    /// Pass-specific metrics
    pub metrics: HashMap<String, f64>,
    /// Success status
    pub success: bool,
    /// Error message if failed
    pub error_message: Option<String>,
}

/// Hardware allocation information
#[derive(Debug, Clone)]
pub struct HardwareAllocation {
    /// Qubit mapping from logical to physical
    pub qubit_mapping: HashMap<usize, usize>,
    /// Allocated qubits
    pub allocated_qubits: Vec<usize>,
    /// Resource utilization
    pub resource_utilization: f64,
    /// Allocation strategy used
    pub strategy: AllocationStrategy,
    /// Allocation quality score
    pub quality_score: f64,
}

/// Allocation strategies
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AllocationStrategy {
    GreedyMapping,
    OptimalMapping,
    HeuristicMapping,
    GraphBased,
    Custom(String),
}

/// Performance prediction with confidence intervals
#[derive(Debug, Clone)]
pub struct PerformancePrediction {
    /// Predicted execution time
    pub execution_time: Duration,
    /// Predicted fidelity
    pub fidelity: f64,
    /// Predicted error rate
    pub error_rate: f64,
    /// Success probability
    pub success_probability: f64,
    /// Confidence interval
    pub confidence_interval: (f64, f64),
    /// Prediction model used
    pub model: String,
}

/// Advanced metrics for compilation analysis
#[derive(Debug, Clone)]
pub struct AdvancedMetrics {
    /// Quantum volume
    pub quantum_volume: usize,
    /// Expressivity measure
    pub expressivity: f64,
    /// Entanglement entropy
    pub entanglement_entropy: f64,
    /// Circuit complexity
    pub complexity_score: f64,
    /// Resource efficiency
    pub resource_efficiency: f64,
    /// Error resilience
    pub error_resilience: f64,
    /// Platform compatibility score
    pub compatibility_score: f64,
}

/// Optimization iteration information
#[derive(Debug, Clone)]
pub struct OptimizationIteration {
    /// Iteration number
    pub iteration: usize,
    /// Objective function values
    pub objective_values: Vec<f64>,
    /// Applied transformations
    pub transformations: Vec<String>,
    /// Intermediate metrics
    pub intermediate_metrics: HashMap<String, f64>,
    /// Timestamp
    pub timestamp: Duration,
}

/// Platform-specific optimization results
#[derive(Debug, Clone)]
pub struct PlatformSpecificResults {
    /// Platform name
    pub platform: String,
    /// Platform-specific metrics
    pub metrics: HashMap<String, f64>,
    /// Applied transformations
    pub transformations: Vec<String>,
}

/// Platform-specific constraints
#[derive(Debug, Clone)]
pub struct PlatformConstraints {
    /// Maximum circuit depth
    pub max_depth: Option<usize>,
    /// Supported gate set
    pub supported_gates: HashSet<String>,
    /// Connectivity restrictions
    pub connectivity: Vec<(usize, usize)>,
    /// Timing constraints
    pub timing_constraints: HashMap<String, f64>,
}

/// Verification and validation results
#[derive(Debug, Clone)]
pub struct VerificationResults {
    /// Circuit equivalence verified
    pub equivalence_verified: bool,
    /// Constraint satisfaction verified
    pub constraints_satisfied: bool,
    /// Semantic correctness verified
    pub semantic_correctness: bool,
    /// Verification time
    pub verification_time: Duration,
    /// Detailed verification report
    pub verification_report: String,
}

/// Constraint verification result
#[derive(Debug, Clone)]
pub struct ConstraintVerificationResult {
    /// Whether constraints are satisfied
    pub is_valid: bool,
}

/// Semantic verification result
#[derive(Debug, Clone)]
pub struct SemanticVerificationResult {
    /// Whether semantics are correct
    pub is_valid: bool,
}

/// Complexity metrics for circuit analysis
#[derive(Debug, Clone)]
pub struct ComplexityMetrics {
    /// Circuit depth distribution
    pub depth_distribution: Vec<usize>,
    /// Gate type distribution
    pub gate_distribution: HashMap<String, usize>,
    /// Entanglement entropy
    pub entanglement_entropy: f64,
    /// Expressivity measure
    pub expressivity_measure: f64,
    /// Quantum volume
    pub quantum_volume: usize,
}

/// Compilation result with comprehensive analysis
#[derive(Debug, Clone)]
pub struct CompilationResult {
    /// Original circuit
    pub original_circuit: String,
    /// Optimized circuit
    pub optimized_circuit: String,
    /// Optimization statistics
    pub optimization_stats: OptimizationStats,
    /// Applied passes with detailed information
    pub applied_passes: Vec<PassInfo>,
    /// Hardware allocation and scheduling
    pub hardware_allocation: HardwareAllocation,
    /// Predicted performance with confidence intervals
    pub predicted_performance: PerformancePrediction,
    /// Compilation timing breakdown
    pub compilation_time: Duration,
    /// Advanced metrics and analysis
    pub advanced_metrics: AdvancedMetrics,
    /// Multi-pass optimization history
    pub optimization_history: Vec<OptimizationIteration>,
    /// Platform-specific results
    pub platform_specific: PlatformSpecificResults,
    /// Verification and validation results
    pub verification_results: VerificationResults,
}

/// Optimization statistics
#[derive(Debug, Clone)]
pub struct OptimizationStats {
    /// Original gate count
    pub original_gate_count: usize,
    /// Optimized gate count
    pub optimized_gate_count: usize,
    /// Original circuit depth
    pub original_depth: usize,
    /// Optimized circuit depth
    pub optimized_depth: usize,
    /// Predicted error rate improvement
    pub error_improvement: f64,
    /// Fidelity improvement
    pub fidelity_improvement: f64,
    /// Resource efficiency gain
    pub efficiency_gain: f64,
    /// Overall improvement score
    pub overall_improvement: f64,
}

/// Performance anomaly detection
#[derive(Debug, Clone)]
pub struct PerformanceAnomaly {
    /// Anomaly description
    pub description: String,
    /// Severity level
    pub severity: AnomalySeverity,
    /// Confidence score
    pub confidence: f64,
    /// Affected metrics
    pub affected_metrics: Vec<String>,
    /// Anomaly type
    pub anomaly_type: String,
    /// Recommended action
    pub recommended_action: String,
}

/// Anomaly severity levels
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AnomalySeverity {
    Low,
    Medium,
    High,
    Critical,
}

/// Advanced optimization results
#[derive(Debug, Clone)]
pub struct AdvancedOptimizationResult {
    /// Optimization method used
    pub method: String,
    /// Convergence achieved
    pub converged: bool,
    /// Final objective value
    pub objective_value: f64,
    /// Number of iterations
    pub iterations: usize,
    /// Parameter evolution
    pub parameter_evolution: Vec<scirs2_core::ndarray::Array1<f64>>,
    /// Whether optimization was successful
    pub success: bool,
    /// Optimized parameters
    pub x: scirs2_core::ndarray::Array1<f64>,
    /// Improvement achieved
    pub improvement: f64,
}

/// Linear algebra optimization results
#[derive(Debug, Clone)]
pub struct LinalgOptimizationResult {
    /// Matrix decomposition improvements
    pub decomposition_improvements: HashMap<String, f64>,
    /// Numerical stability metrics
    pub stability_metrics: NumericalStabilityMetrics,
    /// Eigenvalue analysis
    pub eigenvalue_analysis: EigenvalueAnalysis,
}

/// Numerical stability metrics
#[derive(Debug, Clone)]
pub struct NumericalStabilityMetrics {
    /// Condition number
    pub condition_number: f64,
    /// Numerical rank
    pub numerical_rank: usize,
    /// Spectral radius
    pub spectral_radius: f64,
}

/// Eigenvalue analysis
#[derive(Debug, Clone)]
pub struct EigenvalueAnalysis {
    /// Eigenvalue distribution
    pub eigenvalue_distribution: Vec<scirs2_core::Complex64>,
    /// Spectral gap
    pub spectral_gap: f64,
    /// Entanglement spectrum
    pub entanglement_spectrum: Vec<f64>,
}