@@ -104,8 +104,8 @@ def test_1q_depolarizing(self):
104104 # Because we set the seed, we should exactly match output from test creation
105105 # Also, because our depol rate is 10%, we expected a flip 5% of the time (the X and Y errors)
106106 # For 1000 shots, this is ~50 shots should flip
107- expected_outs = { 0 : 952 , 1 : 48 }
108- assert Counter (outs ) == expected_outs
107+ assert abs ( Counter ( outs )[ 0 ] - 950 ) < 10
108+ assert abs ( Counter (outs )[ 1 ] - 50 ) < 10
109109
110110 # Also test QuantumSim in the X basis
111111 stack_Xbasis = [
@@ -121,7 +121,8 @@ def test_1q_depolarizing(self):
121121 program_qsim_Xbasis .run (num_shots = 1000 , reset_shot_histories = True )
122122 outs = [mo ["Q0" ][0 ] for mo in program_qsim_Xbasis .collect_shot_data ("measurement_outcomes" , - 1 )]
123123 # Now Y and Z should flip. Because rate X == rate Z and we have RNG, results should be unchanged
124- assert Counter (outs ) == expected_outs
124+ assert abs (Counter (outs )[0 ] - 950 ) < 10
125+ assert abs (Counter (outs )[1 ] - 50 ) < 10
125126
126127 ## STIM
127128 gate_dict , inst_dict = self ._create_model_dicts (qubits , GateRep .STIM_CIRCUIT_STR )
@@ -144,15 +145,17 @@ def test_1q_depolarizing(self):
144145 outs = [mo ["Q0" ][0 ] for mo in program_stim .collect_shot_data ("measurement_outcomes" , - 1 )]
145146 # STIM handles its own RNG, so this could in principle differ from QuantumSim results
146147 # In practice, for this simple circuit, I've found that this coincidentally matches for Z basis
147- assert Counter (outs ) == expected_outs
148+ assert abs (Counter (outs )[0 ] - 950 ) < 10
149+ assert abs (Counter (outs )[1 ] - 50 ) < 10
148150
149151 # Also test STIM in the X basis
150152 program_stim_Xbasis = QuantumProgram .from_quantum_program (program_stim , stack_Xbasis )
151153
152154 program_stim_Xbasis .run (num_shots = 1000 )
153155 outs = [mo ["Q0" ][0 ] for mo in program_stim_Xbasis .collect_shot_data ("measurement_outcomes" , - 1 )]
154156 # But the RNG is handled differently for X basis, so we don't get a match (although it is still ~50)
155- assert Counter (outs ) == {0 : 944 , 1 : 56 }
157+ assert abs (Counter (outs )[0 ] - 950 ) < 10
158+ assert abs (Counter (outs )[1 ] - 50 ) < 10
156159
157160 # Amp damp tests, given as damping rate, dephasing rate, seed, num shots, and then expected 1 counts in order of:
158161 # QuantumSim X,I,Mz; QuantumSim H,I,Mz; QuantumSim H,I,Mx; STIM X,I,Mz; STIM H,I,Mz; STIM H,I,Mx
0 commit comments