def test_expand(self): """Test expand method.""" rho0, rho1 = np.diag([1, 0]), np.diag([0, 1]) rho_init = DensityMatrix(np.kron(rho0, rho0)) chan1 = Choi(self.choiI) chan2 = Choi(self.choiX) # X \otimes I chan = chan1.expand(chan2) rho_targ = DensityMatrix(np.kron(rho1, rho0)) self.assertEqual(chan.dim, (4, 4)) self.assertEqual(rho_init.evolve(chan), rho_targ) # I \otimes X chan = chan2.expand(chan1) rho_targ = DensityMatrix(np.kron(rho0, rho1)) self.assertEqual(chan.dim, (4, 4)) self.assertEqual(rho_init.evolve(chan), rho_targ) # Completely depolarizing chan_dep = Choi(self.depol_choi(1)) chan = chan_dep.expand(chan_dep) rho_targ = DensityMatrix(np.diag([1, 1, 1, 1]) / 4) self.assertEqual(chan.dim, (4, 4)) self.assertEqual(rho_init.evolve(chan), rho_targ)
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)