@@ -594,3 +594,33 @@ def test_shard_for_more_prefix_qubits_than_qubits():
594594 expected = np .zeros (2 ** 2 , dtype = np .complex64 )
595595 expected [0 ] = 1.0
596596 np .testing .assert_almost_equal (expected , s .current_state )
597+
598+
599+ @pytest .mark .parametrize ('num_prefix_qubits' , (0 , 2 ))
600+ def test_precision (num_prefix_qubits ):
601+ # 16 random W's followed by their inverses on five qubits.
602+ # The floating point epsilon for np.float32 is about 1e-7.
603+ # Floating point epsilon is about 1e-7.
604+ # Each qubits error will add across gates on that qubit, but it is like a
605+ # random walk, so error should be about sqrt(16) per qubit.
606+ # The total error should then be about 2e-6.
607+ with xmon_stepper .Stepper (num_qubits = 5 ,
608+ num_prefix_qubits = num_prefix_qubits ,
609+ min_qubits_before_shard = 0 ) as s :
610+ half_turns_list = [np .random .rand () for _ in range (16 )]
611+ axis_half_turns_list = [np .random .rand () for _ in range (16 )]
612+
613+ for half_turns , axis_half_turns in zip (half_turns_list ,
614+ axis_half_turns_list ):
615+ for index in range (5 ):
616+ s .simulate_w (index = index , axis_half_turns = axis_half_turns ,
617+ half_turns = half_turns )
618+ for half_turns , axis_half_turns in zip (half_turns_list [::- 1 ],
619+ axis_half_turns_list [::- 1 ]):
620+ for index in range (5 ):
621+ s .simulate_w (index = index , axis_half_turns = axis_half_turns ,
622+ half_turns = - half_turns )
623+ expected = np .zeros (2 ** 5 , dtype = np .complex64 )
624+ expected [0 ] = 1.0
625+ # asserts that abs value of arrays is < 1.5 * 10^(-decimal)
626+ np .testing .assert_almost_equal (expected , s .current_state , decimal = 6 )
0 commit comments