Waveform

Struct Waveform 

Source
pub struct Waveform {
    pub samples: Vec<Complex<f64>>,
    pub sample_rate: f64,
    pub duration: f64,
}
Expand description

Pulse waveform representation

Fields§

§samples: Vec<Complex<f64>>

Sample points

§sample_rate: f64

Sample rate in GS/s (gigasamples per second)

§duration: f64

Total duration in nanoseconds

Implementations§

Source§

impl Waveform

Source

pub fn new(samples: Vec<Complex<f64>>, sample_rate: f64) -> Self

Create a new waveform

Examples found in repository?
examples/pulse_demo.rs (line 403)
330fn demo_advanced_pulses() -> quantrs2_core::error::QuantRS2Result<()> {
331    println!("--- Advanced Pulse Techniques ---");
332
333    let sample_rate = 2.0; // 2 GS/s for higher resolution
334
335    // Composite pulse for robust gates
336    println!("Composite pulse sequence (BB1):");
337    let mut bb1_schedule = PulseSchedule::new();
338
339    // BB1 sequence: Ry(π/2) - Rx(π) - Ry(3π/2) - Rx(π)
340    let pi2_y = Waveform::gaussian(0.25, 8.0, 32.0, sample_rate);
341    let pi_x = Waveform::gaussian(0.5, 8.0, 32.0, sample_rate);
342    let three_pi2_y = Waveform::gaussian(0.75, 8.0, 32.0, sample_rate);
343
344    let mut time = 0.0;
345
346    bb1_schedule.add_instruction(
347        time,
348        PulseInstruction::Play {
349            waveform: pi2_y,
350            channel: Channel::Drive(0),
351            phase: PI / 2.0, // Y rotation
352        },
353    );
354    time += 32.0;
355
356    bb1_schedule.add_instruction(
357        time,
358        PulseInstruction::Play {
359            waveform: pi_x.clone(),
360            channel: Channel::Drive(0),
361            phase: 0.0, // X rotation
362        },
363    );
364    time += 32.0;
365
366    bb1_schedule.add_instruction(
367        time,
368        PulseInstruction::Play {
369            waveform: three_pi2_y,
370            channel: Channel::Drive(0),
371            phase: PI / 2.0, // Y rotation
372        },
373    );
374    time += 32.0;
375
376    bb1_schedule.add_instruction(
377        time,
378        PulseInstruction::Play {
379            waveform: pi_x,
380            channel: Channel::Drive(0),
381            phase: 0.0, // X rotation
382        },
383    );
384
385    println!("  Total duration: {} ns", bb1_schedule.duration);
386    println!("  Robustness: High (compensates for amplitude errors)");
387
388    // Adiabatic pulses
389    println!("\nAdiabatic pulse:");
390    let mut adiabatic_samples = Vec::new();
391    let duration = 100.0;
392    let n_samples = (duration * sample_rate) as usize;
393
394    for i in 0..n_samples {
395        let t = i as f64 / sample_rate;
396        let normalized_t = t / duration;
397
398        // Tanh profile for adiabatic following
399        let amplitude = 0.5 * ((10.0 * (normalized_t - 0.5)).tanh() + 1.0) / 2.0;
400        adiabatic_samples.push(C64::new(amplitude, 0.0));
401    }
402
403    let adiabatic = Waveform::new(adiabatic_samples, sample_rate);
404    println!("  Duration: {} ns", adiabatic.duration);
405    println!("  Profile: Smooth tanh ramp");
406    println!("  Use case: State transfer with high fidelity");
407
408    Ok(())
409}
Source

pub fn gaussian( amplitude: f64, sigma: f64, duration: f64, sample_rate: f64, ) -> Self

Create a Gaussian pulse

Examples found in repository?
examples/pulse_demo.rs (line 33)
27fn demo_pulse_waveforms() -> quantrs2_core::error::QuantRS2Result<()> {
28    println!("--- Pulse Waveform Types ---");
29
30    let sample_rate = 1.0; // 1 GS/s
31
32    // Gaussian pulse
33    let gaussian = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
34    println!("Gaussian pulse:");
35    println!("  Amplitude: 0.5");
36    println!("  Sigma: 10.0 ns");
37    println!("  Duration: {} ns", gaussian.duration);
38    println!("  Samples: {}", gaussian.samples.len());
39    println!("  Max amplitude: {:.4}", gaussian.max_amplitude());
40
41    // DRAG pulse
42    let drag = Waveform::drag(0.5, 10.0, 0.1, 40.0, sample_rate);
43    println!("\nDRAG pulse:");
44    println!("  Beta: 0.1");
45    println!(
46        "  Has imaginary component: {}",
47        drag.samples.iter().any(|s| s.im.abs() > 1e-10)
48    );
49
50    // Square pulse
51    let square = Waveform::square(0.3, 20.0, sample_rate);
52    println!("\nSquare pulse:");
53    println!("  Amplitude: 0.3");
54    println!("  Duration: {} ns", square.duration);
55
56    // Modulated pulse
57    let mut modulated = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
58    modulated.modulate(0.1, PI / 4.0); // 100 MHz modulation
59    println!("\nModulated Gaussian:");
60    println!("  Modulation frequency: 100 MHz");
61    println!("  Phase: π/4");
62
63    println!();
64    Ok(())
65}
66
67fn demo_pulse_schedules() -> quantrs2_core::error::QuantRS2Result<()> {
68    println!("--- Pulse Schedule Construction ---");
69
70    let sample_rate = 1.0;
71    let mut schedule = PulseSchedule::new();
72
73    // Create waveforms
74    let pi_pulse = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
75    let pi2_pulse = Waveform::gaussian(0.25, 10.0, 40.0, sample_rate);
76    let cr_pulse = Waveform::square(0.1, 200.0, sample_rate);
77
78    // Build schedule for a simple circuit
79    let mut time = 0.0;
80
81    // X gate on qubit 0
82    schedule.add_instruction(
83        time,
84        PulseInstruction::Play {
85            waveform: pi_pulse.clone(),
86            channel: Channel::Drive(0),
87            phase: 0.0,
88        },
89    );
90    time += 40.0;
91
92    // Delay
93    schedule.add_instruction(
94        time,
95        PulseInstruction::Delay {
96            duration: 20.0,
97            channels: vec![Channel::Drive(0), Channel::Drive(1)],
98        },
99    );
100    time += 20.0;
101
102    // CNOT using cross-resonance
103    schedule.add_instruction(
104        time,
105        PulseInstruction::Play {
106            waveform: cr_pulse,
107            channel: Channel::Control(0, 1),
108            phase: 0.0,
109        },
110    );
111
112    // Echo pulse on target
113    schedule.add_instruction(
114        time + 100.0,
115        PulseInstruction::Play {
116            waveform: pi_pulse.clone(),
117            channel: Channel::Drive(1),
118            phase: PI,
119        },
120    );
121    time += 200.0;
122
123    // Measurement
124    schedule.add_instruction(
125        time,
126        PulseInstruction::Acquire {
127            duration: 1000.0,
128            channel: Channel::Measure(0),
129            memory_slot: 0,
130        },
131    );
132
133    println!("Built pulse schedule:");
134    println!("  Total duration: {} ns", schedule.duration);
135    println!("  Instructions: {}", schedule.instructions.len());
136    println!("  Channels used: {}", schedule.channels.len());
137
138    println!("\nSchedule timeline:");
139    for (time, instruction) in &schedule.instructions {
140        match instruction {
141            PulseInstruction::Play { channel, .. } => {
142                println!("  {:6.1} ns: Play on {:?}", time, channel);
143            }
144            PulseInstruction::Delay { duration, .. } => {
145                println!("  {:6.1} ns: Delay {} ns", time, duration);
146            }
147            PulseInstruction::Acquire { channel, .. } => {
148                println!("  {:6.1} ns: Acquire on {:?}", time, channel);
149            }
150            _ => {}
151        }
152    }
153
154    println!();
155    Ok(())
156}
157
158fn demo_pulse_compilation() -> quantrs2_core::error::QuantRS2Result<()> {
159    println!("--- Circuit to Pulse Compilation ---");
160
161    // Create device configuration
162    let device_config = DeviceConfig::default_config(4);
163    println!("Device configuration:");
164    println!("  Qubits: 4");
165    println!("  Qubit frequencies: ~5 GHz");
166    println!("  Sample rate: {} GS/s", device_config.sample_rate);
167
168    // Create compiler
169    let compiler = PulseCompiler::new(device_config);
170
171    // Create a simple circuit
172    let mut circuit = Circuit::<4>::new();
173    circuit.add_gate(Hadamard { target: QubitId(0) })?;
174    circuit.add_gate(CNOT {
175        control: QubitId(0),
176        target: QubitId(1),
177    })?;
178    circuit.add_gate(RotationZ {
179        target: QubitId(1),
180        theta: PI / 4.0,
181    })?;
182
183    println!("\nCompiling circuit:");
184    for (i, gate) in circuit.gates().iter().enumerate() {
185        println!("  {}: {}", i, gate.name());
186    }
187
188    // Compile to pulses
189    let pulse_schedule = compiler.compile(&circuit)?;
190
191    println!("\nCompiled pulse schedule:");
192    println!("  Duration: {} ns", pulse_schedule.duration);
193    println!("  Instructions: {}", pulse_schedule.instructions.len());
194
195    // Show channel usage
196    let mut channel_usage = std::collections::HashMap::new();
197    for (_, instruction) in &pulse_schedule.instructions {
198        match instruction {
199            PulseInstruction::Play { channel, .. } => {
200                *channel_usage.entry(format!("{:?}", channel)).or_insert(0) += 1;
201            }
202            _ => {}
203        }
204    }
205
206    println!("\nChannel usage:");
207    for (channel, count) in channel_usage {
208        println!("  {}: {} pulses", channel, count);
209    }
210
211    println!();
212    Ok(())
213}
214
215fn demo_pulse_calibration() -> quantrs2_core::error::QuantRS2Result<()> {
216    println!("--- Pulse Calibration ---");
217
218    let sample_rate = 1.0;
219
220    // Create calibrations for different rotation angles
221    let angles = vec![PI / 4.0, PI / 2.0, PI, 3.0 * PI / 2.0];
222    let mut calibrations = Vec::new();
223
224    for &angle in &angles {
225        // Calculate pulse amplitude for rotation
226        let amplitude = angle / (2.0 * PI) * 0.5; // Simplified
227        let waveform = Waveform::gaussian(amplitude, 10.0, 40.0, sample_rate);
228
229        let mut schedule = PulseSchedule::new();
230        schedule.add_instruction(
231            0.0,
232            PulseInstruction::Play {
233                waveform,
234                channel: Channel::Drive(0),
235                phase: 0.0,
236            },
237        );
238
239        let mut parameters = std::collections::HashMap::new();
240        parameters.insert("theta".to_string(), angle);
241
242        calibrations.push(PulseCalibration {
243            gate_name: "RZ".to_string(),
244            qubits: vec![QubitId(0)],
245            parameters,
246            schedule,
247        });
248    }
249
250    println!("Created {} calibrations for RZ gate", calibrations.len());
251
252    for calib in &calibrations {
253        let theta = calib.parameters.get("theta").unwrap();
254        println!(
255            "  RZ(θ={:.3}): duration = {} ns",
256            theta, calib.schedule.duration
257        );
258    }
259
260    // Demonstrate calibration interpolation
261    println!("\nCalibration interpolation:");
262    let target_angle = PI / 3.0;
263    println!("  Target angle: π/3");
264    println!("  Would interpolate between π/4 and π/2 calibrations");
265
266    println!();
267    Ok(())
268}
269
270fn demo_pulse_optimization() -> quantrs2_core::error::QuantRS2Result<()> {
271    println!("--- Pulse Optimization ---");
272
273    let sample_rate = 1.0;
274    let optimizer = PulseOptimizer::new();
275
276    // Create initial pulse
277    let mut pulse = Waveform::gaussian(0.5, 15.0, 60.0, sample_rate);
278    println!("Initial pulse:");
279    println!("  Type: Gaussian");
280    println!("  Duration: {} ns", pulse.duration);
281    println!("  Max amplitude: {:.4}", pulse.max_amplitude());
282
283    // Apply DRAG correction
284    optimizer.apply_drag_correction(&mut pulse, 0.1)?;
285    println!("\nAfter DRAG correction:");
286    println!(
287        "  Has imaginary component: {}",
288        pulse.samples.iter().any(|s| s.im.abs() > 1e-10)
289    );
290
291    // Create a pulse schedule to optimize
292    let mut schedule = PulseSchedule::new();
293
294    // Add multiple pulses
295    for i in 0..3 {
296        let waveform = Waveform::gaussian(0.4, 12.0, 48.0, sample_rate);
297        schedule.add_instruction(
298            i as f64 * 60.0,
299            PulseInstruction::Play {
300                waveform,
301                channel: Channel::Drive(i),
302                phase: 0.0,
303            },
304        );
305    }
306
307    println!("\nSchedule optimization:");
308    println!("  Original duration: {} ns", schedule.duration);
309
310    // Optimize (placeholder - would do actual optimization)
311    optimizer.optimize(&mut schedule)?;
312
313    println!(
314        "  Optimized duration: {} ns (placeholder)",
315        schedule.duration
316    );
317    println!("  Target fidelity: 0.999"); // Placeholder since field is private
318
319    // Demonstrate pulse shaping techniques
320    println!("\nPulse shaping techniques:");
321    println!("  - Gaussian: Smooth envelope, reduced frequency spread");
322    println!("  - DRAG: Reduces leakage to higher levels");
323    println!("  - Cosine: Smooth turn-on/off");
324    println!("  - GRAPE: Optimal control for specific unitaries");
325
326    println!();
327    Ok(())
328}
329
330fn demo_advanced_pulses() -> quantrs2_core::error::QuantRS2Result<()> {
331    println!("--- Advanced Pulse Techniques ---");
332
333    let sample_rate = 2.0; // 2 GS/s for higher resolution
334
335    // Composite pulse for robust gates
336    println!("Composite pulse sequence (BB1):");
337    let mut bb1_schedule = PulseSchedule::new();
338
339    // BB1 sequence: Ry(π/2) - Rx(π) - Ry(3π/2) - Rx(π)
340    let pi2_y = Waveform::gaussian(0.25, 8.0, 32.0, sample_rate);
341    let pi_x = Waveform::gaussian(0.5, 8.0, 32.0, sample_rate);
342    let three_pi2_y = Waveform::gaussian(0.75, 8.0, 32.0, sample_rate);
343
344    let mut time = 0.0;
345
346    bb1_schedule.add_instruction(
347        time,
348        PulseInstruction::Play {
349            waveform: pi2_y,
350            channel: Channel::Drive(0),
351            phase: PI / 2.0, // Y rotation
352        },
353    );
354    time += 32.0;
355
356    bb1_schedule.add_instruction(
357        time,
358        PulseInstruction::Play {
359            waveform: pi_x.clone(),
360            channel: Channel::Drive(0),
361            phase: 0.0, // X rotation
362        },
363    );
364    time += 32.0;
365
366    bb1_schedule.add_instruction(
367        time,
368        PulseInstruction::Play {
369            waveform: three_pi2_y,
370            channel: Channel::Drive(0),
371            phase: PI / 2.0, // Y rotation
372        },
373    );
374    time += 32.0;
375
376    bb1_schedule.add_instruction(
377        time,
378        PulseInstruction::Play {
379            waveform: pi_x,
380            channel: Channel::Drive(0),
381            phase: 0.0, // X rotation
382        },
383    );
384
385    println!("  Total duration: {} ns", bb1_schedule.duration);
386    println!("  Robustness: High (compensates for amplitude errors)");
387
388    // Adiabatic pulses
389    println!("\nAdiabatic pulse:");
390    let mut adiabatic_samples = Vec::new();
391    let duration = 100.0;
392    let n_samples = (duration * sample_rate) as usize;
393
394    for i in 0..n_samples {
395        let t = i as f64 / sample_rate;
396        let normalized_t = t / duration;
397
398        // Tanh profile for adiabatic following
399        let amplitude = 0.5 * ((10.0 * (normalized_t - 0.5)).tanh() + 1.0) / 2.0;
400        adiabatic_samples.push(C64::new(amplitude, 0.0));
401    }
402
403    let adiabatic = Waveform::new(adiabatic_samples, sample_rate);
404    println!("  Duration: {} ns", adiabatic.duration);
405    println!("  Profile: Smooth tanh ramp");
406    println!("  Use case: State transfer with high fidelity");
407
408    Ok(())
409}
Source

pub fn drag( amplitude: f64, sigma: f64, beta: f64, duration: f64, sample_rate: f64, ) -> Self

Create a DRAG (Derivative Removal by Adiabatic Gate) pulse

Examples found in repository?
examples/pulse_demo.rs (line 42)
27fn demo_pulse_waveforms() -> quantrs2_core::error::QuantRS2Result<()> {
28    println!("--- Pulse Waveform Types ---");
29
30    let sample_rate = 1.0; // 1 GS/s
31
32    // Gaussian pulse
33    let gaussian = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
34    println!("Gaussian pulse:");
35    println!("  Amplitude: 0.5");
36    println!("  Sigma: 10.0 ns");
37    println!("  Duration: {} ns", gaussian.duration);
38    println!("  Samples: {}", gaussian.samples.len());
39    println!("  Max amplitude: {:.4}", gaussian.max_amplitude());
40
41    // DRAG pulse
42    let drag = Waveform::drag(0.5, 10.0, 0.1, 40.0, sample_rate);
43    println!("\nDRAG pulse:");
44    println!("  Beta: 0.1");
45    println!(
46        "  Has imaginary component: {}",
47        drag.samples.iter().any(|s| s.im.abs() > 1e-10)
48    );
49
50    // Square pulse
51    let square = Waveform::square(0.3, 20.0, sample_rate);
52    println!("\nSquare pulse:");
53    println!("  Amplitude: 0.3");
54    println!("  Duration: {} ns", square.duration);
55
56    // Modulated pulse
57    let mut modulated = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
58    modulated.modulate(0.1, PI / 4.0); // 100 MHz modulation
59    println!("\nModulated Gaussian:");
60    println!("  Modulation frequency: 100 MHz");
61    println!("  Phase: π/4");
62
63    println!();
64    Ok(())
65}
Source

pub fn square(amplitude: f64, duration: f64, sample_rate: f64) -> Self

Create a square pulse

Examples found in repository?
examples/pulse_demo.rs (line 51)
27fn demo_pulse_waveforms() -> quantrs2_core::error::QuantRS2Result<()> {
28    println!("--- Pulse Waveform Types ---");
29
30    let sample_rate = 1.0; // 1 GS/s
31
32    // Gaussian pulse
33    let gaussian = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
34    println!("Gaussian pulse:");
35    println!("  Amplitude: 0.5");
36    println!("  Sigma: 10.0 ns");
37    println!("  Duration: {} ns", gaussian.duration);
38    println!("  Samples: {}", gaussian.samples.len());
39    println!("  Max amplitude: {:.4}", gaussian.max_amplitude());
40
41    // DRAG pulse
42    let drag = Waveform::drag(0.5, 10.0, 0.1, 40.0, sample_rate);
43    println!("\nDRAG pulse:");
44    println!("  Beta: 0.1");
45    println!(
46        "  Has imaginary component: {}",
47        drag.samples.iter().any(|s| s.im.abs() > 1e-10)
48    );
49
50    // Square pulse
51    let square = Waveform::square(0.3, 20.0, sample_rate);
52    println!("\nSquare pulse:");
53    println!("  Amplitude: 0.3");
54    println!("  Duration: {} ns", square.duration);
55
56    // Modulated pulse
57    let mut modulated = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
58    modulated.modulate(0.1, PI / 4.0); // 100 MHz modulation
59    println!("\nModulated Gaussian:");
60    println!("  Modulation frequency: 100 MHz");
61    println!("  Phase: π/4");
62
63    println!();
64    Ok(())
65}
66
67fn demo_pulse_schedules() -> quantrs2_core::error::QuantRS2Result<()> {
68    println!("--- Pulse Schedule Construction ---");
69
70    let sample_rate = 1.0;
71    let mut schedule = PulseSchedule::new();
72
73    // Create waveforms
74    let pi_pulse = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
75    let pi2_pulse = Waveform::gaussian(0.25, 10.0, 40.0, sample_rate);
76    let cr_pulse = Waveform::square(0.1, 200.0, sample_rate);
77
78    // Build schedule for a simple circuit
79    let mut time = 0.0;
80
81    // X gate on qubit 0
82    schedule.add_instruction(
83        time,
84        PulseInstruction::Play {
85            waveform: pi_pulse.clone(),
86            channel: Channel::Drive(0),
87            phase: 0.0,
88        },
89    );
90    time += 40.0;
91
92    // Delay
93    schedule.add_instruction(
94        time,
95        PulseInstruction::Delay {
96            duration: 20.0,
97            channels: vec![Channel::Drive(0), Channel::Drive(1)],
98        },
99    );
100    time += 20.0;
101
102    // CNOT using cross-resonance
103    schedule.add_instruction(
104        time,
105        PulseInstruction::Play {
106            waveform: cr_pulse,
107            channel: Channel::Control(0, 1),
108            phase: 0.0,
109        },
110    );
111
112    // Echo pulse on target
113    schedule.add_instruction(
114        time + 100.0,
115        PulseInstruction::Play {
116            waveform: pi_pulse.clone(),
117            channel: Channel::Drive(1),
118            phase: PI,
119        },
120    );
121    time += 200.0;
122
123    // Measurement
124    schedule.add_instruction(
125        time,
126        PulseInstruction::Acquire {
127            duration: 1000.0,
128            channel: Channel::Measure(0),
129            memory_slot: 0,
130        },
131    );
132
133    println!("Built pulse schedule:");
134    println!("  Total duration: {} ns", schedule.duration);
135    println!("  Instructions: {}", schedule.instructions.len());
136    println!("  Channels used: {}", schedule.channels.len());
137
138    println!("\nSchedule timeline:");
139    for (time, instruction) in &schedule.instructions {
140        match instruction {
141            PulseInstruction::Play { channel, .. } => {
142                println!("  {:6.1} ns: Play on {:?}", time, channel);
143            }
144            PulseInstruction::Delay { duration, .. } => {
145                println!("  {:6.1} ns: Delay {} ns", time, duration);
146            }
147            PulseInstruction::Acquire { channel, .. } => {
148                println!("  {:6.1} ns: Acquire on {:?}", time, channel);
149            }
150            _ => {}
151        }
152    }
153
154    println!();
155    Ok(())
156}
Source

pub fn modulate(&mut self, frequency: f64, phase: f64)

Apply frequency modulation

Examples found in repository?
examples/pulse_demo.rs (line 58)
27fn demo_pulse_waveforms() -> quantrs2_core::error::QuantRS2Result<()> {
28    println!("--- Pulse Waveform Types ---");
29
30    let sample_rate = 1.0; // 1 GS/s
31
32    // Gaussian pulse
33    let gaussian = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
34    println!("Gaussian pulse:");
35    println!("  Amplitude: 0.5");
36    println!("  Sigma: 10.0 ns");
37    println!("  Duration: {} ns", gaussian.duration);
38    println!("  Samples: {}", gaussian.samples.len());
39    println!("  Max amplitude: {:.4}", gaussian.max_amplitude());
40
41    // DRAG pulse
42    let drag = Waveform::drag(0.5, 10.0, 0.1, 40.0, sample_rate);
43    println!("\nDRAG pulse:");
44    println!("  Beta: 0.1");
45    println!(
46        "  Has imaginary component: {}",
47        drag.samples.iter().any(|s| s.im.abs() > 1e-10)
48    );
49
50    // Square pulse
51    let square = Waveform::square(0.3, 20.0, sample_rate);
52    println!("\nSquare pulse:");
53    println!("  Amplitude: 0.3");
54    println!("  Duration: {} ns", square.duration);
55
56    // Modulated pulse
57    let mut modulated = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
58    modulated.modulate(0.1, PI / 4.0); // 100 MHz modulation
59    println!("\nModulated Gaussian:");
60    println!("  Modulation frequency: 100 MHz");
61    println!("  Phase: π/4");
62
63    println!();
64    Ok(())
65}
Source

pub fn scale(&mut self, factor: f64)

Scale amplitude

Source

pub fn max_amplitude(&self) -> f64

Get maximum amplitude

Examples found in repository?
examples/pulse_demo.rs (line 39)
27fn demo_pulse_waveforms() -> quantrs2_core::error::QuantRS2Result<()> {
28    println!("--- Pulse Waveform Types ---");
29
30    let sample_rate = 1.0; // 1 GS/s
31
32    // Gaussian pulse
33    let gaussian = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
34    println!("Gaussian pulse:");
35    println!("  Amplitude: 0.5");
36    println!("  Sigma: 10.0 ns");
37    println!("  Duration: {} ns", gaussian.duration);
38    println!("  Samples: {}", gaussian.samples.len());
39    println!("  Max amplitude: {:.4}", gaussian.max_amplitude());
40
41    // DRAG pulse
42    let drag = Waveform::drag(0.5, 10.0, 0.1, 40.0, sample_rate);
43    println!("\nDRAG pulse:");
44    println!("  Beta: 0.1");
45    println!(
46        "  Has imaginary component: {}",
47        drag.samples.iter().any(|s| s.im.abs() > 1e-10)
48    );
49
50    // Square pulse
51    let square = Waveform::square(0.3, 20.0, sample_rate);
52    println!("\nSquare pulse:");
53    println!("  Amplitude: 0.3");
54    println!("  Duration: {} ns", square.duration);
55
56    // Modulated pulse
57    let mut modulated = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
58    modulated.modulate(0.1, PI / 4.0); // 100 MHz modulation
59    println!("\nModulated Gaussian:");
60    println!("  Modulation frequency: 100 MHz");
61    println!("  Phase: π/4");
62
63    println!();
64    Ok(())
65}
66
67fn demo_pulse_schedules() -> quantrs2_core::error::QuantRS2Result<()> {
68    println!("--- Pulse Schedule Construction ---");
69
70    let sample_rate = 1.0;
71    let mut schedule = PulseSchedule::new();
72
73    // Create waveforms
74    let pi_pulse = Waveform::gaussian(0.5, 10.0, 40.0, sample_rate);
75    let pi2_pulse = Waveform::gaussian(0.25, 10.0, 40.0, sample_rate);
76    let cr_pulse = Waveform::square(0.1, 200.0, sample_rate);
77
78    // Build schedule for a simple circuit
79    let mut time = 0.0;
80
81    // X gate on qubit 0
82    schedule.add_instruction(
83        time,
84        PulseInstruction::Play {
85            waveform: pi_pulse.clone(),
86            channel: Channel::Drive(0),
87            phase: 0.0,
88        },
89    );
90    time += 40.0;
91
92    // Delay
93    schedule.add_instruction(
94        time,
95        PulseInstruction::Delay {
96            duration: 20.0,
97            channels: vec![Channel::Drive(0), Channel::Drive(1)],
98        },
99    );
100    time += 20.0;
101
102    // CNOT using cross-resonance
103    schedule.add_instruction(
104        time,
105        PulseInstruction::Play {
106            waveform: cr_pulse,
107            channel: Channel::Control(0, 1),
108            phase: 0.0,
109        },
110    );
111
112    // Echo pulse on target
113    schedule.add_instruction(
114        time + 100.0,
115        PulseInstruction::Play {
116            waveform: pi_pulse.clone(),
117            channel: Channel::Drive(1),
118            phase: PI,
119        },
120    );
121    time += 200.0;
122
123    // Measurement
124    schedule.add_instruction(
125        time,
126        PulseInstruction::Acquire {
127            duration: 1000.0,
128            channel: Channel::Measure(0),
129            memory_slot: 0,
130        },
131    );
132
133    println!("Built pulse schedule:");
134    println!("  Total duration: {} ns", schedule.duration);
135    println!("  Instructions: {}", schedule.instructions.len());
136    println!("  Channels used: {}", schedule.channels.len());
137
138    println!("\nSchedule timeline:");
139    for (time, instruction) in &schedule.instructions {
140        match instruction {
141            PulseInstruction::Play { channel, .. } => {
142                println!("  {:6.1} ns: Play on {:?}", time, channel);
143            }
144            PulseInstruction::Delay { duration, .. } => {
145                println!("  {:6.1} ns: Delay {} ns", time, duration);
146            }
147            PulseInstruction::Acquire { channel, .. } => {
148                println!("  {:6.1} ns: Acquire on {:?}", time, channel);
149            }
150            _ => {}
151        }
152    }
153
154    println!();
155    Ok(())
156}
157
158fn demo_pulse_compilation() -> quantrs2_core::error::QuantRS2Result<()> {
159    println!("--- Circuit to Pulse Compilation ---");
160
161    // Create device configuration
162    let device_config = DeviceConfig::default_config(4);
163    println!("Device configuration:");
164    println!("  Qubits: 4");
165    println!("  Qubit frequencies: ~5 GHz");
166    println!("  Sample rate: {} GS/s", device_config.sample_rate);
167
168    // Create compiler
169    let compiler = PulseCompiler::new(device_config);
170
171    // Create a simple circuit
172    let mut circuit = Circuit::<4>::new();
173    circuit.add_gate(Hadamard { target: QubitId(0) })?;
174    circuit.add_gate(CNOT {
175        control: QubitId(0),
176        target: QubitId(1),
177    })?;
178    circuit.add_gate(RotationZ {
179        target: QubitId(1),
180        theta: PI / 4.0,
181    })?;
182
183    println!("\nCompiling circuit:");
184    for (i, gate) in circuit.gates().iter().enumerate() {
185        println!("  {}: {}", i, gate.name());
186    }
187
188    // Compile to pulses
189    let pulse_schedule = compiler.compile(&circuit)?;
190
191    println!("\nCompiled pulse schedule:");
192    println!("  Duration: {} ns", pulse_schedule.duration);
193    println!("  Instructions: {}", pulse_schedule.instructions.len());
194
195    // Show channel usage
196    let mut channel_usage = std::collections::HashMap::new();
197    for (_, instruction) in &pulse_schedule.instructions {
198        match instruction {
199            PulseInstruction::Play { channel, .. } => {
200                *channel_usage.entry(format!("{:?}", channel)).or_insert(0) += 1;
201            }
202            _ => {}
203        }
204    }
205
206    println!("\nChannel usage:");
207    for (channel, count) in channel_usage {
208        println!("  {}: {} pulses", channel, count);
209    }
210
211    println!();
212    Ok(())
213}
214
215fn demo_pulse_calibration() -> quantrs2_core::error::QuantRS2Result<()> {
216    println!("--- Pulse Calibration ---");
217
218    let sample_rate = 1.0;
219
220    // Create calibrations for different rotation angles
221    let angles = vec![PI / 4.0, PI / 2.0, PI, 3.0 * PI / 2.0];
222    let mut calibrations = Vec::new();
223
224    for &angle in &angles {
225        // Calculate pulse amplitude for rotation
226        let amplitude = angle / (2.0 * PI) * 0.5; // Simplified
227        let waveform = Waveform::gaussian(amplitude, 10.0, 40.0, sample_rate);
228
229        let mut schedule = PulseSchedule::new();
230        schedule.add_instruction(
231            0.0,
232            PulseInstruction::Play {
233                waveform,
234                channel: Channel::Drive(0),
235                phase: 0.0,
236            },
237        );
238
239        let mut parameters = std::collections::HashMap::new();
240        parameters.insert("theta".to_string(), angle);
241
242        calibrations.push(PulseCalibration {
243            gate_name: "RZ".to_string(),
244            qubits: vec![QubitId(0)],
245            parameters,
246            schedule,
247        });
248    }
249
250    println!("Created {} calibrations for RZ gate", calibrations.len());
251
252    for calib in &calibrations {
253        let theta = calib.parameters.get("theta").unwrap();
254        println!(
255            "  RZ(θ={:.3}): duration = {} ns",
256            theta, calib.schedule.duration
257        );
258    }
259
260    // Demonstrate calibration interpolation
261    println!("\nCalibration interpolation:");
262    let target_angle = PI / 3.0;
263    println!("  Target angle: π/3");
264    println!("  Would interpolate between π/4 and π/2 calibrations");
265
266    println!();
267    Ok(())
268}
269
270fn demo_pulse_optimization() -> quantrs2_core::error::QuantRS2Result<()> {
271    println!("--- Pulse Optimization ---");
272
273    let sample_rate = 1.0;
274    let optimizer = PulseOptimizer::new();
275
276    // Create initial pulse
277    let mut pulse = Waveform::gaussian(0.5, 15.0, 60.0, sample_rate);
278    println!("Initial pulse:");
279    println!("  Type: Gaussian");
280    println!("  Duration: {} ns", pulse.duration);
281    println!("  Max amplitude: {:.4}", pulse.max_amplitude());
282
283    // Apply DRAG correction
284    optimizer.apply_drag_correction(&mut pulse, 0.1)?;
285    println!("\nAfter DRAG correction:");
286    println!(
287        "  Has imaginary component: {}",
288        pulse.samples.iter().any(|s| s.im.abs() > 1e-10)
289    );
290
291    // Create a pulse schedule to optimize
292    let mut schedule = PulseSchedule::new();
293
294    // Add multiple pulses
295    for i in 0..3 {
296        let waveform = Waveform::gaussian(0.4, 12.0, 48.0, sample_rate);
297        schedule.add_instruction(
298            i as f64 * 60.0,
299            PulseInstruction::Play {
300                waveform,
301                channel: Channel::Drive(i),
302                phase: 0.0,
303            },
304        );
305    }
306
307    println!("\nSchedule optimization:");
308    println!("  Original duration: {} ns", schedule.duration);
309
310    // Optimize (placeholder - would do actual optimization)
311    optimizer.optimize(&mut schedule)?;
312
313    println!(
314        "  Optimized duration: {} ns (placeholder)",
315        schedule.duration
316    );
317    println!("  Target fidelity: 0.999"); // Placeholder since field is private
318
319    // Demonstrate pulse shaping techniques
320    println!("\nPulse shaping techniques:");
321    println!("  - Gaussian: Smooth envelope, reduced frequency spread");
322    println!("  - DRAG: Reduces leakage to higher levels");
323    println!("  - Cosine: Smooth turn-on/off");
324    println!("  - GRAPE: Optimal control for specific unitaries");
325
326    println!();
327    Ok(())
328}

Trait Implementations§

Source§

impl Clone for Waveform

Source§

fn clone(&self) -> Waveform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Waveform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Waveform

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Waveform

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Ungil for T
where T: Send,