def test_reset_2qubit(self): """Test reset method for 2-qubit state""" state = Statevector(np.array([1, 0, 0, 1]) / np.sqrt(2)) state.seed(100) with self.subTest(msg="reset"): psi = state.copy() value = psi.reset() target = Statevector(np.array([1, 0, 0, 0])) self.assertEqual(value, target) with self.subTest(msg="reset"): psi = state.copy() value = psi.reset([0, 1]) target = Statevector(np.array([1, 0, 0, 0])) self.assertEqual(value, target) with self.subTest(msg="reset [0]"): psi = state.copy() value = psi.reset([0]) targets = [ Statevector(np.array([1, 0, 0, 0])), Statevector(np.array([0, 0, 1, 0])) ] self.assertIn(value, targets) with self.subTest(msg="reset [0]"): psi = state.copy() value = psi.reset([1]) targets = [ Statevector(np.array([1, 0, 0, 0])), Statevector(np.array([0, 1, 0, 0])) ] self.assertIn(value, targets)
def test_copy(self): """Test Statevector copy method""" for _ in range(5): vec = self.rand_vec(4) orig = Statevector(vec) cpy = orig.copy() cpy._data[0] += 1.0 self.assertFalse(cpy == orig)
def test_measure_qutrit(self): """Test measure method for qutrit""" state = Statevector(np.array([1, 1, 1]) / np.sqrt(3)) seed = 200 shots = 100 for i in range(shots): psi = state.copy() psi.seed(seed + i) outcome, value = psi.measure() self.assertIn(outcome, ["0", "1", "2"]) if outcome == "0": target = Statevector([1, 0, 0]) self.assertEqual(value, target) elif outcome == "1": target = Statevector([0, 1, 0]) self.assertEqual(value, target) else: target = Statevector([0, 0, 1]) self.assertEqual(value, target)