def test_expand_inplace(self): """Test inplace expand method.""" rho0, rho1 = np.diag([1, 0]), np.diag([0, 1]) rho_init = np.kron(rho0, rho0) # X \otimes I chan1 = Choi(self.choiI) chan2 = Choi(self.choiX) chan1.expand(chan2, inplace=True) rho_targ = np.kron(rho1, rho0) self.assertEqual(chan1.dims, (4, 4)) self.assertAllClose(chan1._evolve(rho_init), rho_targ) # I \otimes X chan1 = Choi(self.choiI) chan2 = Choi(self.choiX) chan2.expand(chan1, inplace=True) rho_targ = np.kron(rho0, rho1) self.assertEqual(chan2.dims, (4, 4)) self.assertAllClose(chan2._evolve(rho_init), rho_targ) # Completely depolarizing chan = Choi(self.depol_choi(1)) chan.expand(chan, inplace=True) rho_targ = np.diag([1, 1, 1, 1]) / 4 self.assertEqual(chan.dims, (4, 4)) self.assertAllClose(chan._evolve(rho_init), rho_targ)
def test_tensor_inplace(self): """Test inplace tensor method.""" rho0, rho1 = np.diag([1, 0]), np.diag([0, 1]) rho_init = np.kron(rho0, rho0) # X \otimes I rho_targ = np.kron(rho1, rho0) chan1 = Choi(self.choiI) chan2 = Choi(self.choiX) chan2.tensor(chan1, inplace=True) self.assertEqual(chan2.dims, (4, 4)) self.assertAllClose(chan2._evolve(rho_init), rho_targ) chan1 = Choi(self.choiI) chan2 = Choi(self.choiX) chan2 ^= chan1 self.assertEqual(chan2.dims, (4, 4)) self.assertAllClose(chan2._evolve(rho_init), rho_targ) # I \otimes X rho_targ = np.kron(rho0, rho1) chan1 = Choi(self.choiI) chan2 = Choi(self.choiX) chan1.tensor(chan2, inplace=True) self.assertEqual(chan1.dims, (4, 4)) self.assertAllClose(chan1._evolve(rho_init), rho_targ) chan1 = Choi(self.choiI) chan2 = Choi(self.choiX) chan1 ^= chan2 self.assertEqual(chan1.dims, (4, 4)) self.assertAllClose(chan1._evolve(rho_init), rho_targ) # Completely depolarizing rho_targ = np.diag([1, 1, 1, 1]) / 4 chan = Choi(self.depol_choi(1)) chan.tensor(chan, inplace=True) self.assertEqual(chan.dims, (4, 4)) self.assertAllClose(chan._evolve(rho_init), rho_targ) chan = Choi(self.depol_choi(1)) chan ^= chan self.assertEqual(chan.dims, (4, 4)) self.assertAllClose(chan._evolve(rho_init), rho_targ)
def test_evolve(self): """Test evolve method.""" input_psi = [0, 1] input_rho = [[0, 0], [0, 1]] # Identity channel chan = Choi(self.choiI) target_rho = np.array([[0, 0], [0, 1]]) self.assertAllClose(chan._evolve(input_psi), target_rho) self.assertAllClose(chan._evolve(np.array(input_psi)), target_rho) self.assertAllClose(chan._evolve(input_rho), target_rho) self.assertAllClose(chan._evolve(np.array(input_rho)), target_rho) # Hadamard channel chan = Choi(self.choiH) target_rho = np.array([[1, -1], [-1, 1]]) / 2 self.assertAllClose(chan._evolve(input_psi), target_rho) self.assertAllClose(chan._evolve(np.array(input_psi)), target_rho) self.assertAllClose(chan._evolve(input_rho), target_rho) self.assertAllClose(chan._evolve(np.array(input_rho)), target_rho) # Completely depolarizing channel chan = Choi(self.depol_choi(1)) target_rho = np.eye(2) / 2 self.assertAllClose(chan._evolve(input_psi), target_rho) self.assertAllClose(chan._evolve(np.array(input_psi)), target_rho) self.assertAllClose(chan._evolve(input_rho), target_rho) self.assertAllClose(chan._evolve(np.array(input_rho)), target_rho)