def test_reset_qutrit(self): """Test reset method for qutrit""" state = Statevector(np.array([1, 1, 1]) / np.sqrt(3)) state.seed(200) value = state.reset() target = Statevector(np.array([1, 0, 0])) self.assertEqual(value, target)
def test_sample_memory_qutrit(self): """Test sample_memory method for qutrit state""" p = 0.3 shots = 1000 state = Statevector([np.sqrt(p), 0, np.sqrt(1 - p)]) state.seed(100) with self.subTest(msg="memory"): memory = state.sample_memory(shots) self.assertEqual(len(memory), shots) self.assertEqual(set(memory), {"0", "2"})
def test_sample_counts_qutrit(self): """Test sample_counts method for qutrit state""" p = 0.3 shots = 1000 threshold = 0.03 * shots state = Statevector([np.sqrt(p), 0, np.sqrt(1 - p)]) state.seed(100) with self.subTest(msg="counts"): target = {"0": shots * p, "2": shots * (1 - p)} counts = state.sample_counts(shots=shots) self.assertDictAlmostEqual(counts, target, threshold)
def test_sample_measure_qutrit(self): """Test sample measure method for qutrit state""" p = 0.3 shots = 1000 threshold = 0.02 * shots state = Statevector([np.sqrt(p), 0, np.sqrt(1 - p)]) state.seed(100) with self.subTest(msg='counts'): target = {'0': shots * p, '2': shots * (1 - p)} counts = state.sample_measure(shots=shots) self.assertDictAlmostEqual(counts, target, threshold) with self.subTest(msg='memory'): memory = state.sample_measure(shots=shots, memory=True) self.assertEqual(len(memory), shots) self.assertEqual(set(memory), set(['0', '2']))