@@ -101,6 +101,9 @@ pub trait Backend {
101
101
fn qubit_is_zero ( & mut self , _q : usize ) -> bool {
102
102
unimplemented ! ( "qubit_is_zero operation" ) ;
103
103
}
104
+ /// Executes custom intrinsic specified by `_name`.
105
+ /// Returns None if this intrinsic is unknown.
106
+ /// Otherwise returns Some(Result), with the Result from intrinsic.
104
107
fn custom_intrinsic ( & mut self , _name : & str , _arg : Value ) -> Option < Result < Value , String > > {
105
108
None
106
109
}
@@ -137,14 +140,17 @@ impl SparseSim {
137
140
138
141
#[ must_use]
139
142
pub fn new_with_noise ( noise : & PauliNoise ) -> Self {
140
- Self {
141
- sim : QuantumSim :: new ( None ) ,
142
- noise : * noise,
143
- rng : if noise. is_noiseless ( ) {
144
- None
145
- } else {
146
- Some ( StdRng :: from_entropy ( ) )
147
- } ,
143
+ let mut sim = SparseSim :: new ( ) ;
144
+ sim. set_noise ( noise) ;
145
+ sim
146
+ }
147
+
148
+ fn set_noise ( & mut self , noise : & PauliNoise ) {
149
+ self . noise = * noise;
150
+ if noise. is_noiseless ( ) {
151
+ self . rng = None ;
152
+ } else {
153
+ self . rng = Some ( StdRng :: from_entropy ( ) ) ;
148
154
}
149
155
}
150
156
@@ -393,6 +399,26 @@ impl Backend for SparseSim {
393
399
| "AccountForEstimatesInternal"
394
400
| "BeginRepeatEstimatesInternal"
395
401
| "EndRepeatEstimatesInternal" => Some ( Ok ( Value :: unit ( ) ) ) ,
402
+ "ConfigurePauliNoise" => {
403
+ let [ xv, yv, zv] = & * arg. unwrap_tuple ( ) else {
404
+ panic ! ( "tuple arity for ConfigurePauliNoise intrinsic should be 3" ) ;
405
+ } ;
406
+ let px = xv. get_double ( ) ;
407
+ let py = yv. get_double ( ) ;
408
+ let pz = zv. get_double ( ) ;
409
+ match PauliNoise :: from_probabilities ( px, py, pz) {
410
+ Ok ( noise) => {
411
+ self . set_noise ( & noise) ;
412
+ Some ( Ok ( Value :: unit ( ) ) )
413
+ }
414
+ Err ( message) => Some ( Err ( message) ) ,
415
+ }
416
+ }
417
+ "ApplyIdleNoise" => {
418
+ let q = arg. unwrap_qubit ( ) . 0 ;
419
+ self . apply_noise ( q) ;
420
+ Some ( Ok ( Value :: unit ( ) ) )
421
+ }
396
422
_ => None ,
397
423
}
398
424
}
0 commit comments