1- from qiskit import QuantumCircuit , execute , Aer
1+ from qiskit import QuantumCircuit , execute , Aer , transpile
22
33from qiskit .transpiler import PassManager , PassManagerConfig , CouplingMap
44from qiskit .transpiler .passes import Unroller , Optimize1qGates
@@ -165,8 +165,9 @@ def transpile_circuit(self, qc: QuantumCircuit, custom_pass_manager: PassManager
165165
166166 if custom_pass_manager == None :
167167 pass_manager_config = PassManagerConfig (basis_gates = ["id" , "u1" , "u2" , "u3" , "cx" ],
168- coupling_map = CouplingMap (self .backend .configuration ().coupling_map ),
169168 backend_properties = self .backend .properties ())
169+ if not self .backend .configuration ().simulator :
170+ pass_manager_config .coupling_map = CouplingMap (self .backend .configuration ().coupling_map )
170171 pass_manager = level_3_pass_manager (pass_manager_config )
171172 else :
172173 pass_manager = custom_pass_manager
@@ -288,24 +289,21 @@ def mitigate(self, repeats: int = 1, verbose: bool = False) -> float:
288289
289290 if verbose :
290291 print ("shots=" , self .shots , ", n_amp_factors=" , self .n_amp_factors , ", paulitwirl=" , self .pauli_twirl ,
291- " repeats=" , repeats , sep = "" )
292+ ", repeats=" , repeats , sep = "" )
292293 print ("noise amplification factors=" , self .noise_amplification_factors , sep = "" )
293294
294295 if verbose :
295296 print ("Constructing circuits" )
296297
297298 circuits = []
298299
299- for i in range (repeats ):
300+ for j , amp_factor in enumerate (self .noise_amplification_factors ):
301+ circuits .append (self .noise_amplify_and_pauli_twirl_cnots (qc = self .qc , amp_factor = amp_factor ,
302+ pauli_twirl = self .pauli_twirl ))
303+ self .depths [j ] = circuits [- 1 ].depth ()
300304
301- if verbose and ((i + 1 ) % 25 == 0 ):
302- print (i + 1 ,"/" ,repeats )
303-
304- for j , amp_factor in enumerate (self .noise_amplification_factors ):
305- circuits .append (self .noise_amplify_and_pauli_twirl_cnots (qc = self .qc , amp_factor = amp_factor ,
306- pauli_twirl = self .pauli_twirl ))
307- if i == 0 :
308- self .depths [j ] = circuits [- 1 ].depth ()
305+ if repeats != 1 :
306+ circuits = circuits * repeats
309307
310308 if verbose :
311309 print ("Depths=" ,self .depths , sep = "" )
@@ -323,10 +321,15 @@ def mitigate(self, repeats: int = 1, verbose: bool = False) -> float:
323321 self .mitigated_exp_vals = zeros ((repeats ,))
324322
325323 if verbose :
326- print ("Processing results: " )
324+ print ("Processing results" )
327325
328326 if repeats == 1 :
327+ self .bare_exp_vals [0 ] = exp_vals [0 ]
328+ self .all_exp_vals [0 ,:] = exp_vals
329+
329330 self .result = richardson_extrapolate (self .all_exp_vals [0 ,:], self .noise_amplification_factors )
331+
332+ self .mitigated_exp_vals [0 ] = self .result
330333 else :
331334 for i in range (repeats ):
332335 self .bare_exp_vals [i ] = exp_vals [i * n_amp_factors ]
0 commit comments