NoiseModel

Struct NoiseModel 

Source
pub struct NoiseModel {
    pub single_qubit_errors: HashMap<usize, f64>,
    pub two_qubit_errors: HashMap<(usize, usize), f64>,
    pub t1_times: HashMap<usize, f64>,
    pub t2_times: HashMap<usize, f64>,
    pub readout_fidelities: HashMap<usize, f64>,
    pub gate_times: HashMap<String, f64>,
    pub crosstalk_matrix: Option<Vec<Vec<f64>>>,
}
Expand description

Noise model for quantum devices

Fields§

§single_qubit_errors: HashMap<usize, f64>

Single-qubit gate error rates (per qubit)

§two_qubit_errors: HashMap<(usize, usize), f64>

Two-qubit gate error rates (per qubit pair)

§t1_times: HashMap<usize, f64>

T1 coherence times (microseconds)

§t2_times: HashMap<usize, f64>

T2 coherence times (microseconds)

§readout_fidelities: HashMap<usize, f64>

Readout fidelities

§gate_times: HashMap<String, f64>

Gate execution times (nanoseconds)

§crosstalk_matrix: Option<Vec<Vec<f64>>>

Crosstalk matrix

Implementations§

Source§

impl NoiseModel

Source

pub fn new() -> Self

Create a new empty noise model

Examples found in repository?
examples/noise_optimization_demo.rs (line 197)
186fn demo_fidelity_comparison() -> quantrs2_core::error::QuantRS2Result<()> {
187    println!("--- Fidelity Comparison Across Noise Models ---");
188
189    // Create circuits of different complexity
190    let circuits = vec![
191        create_simple_circuit()?,
192        create_medium_circuit()?,
193        create_complex_circuit()?,
194    ];
195
196    let noise_models = vec![
197        ("Ideal", NoiseModel::new()),
198        ("Uniform", NoiseModel::uniform(4)),
199        ("IBM-like", NoiseModel::ibm_like(4)),
200    ];
201
202    println!(
203        "{:<12} {:<8} {:<8} {:<8}",
204        "Circuit", "Ideal", "Uniform", "IBM-like"
205    );
206    println!("{:-<40}", "");
207
208    for (i, circuit) in circuits.iter().enumerate() {
209        let circuit_name = match i {
210            0 => "Simple",
211            1 => "Medium",
212            2 => "Complex",
213            _ => "Unknown",
214        };
215
216        print!("{:<12}", circuit_name);
217
218        for (_, noise_model) in &noise_models {
219            let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
220            let fidelity = optimizer.estimate_fidelity(circuit);
221            print!(" {:<8.4}", fidelity);
222        }
223        println!();
224    }
225
226    println!();
227    Ok(())
228}
Source

pub fn uniform(num_qubits: usize) -> Self

Create a uniform noise model for testing

Examples found in repository?
examples/noise_optimization_demo.rs (line 47)
44fn demo_uniform_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
45    println!("--- Uniform Noise Model ---");
46
47    let noise_model = NoiseModel::uniform(4);
48    let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
49
50    println!("Noise characteristics:");
51    println!(
52        "  Single-qubit error rate: {:.2e}",
53        noise_model.single_qubit_error(0)
54    );
55    println!(
56        "  Two-qubit error rate: {:.2e}",
57        noise_model.two_qubit_error(0, 1)
58    );
59    println!("  T1 time: {:.1} μs", noise_model.t1_time(0));
60    println!("  T2 time: {:.1} μs", noise_model.t2_time(0));
61    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
62
63    let original_fidelity = optimizer.estimate_fidelity(circuit);
64    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
65
66    let optimized = optimizer.optimize(circuit)?;
67    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
68    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
69
70    if optimized_fidelity > original_fidelity {
71        println!(
72            "✓ Fidelity improved by {:.4}",
73            optimized_fidelity - original_fidelity
74        );
75    } else {
76        println!("→ No fidelity improvement (circuit already optimal)");
77    }
78
79    println!();
80    Ok(())
81}
82
83fn demo_ibm_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
84    println!("--- IBM-like Noise Model ---");
85
86    let noise_model = NoiseModel::ibm_like(4);
87    let coupling_map = CouplingMap::linear(4);
88    let optimizer = NoiseAwareOptimizer::new(noise_model.clone()).with_coupling_map(coupling_map);
89
90    println!("IBM-like noise characteristics:");
91    println!(
92        "  Single-qubit error rate: {:.2e}",
93        noise_model.single_qubit_error(0)
94    );
95    println!(
96        "  Two-qubit error rate (adjacent): {:.2e}",
97        noise_model.two_qubit_error(0, 1)
98    );
99    println!("  Hadamard gate time: {:.1} ns", noise_model.gate_time("H"));
100    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
101
102    let original_fidelity = optimizer.estimate_fidelity(circuit);
103    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
104
105    let optimized = optimizer.optimize(circuit)?;
106    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
107    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
108
109    println!("Available optimization passes:");
110    for pass in optimizer.get_passes() {
111        println!("  - {}", pass.name());
112    }
113
114    println!();
115    Ok(())
116}
117
118fn demo_noise_aware_cost_model(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
119    println!("--- Noise-Aware Cost Analysis ---");
120
121    let uniform_noise = NoiseModel::uniform(4);
122    let ibm_noise = NoiseModel::ibm_like(4);
123
124    let uniform_cost_model = NoiseAwareCostModel::new(uniform_noise);
125    let ibm_cost_model = NoiseAwareCostModel::new(ibm_noise);
126
127    let uniform_cost = uniform_cost_model.circuit_cost(circuit);
128    let ibm_cost = ibm_cost_model.circuit_cost(circuit);
129
130    println!("Circuit costs with different noise models:");
131    println!("  Uniform noise model: {:.2}", uniform_cost);
132    println!("  IBM-like noise model: {:.2}", ibm_cost);
133
134    // Analyze individual gate costs
135    println!("\nGate-by-gate cost analysis (IBM model):");
136    for (i, gate) in circuit.gates().iter().enumerate() {
137        let gate_cost = ibm_cost_model.gate_cost(gate.as_ref());
138        println!("  Gate {}: {} - Cost: {:.2}", i, gate.name(), gate_cost);
139    }
140
141    println!();
142    Ok(())
143}
144
145fn demo_noise_optimization_passes(
146    circuit: &Circuit<4>,
147) -> quantrs2_core::error::QuantRS2Result<()> {
148    println!("--- Individual Optimization Passes ---");
149
150    let noise_model = NoiseModel::ibm_like(4);
151    let coupling_map = CouplingMap::linear(4);
152
153    // Test coherence optimization
154    let coherence_opt = CoherenceOptimization::new(noise_model.clone());
155    let cost_model = NoiseAwareCostModel::new(noise_model.clone());
156
157    if coherence_opt.should_apply() {
158        let coherence_result = coherence_opt.apply(circuit, &cost_model)?;
159        println!("✓ Coherence optimization applied");
160        println!("  Original gates: {}", circuit.num_gates());
161        println!("  After coherence opt: {}", coherence_result.num_gates());
162    }
163
164    // Test noise-aware mapping
165    let mapping_opt = NoiseAwareMapping::new(noise_model.clone(), coupling_map.clone());
166    if mapping_opt.should_apply() {
167        let mapping_result = mapping_opt.apply(circuit, &cost_model)?;
168        println!("✓ Noise-aware mapping applied");
169        println!("  Original gates: {}", circuit.num_gates());
170        println!("  After mapping opt: {}", mapping_result.num_gates());
171    }
172
173    // Test dynamical decoupling
174    let dd_opt = DynamicalDecoupling::new(noise_model.clone());
175    if dd_opt.should_apply() {
176        let dd_result = dd_opt.apply(circuit, &cost_model)?;
177        println!("✓ Dynamical decoupling applied");
178        println!("  Original gates: {}", circuit.num_gates());
179        println!("  After DD insertion: {}", dd_result.num_gates());
180    }
181
182    println!();
183    Ok(())
184}
185
186fn demo_fidelity_comparison() -> quantrs2_core::error::QuantRS2Result<()> {
187    println!("--- Fidelity Comparison Across Noise Models ---");
188
189    // Create circuits of different complexity
190    let circuits = vec![
191        create_simple_circuit()?,
192        create_medium_circuit()?,
193        create_complex_circuit()?,
194    ];
195
196    let noise_models = vec![
197        ("Ideal", NoiseModel::new()),
198        ("Uniform", NoiseModel::uniform(4)),
199        ("IBM-like", NoiseModel::ibm_like(4)),
200    ];
201
202    println!(
203        "{:<12} {:<8} {:<8} {:<8}",
204        "Circuit", "Ideal", "Uniform", "IBM-like"
205    );
206    println!("{:-<40}", "");
207
208    for (i, circuit) in circuits.iter().enumerate() {
209        let circuit_name = match i {
210            0 => "Simple",
211            1 => "Medium",
212            2 => "Complex",
213            _ => "Unknown",
214        };
215
216        print!("{:<12}", circuit_name);
217
218        for (_, noise_model) in &noise_models {
219            let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
220            let fidelity = optimizer.estimate_fidelity(circuit);
221            print!(" {:<8.4}", fidelity);
222        }
223        println!();
224    }
225
226    println!();
227    Ok(())
228}
Source

pub fn ibm_like(num_qubits: usize) -> Self

Create a realistic noise model based on IBM devices

Examples found in repository?
examples/noise_optimization_demo.rs (line 86)
83fn demo_ibm_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
84    println!("--- IBM-like Noise Model ---");
85
86    let noise_model = NoiseModel::ibm_like(4);
87    let coupling_map = CouplingMap::linear(4);
88    let optimizer = NoiseAwareOptimizer::new(noise_model.clone()).with_coupling_map(coupling_map);
89
90    println!("IBM-like noise characteristics:");
91    println!(
92        "  Single-qubit error rate: {:.2e}",
93        noise_model.single_qubit_error(0)
94    );
95    println!(
96        "  Two-qubit error rate (adjacent): {:.2e}",
97        noise_model.two_qubit_error(0, 1)
98    );
99    println!("  Hadamard gate time: {:.1} ns", noise_model.gate_time("H"));
100    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
101
102    let original_fidelity = optimizer.estimate_fidelity(circuit);
103    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
104
105    let optimized = optimizer.optimize(circuit)?;
106    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
107    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
108
109    println!("Available optimization passes:");
110    for pass in optimizer.get_passes() {
111        println!("  - {}", pass.name());
112    }
113
114    println!();
115    Ok(())
116}
117
118fn demo_noise_aware_cost_model(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
119    println!("--- Noise-Aware Cost Analysis ---");
120
121    let uniform_noise = NoiseModel::uniform(4);
122    let ibm_noise = NoiseModel::ibm_like(4);
123
124    let uniform_cost_model = NoiseAwareCostModel::new(uniform_noise);
125    let ibm_cost_model = NoiseAwareCostModel::new(ibm_noise);
126
127    let uniform_cost = uniform_cost_model.circuit_cost(circuit);
128    let ibm_cost = ibm_cost_model.circuit_cost(circuit);
129
130    println!("Circuit costs with different noise models:");
131    println!("  Uniform noise model: {:.2}", uniform_cost);
132    println!("  IBM-like noise model: {:.2}", ibm_cost);
133
134    // Analyze individual gate costs
135    println!("\nGate-by-gate cost analysis (IBM model):");
136    for (i, gate) in circuit.gates().iter().enumerate() {
137        let gate_cost = ibm_cost_model.gate_cost(gate.as_ref());
138        println!("  Gate {}: {} - Cost: {:.2}", i, gate.name(), gate_cost);
139    }
140
141    println!();
142    Ok(())
143}
144
145fn demo_noise_optimization_passes(
146    circuit: &Circuit<4>,
147) -> quantrs2_core::error::QuantRS2Result<()> {
148    println!("--- Individual Optimization Passes ---");
149
150    let noise_model = NoiseModel::ibm_like(4);
151    let coupling_map = CouplingMap::linear(4);
152
153    // Test coherence optimization
154    let coherence_opt = CoherenceOptimization::new(noise_model.clone());
155    let cost_model = NoiseAwareCostModel::new(noise_model.clone());
156
157    if coherence_opt.should_apply() {
158        let coherence_result = coherence_opt.apply(circuit, &cost_model)?;
159        println!("✓ Coherence optimization applied");
160        println!("  Original gates: {}", circuit.num_gates());
161        println!("  After coherence opt: {}", coherence_result.num_gates());
162    }
163
164    // Test noise-aware mapping
165    let mapping_opt = NoiseAwareMapping::new(noise_model.clone(), coupling_map.clone());
166    if mapping_opt.should_apply() {
167        let mapping_result = mapping_opt.apply(circuit, &cost_model)?;
168        println!("✓ Noise-aware mapping applied");
169        println!("  Original gates: {}", circuit.num_gates());
170        println!("  After mapping opt: {}", mapping_result.num_gates());
171    }
172
173    // Test dynamical decoupling
174    let dd_opt = DynamicalDecoupling::new(noise_model.clone());
175    if dd_opt.should_apply() {
176        let dd_result = dd_opt.apply(circuit, &cost_model)?;
177        println!("✓ Dynamical decoupling applied");
178        println!("  Original gates: {}", circuit.num_gates());
179        println!("  After DD insertion: {}", dd_result.num_gates());
180    }
181
182    println!();
183    Ok(())
184}
185
186fn demo_fidelity_comparison() -> quantrs2_core::error::QuantRS2Result<()> {
187    println!("--- Fidelity Comparison Across Noise Models ---");
188
189    // Create circuits of different complexity
190    let circuits = vec![
191        create_simple_circuit()?,
192        create_medium_circuit()?,
193        create_complex_circuit()?,
194    ];
195
196    let noise_models = vec![
197        ("Ideal", NoiseModel::new()),
198        ("Uniform", NoiseModel::uniform(4)),
199        ("IBM-like", NoiseModel::ibm_like(4)),
200    ];
201
202    println!(
203        "{:<12} {:<8} {:<8} {:<8}",
204        "Circuit", "Ideal", "Uniform", "IBM-like"
205    );
206    println!("{:-<40}", "");
207
208    for (i, circuit) in circuits.iter().enumerate() {
209        let circuit_name = match i {
210            0 => "Simple",
211            1 => "Medium",
212            2 => "Complex",
213            _ => "Unknown",
214        };
215
216        print!("{:<12}", circuit_name);
217
218        for (_, noise_model) in &noise_models {
219            let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
220            let fidelity = optimizer.estimate_fidelity(circuit);
221            print!(" {:<8.4}", fidelity);
222        }
223        println!();
224    }
225
226    println!();
227    Ok(())
228}
Source

pub fn single_qubit_error(&self, qubit: usize) -> f64

Get error rate for a single-qubit gate

Examples found in repository?
examples/noise_optimization_demo.rs (line 53)
44fn demo_uniform_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
45    println!("--- Uniform Noise Model ---");
46
47    let noise_model = NoiseModel::uniform(4);
48    let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
49
50    println!("Noise characteristics:");
51    println!(
52        "  Single-qubit error rate: {:.2e}",
53        noise_model.single_qubit_error(0)
54    );
55    println!(
56        "  Two-qubit error rate: {:.2e}",
57        noise_model.two_qubit_error(0, 1)
58    );
59    println!("  T1 time: {:.1} μs", noise_model.t1_time(0));
60    println!("  T2 time: {:.1} μs", noise_model.t2_time(0));
61    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
62
63    let original_fidelity = optimizer.estimate_fidelity(circuit);
64    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
65
66    let optimized = optimizer.optimize(circuit)?;
67    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
68    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
69
70    if optimized_fidelity > original_fidelity {
71        println!(
72            "✓ Fidelity improved by {:.4}",
73            optimized_fidelity - original_fidelity
74        );
75    } else {
76        println!("→ No fidelity improvement (circuit already optimal)");
77    }
78
79    println!();
80    Ok(())
81}
82
83fn demo_ibm_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
84    println!("--- IBM-like Noise Model ---");
85
86    let noise_model = NoiseModel::ibm_like(4);
87    let coupling_map = CouplingMap::linear(4);
88    let optimizer = NoiseAwareOptimizer::new(noise_model.clone()).with_coupling_map(coupling_map);
89
90    println!("IBM-like noise characteristics:");
91    println!(
92        "  Single-qubit error rate: {:.2e}",
93        noise_model.single_qubit_error(0)
94    );
95    println!(
96        "  Two-qubit error rate (adjacent): {:.2e}",
97        noise_model.two_qubit_error(0, 1)
98    );
99    println!("  Hadamard gate time: {:.1} ns", noise_model.gate_time("H"));
100    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
101
102    let original_fidelity = optimizer.estimate_fidelity(circuit);
103    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
104
105    let optimized = optimizer.optimize(circuit)?;
106    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
107    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
108
109    println!("Available optimization passes:");
110    for pass in optimizer.get_passes() {
111        println!("  - {}", pass.name());
112    }
113
114    println!();
115    Ok(())
116}
Source

pub fn two_qubit_error(&self, q1: usize, q2: usize) -> f64

Get error rate for a two-qubit gate

Examples found in repository?
examples/noise_optimization_demo.rs (line 57)
44fn demo_uniform_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
45    println!("--- Uniform Noise Model ---");
46
47    let noise_model = NoiseModel::uniform(4);
48    let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
49
50    println!("Noise characteristics:");
51    println!(
52        "  Single-qubit error rate: {:.2e}",
53        noise_model.single_qubit_error(0)
54    );
55    println!(
56        "  Two-qubit error rate: {:.2e}",
57        noise_model.two_qubit_error(0, 1)
58    );
59    println!("  T1 time: {:.1} μs", noise_model.t1_time(0));
60    println!("  T2 time: {:.1} μs", noise_model.t2_time(0));
61    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
62
63    let original_fidelity = optimizer.estimate_fidelity(circuit);
64    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
65
66    let optimized = optimizer.optimize(circuit)?;
67    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
68    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
69
70    if optimized_fidelity > original_fidelity {
71        println!(
72            "✓ Fidelity improved by {:.4}",
73            optimized_fidelity - original_fidelity
74        );
75    } else {
76        println!("→ No fidelity improvement (circuit already optimal)");
77    }
78
79    println!();
80    Ok(())
81}
82
83fn demo_ibm_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
84    println!("--- IBM-like Noise Model ---");
85
86    let noise_model = NoiseModel::ibm_like(4);
87    let coupling_map = CouplingMap::linear(4);
88    let optimizer = NoiseAwareOptimizer::new(noise_model.clone()).with_coupling_map(coupling_map);
89
90    println!("IBM-like noise characteristics:");
91    println!(
92        "  Single-qubit error rate: {:.2e}",
93        noise_model.single_qubit_error(0)
94    );
95    println!(
96        "  Two-qubit error rate (adjacent): {:.2e}",
97        noise_model.two_qubit_error(0, 1)
98    );
99    println!("  Hadamard gate time: {:.1} ns", noise_model.gate_time("H"));
100    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
101
102    let original_fidelity = optimizer.estimate_fidelity(circuit);
103    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
104
105    let optimized = optimizer.optimize(circuit)?;
106    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
107    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
108
109    println!("Available optimization passes:");
110    for pass in optimizer.get_passes() {
111        println!("  - {}", pass.name());
112    }
113
114    println!();
115    Ok(())
116}
Source

pub fn t1_time(&self, qubit: usize) -> f64

Get T1 time for a qubit

Examples found in repository?
examples/noise_optimization_demo.rs (line 59)
44fn demo_uniform_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
45    println!("--- Uniform Noise Model ---");
46
47    let noise_model = NoiseModel::uniform(4);
48    let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
49
50    println!("Noise characteristics:");
51    println!(
52        "  Single-qubit error rate: {:.2e}",
53        noise_model.single_qubit_error(0)
54    );
55    println!(
56        "  Two-qubit error rate: {:.2e}",
57        noise_model.two_qubit_error(0, 1)
58    );
59    println!("  T1 time: {:.1} μs", noise_model.t1_time(0));
60    println!("  T2 time: {:.1} μs", noise_model.t2_time(0));
61    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
62
63    let original_fidelity = optimizer.estimate_fidelity(circuit);
64    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
65
66    let optimized = optimizer.optimize(circuit)?;
67    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
68    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
69
70    if optimized_fidelity > original_fidelity {
71        println!(
72            "✓ Fidelity improved by {:.4}",
73            optimized_fidelity - original_fidelity
74        );
75    } else {
76        println!("→ No fidelity improvement (circuit already optimal)");
77    }
78
79    println!();
80    Ok(())
81}
Source

pub fn t2_time(&self, qubit: usize) -> f64

Get T2 time for a qubit

Examples found in repository?
examples/noise_optimization_demo.rs (line 60)
44fn demo_uniform_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
45    println!("--- Uniform Noise Model ---");
46
47    let noise_model = NoiseModel::uniform(4);
48    let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
49
50    println!("Noise characteristics:");
51    println!(
52        "  Single-qubit error rate: {:.2e}",
53        noise_model.single_qubit_error(0)
54    );
55    println!(
56        "  Two-qubit error rate: {:.2e}",
57        noise_model.two_qubit_error(0, 1)
58    );
59    println!("  T1 time: {:.1} μs", noise_model.t1_time(0));
60    println!("  T2 time: {:.1} μs", noise_model.t2_time(0));
61    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
62
63    let original_fidelity = optimizer.estimate_fidelity(circuit);
64    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
65
66    let optimized = optimizer.optimize(circuit)?;
67    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
68    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
69
70    if optimized_fidelity > original_fidelity {
71        println!(
72            "✓ Fidelity improved by {:.4}",
73            optimized_fidelity - original_fidelity
74        );
75    } else {
76        println!("→ No fidelity improvement (circuit already optimal)");
77    }
78
79    println!();
80    Ok(())
81}
Source

pub fn gate_time(&self, gate_name: &str) -> f64

Get gate execution time

Examples found in repository?
examples/noise_optimization_demo.rs (line 61)
44fn demo_uniform_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
45    println!("--- Uniform Noise Model ---");
46
47    let noise_model = NoiseModel::uniform(4);
48    let optimizer = NoiseAwareOptimizer::new(noise_model.clone());
49
50    println!("Noise characteristics:");
51    println!(
52        "  Single-qubit error rate: {:.2e}",
53        noise_model.single_qubit_error(0)
54    );
55    println!(
56        "  Two-qubit error rate: {:.2e}",
57        noise_model.two_qubit_error(0, 1)
58    );
59    println!("  T1 time: {:.1} μs", noise_model.t1_time(0));
60    println!("  T2 time: {:.1} μs", noise_model.t2_time(0));
61    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
62
63    let original_fidelity = optimizer.estimate_fidelity(circuit);
64    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
65
66    let optimized = optimizer.optimize(circuit)?;
67    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
68    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
69
70    if optimized_fidelity > original_fidelity {
71        println!(
72            "✓ Fidelity improved by {:.4}",
73            optimized_fidelity - original_fidelity
74        );
75    } else {
76        println!("→ No fidelity improvement (circuit already optimal)");
77    }
78
79    println!();
80    Ok(())
81}
82
83fn demo_ibm_noise(circuit: &Circuit<4>) -> quantrs2_core::error::QuantRS2Result<()> {
84    println!("--- IBM-like Noise Model ---");
85
86    let noise_model = NoiseModel::ibm_like(4);
87    let coupling_map = CouplingMap::linear(4);
88    let optimizer = NoiseAwareOptimizer::new(noise_model.clone()).with_coupling_map(coupling_map);
89
90    println!("IBM-like noise characteristics:");
91    println!(
92        "  Single-qubit error rate: {:.2e}",
93        noise_model.single_qubit_error(0)
94    );
95    println!(
96        "  Two-qubit error rate (adjacent): {:.2e}",
97        noise_model.two_qubit_error(0, 1)
98    );
99    println!("  Hadamard gate time: {:.1} ns", noise_model.gate_time("H"));
100    println!("  CNOT gate time: {:.1} ns", noise_model.gate_time("CNOT"));
101
102    let original_fidelity = optimizer.estimate_fidelity(circuit);
103    println!("\nOriginal circuit fidelity: {:.4}", original_fidelity);
104
105    let optimized = optimizer.optimize(circuit)?;
106    let optimized_fidelity = optimizer.estimate_fidelity(&optimized);
107    println!("Optimized circuit fidelity: {:.4}", optimized_fidelity);
108
109    println!("Available optimization passes:");
110    for pass in optimizer.get_passes() {
111        println!("  - {}", pass.name());
112    }
113
114    println!();
115    Ok(())
116}
Source

pub fn gate_error_probability(&self, gate: &dyn GateOp) -> f64

Calculate error probability for a gate

Trait Implementations§

Source§

impl Clone for NoiseModel

Source§

fn clone(&self) -> NoiseModel

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 NoiseModel

Source§

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

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

impl Default for NoiseModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for NoiseModel

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 NoiseModel

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,