quantrs2_device/neutral_atom/
config.rs1use crate::DeviceResult;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6use std::time::Duration;
7
8#[derive(Debug, Clone, Serialize, Deserialize, Default)]
10pub struct AdvancedNeutralAtomConfig {
11 pub hardware_settings: HardwareSettings,
13 pub optimization: OptimizationConfig,
15 pub error_correction: ErrorCorrectionConfig,
17 pub calibration: CalibrationConfig,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, Default)]
23pub struct HardwareSettings {
24 pub laser_control: LaserControlConfig,
26 pub trap_config: TrapConfig,
28 pub detection: DetectionConfig,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct LaserControlConfig {
35 pub trapping_wavelength: f64,
37 pub rydberg_wavelength: f64,
39 pub max_power: f64,
41 pub beam_waist: f64,
43 pub stability: LaserStabilityConfig,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct LaserStabilityConfig {
50 pub frequency_stability: f64,
52 pub power_stability: f64,
54 pub phase_stability: f64,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct TrapConfig {
61 pub trap_depth: f64,
63 pub trap_frequency: f64,
65 pub anharmonicity: f64,
67 pub loading_rate: f64,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct DetectionConfig {
74 pub efficiency: f64,
76 pub dark_count_rate: f64,
78 pub integration_time: f64,
80 pub background_subtraction: bool,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct OptimizationConfig {
87 pub gate_optimization: bool,
89 pub circuit_optimization: bool,
91 pub max_optimization_time: Duration,
93 pub optimization_target: OptimizationTarget,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99pub enum OptimizationTarget {
100 Speed,
102 Fidelity,
104 Balanced,
106 Custom(String),
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct ErrorCorrectionConfig {
113 pub enabled: bool,
115 pub scheme: ErrorCorrectionScheme,
117 pub syndrome_detection: SyndromeDetectionConfig,
119 pub recovery_protocol: RecoveryProtocolConfig,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
125pub enum ErrorCorrectionScheme {
126 None,
128 Repetition,
130 Surface,
132 Color,
134 Custom(String),
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct SyndromeDetectionConfig {
141 pub threshold: f64,
143 pub measurement_rounds: usize,
145 pub majority_voting: bool,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct RecoveryProtocolConfig {
152 pub max_attempts: usize,
154 pub timeout: Duration,
156 pub adaptive: bool,
158}
159
160#[derive(Debug, Clone, Serialize, Deserialize)]
162pub struct CalibrationConfig {
163 pub auto_calibration: bool,
165 pub calibration_interval: Duration,
167 pub procedures: Vec<CalibrationProcedure>,
169 pub reference_measurements: HashMap<String, f64>,
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize)]
175pub enum CalibrationProcedure {
176 LaserFrequency,
178 PowerCalibration,
180 TrapDepth,
182 GateFidelity,
184 DetectionEfficiency,
186 Custom(String),
188}
189
190impl Default for LaserControlConfig {
191 fn default() -> Self {
192 Self {
193 trapping_wavelength: 852.0,
194 rydberg_wavelength: 480.0,
195 max_power: 100.0,
196 beam_waist: 1.0,
197 stability: LaserStabilityConfig::default(),
198 }
199 }
200}
201
202impl Default for LaserStabilityConfig {
203 fn default() -> Self {
204 Self {
205 frequency_stability: 1000.0,
206 power_stability: 0.1,
207 phase_stability: 0.01,
208 }
209 }
210}
211
212impl Default for TrapConfig {
213 fn default() -> Self {
214 Self {
215 trap_depth: 1000.0,
216 trap_frequency: 100_000.0,
217 anharmonicity: 0.01,
218 loading_rate: 1000.0,
219 }
220 }
221}
222
223impl Default for DetectionConfig {
224 fn default() -> Self {
225 Self {
226 efficiency: 0.95,
227 dark_count_rate: 10.0,
228 integration_time: 100.0,
229 background_subtraction: true,
230 }
231 }
232}
233
234impl Default for OptimizationConfig {
235 fn default() -> Self {
236 Self {
237 gate_optimization: true,
238 circuit_optimization: true,
239 max_optimization_time: Duration::from_millis(1000),
240 optimization_target: OptimizationTarget::Balanced,
241 }
242 }
243}
244
245impl Default for ErrorCorrectionConfig {
246 fn default() -> Self {
247 Self {
248 enabled: false,
249 scheme: ErrorCorrectionScheme::None,
250 syndrome_detection: SyndromeDetectionConfig::default(),
251 recovery_protocol: RecoveryProtocolConfig::default(),
252 }
253 }
254}
255
256impl Default for SyndromeDetectionConfig {
257 fn default() -> Self {
258 Self {
259 threshold: 0.5,
260 measurement_rounds: 3,
261 majority_voting: true,
262 }
263 }
264}
265
266impl Default for RecoveryProtocolConfig {
267 fn default() -> Self {
268 Self {
269 max_attempts: 3,
270 timeout: Duration::from_millis(100),
271 adaptive: true,
272 }
273 }
274}
275
276impl Default for CalibrationConfig {
277 fn default() -> Self {
278 Self {
279 auto_calibration: true,
280 calibration_interval: Duration::from_secs(3600),
281 procedures: vec![
282 CalibrationProcedure::LaserFrequency,
283 CalibrationProcedure::PowerCalibration,
284 CalibrationProcedure::TrapDepth,
285 ],
286 reference_measurements: HashMap::new(),
287 }
288 }
289}
290
291pub fn validate_advanced_config(config: &AdvancedNeutralAtomConfig) -> DeviceResult<()> {
293 if config.hardware_settings.laser_control.max_power <= 0.0 {
295 return Err(crate::DeviceError::InvalidInput(
296 "Maximum laser power must be positive".to_string(),
297 ));
298 }
299
300 if config.hardware_settings.trap_config.trap_depth <= 0.0 {
302 return Err(crate::DeviceError::InvalidInput(
303 "Trap depth must be positive".to_string(),
304 ));
305 }
306
307 let efficiency = config.hardware_settings.detection.efficiency;
309 if !(0.0..=1.0).contains(&efficiency) {
310 return Err(crate::DeviceError::InvalidInput(
311 "Detection efficiency must be between 0 and 1".to_string(),
312 ));
313 }
314
315 Ok(())
316}