def test_operator_to_ptm(self): """Test Operator to PTM transformation.""" # Test unitary channels for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = PTM(ptm) chan2 = PTM(Operator(mat)) self.assertEqual(chan1, chan2)
def test_unitary_to_ptm(self): """Test UnitaryChannel to PTM transformation.""" # Test unitary channels for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = PTM(ptm) chan2 = PTM(UnitaryChannel(mat)) self.assertEqual(chan1, chan2)
def test_ptm_to_operator(self): """Test PTM to Operator transformation.""" for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = Operator(mat) chan2 = Operator(PTM(ptm)) self.assertTrue( matrix_equal(chan2.data, chan1.data, ignore_phase=True)) self.assertRaises(QiskitError, Operator, PTM(self.depol_ptm(0.5)))
def test_ptm_to_unitary(self): """Test PTM to UnitaryChannel transformation.""" for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = UnitaryChannel(mat) chan2 = UnitaryChannel(PTM(ptm)) self.assertTrue( matrix_equal(chan2.data, chan1.data, ignore_phase=True)) self.assertRaises(QiskitError, UnitaryChannel, PTM(self.depol_ptm(0.5)))
def test_stinespring_to_ptm(self): """Test Stinespring to PTM transformation.""" # Test unitary channels for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = PTM(ptm) chan2 = PTM(Stinespring(mat)) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = PTM(self.depol_ptm(p)) chan2 = PTM(Stinespring(self.depol_stine(p))) self.assertEqual(chan1, chan2)
def test_kraus_to_ptm(self): """Test Kraus to PTM transformation.""" # Test unitary channels for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = PTM(ptm) chan2 = PTM(Kraus(mat)) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = PTM(self.depol_ptm(p)) chan2 = PTM(Kraus(self.depol_kraus(p))) self.assertEqual(chan1, chan2)
def test_superop_to_ptm(self): """Test SuperOp to PTM transformation.""" # Test unitary channels for sop, ptm in zip(self.unitary_sop, self.unitary_ptm): chan1 = PTM(ptm) chan2 = PTM(SuperOp(sop)) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = PTM(self.depol_ptm(p)) chan2 = PTM(SuperOp(self.depol_sop(p))) self.assertEqual(chan1, chan2)
def test_choi_to_ptm(self): """Test Choi to PTM transformation.""" # Test unitary channels for choi, ptm in zip(self.unitary_choi, self.unitary_ptm): chan1 = PTM(ptm) chan2 = PTM(Choi(choi)) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = PTM(self.depol_ptm(p)) chan2 = PTM(Choi(self.depol_choi(p))) self.assertEqual(chan1, chan2)
def test_ptm_to_chi(self): """Test PTM to Chi transformation.""" # Test unitary channels for chi, ptm in zip(self.unitary_chi, self.unitary_ptm): chan1 = Chi(chi) chan2 = Chi(PTM(ptm)) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = Chi(self.depol_chi(p)) chan2 = Chi(PTM(self.depol_ptm(p))) self.assertEqual(chan1, chan2)
def test_ptm_to_ptm(self): """Test PTM to PTM transformation.""" # Test unitary channels for ptm in self.unitary_ptm: chan1 = PTM(ptm) chan2 = PTM(chan1) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = PTM(self.depol_ptm(p)) chan2 = PTM(chan1) self.assertEqual(chan1, chan2)
def _ptm_to_other(self, rep, qubits_test_cases, repetitions): """Test PTM to Other evolution.""" for nq in qubits_test_cases: dim = 2**nq for _ in range(repetitions): rho = self.rand_rho(dim) mat = self.rand_matrix(dim**2, dim**2, real=True) chan1 = PTM(mat) rho1 = chan1._evolve(rho) chan2 = rep(chan1) rho2 = chan2._evolve(rho) self.assertAllClose(rho1, rho2)
def test_ptm_to_superop(self): """Test PTM to SuperOp transformation.""" # Test unitary channels for ptm, sop in zip(self.unitary_ptm, self.unitary_sop): chan1 = SuperOp(sop) chan2 = SuperOp(PTM(ptm)) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = SuperOp(self.depol_sop(p)) chan2 = SuperOp(PTM(self.depol_ptm(p))) self.assertEqual(chan1, chan2)
def test_ptm_to_stinespring(self): """Test PTM to Stinespring transformation.""" # Test unitary channels for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = Kraus(mat) chan2 = Kraus(PTM(ptm)) self.assertTrue( matrix_equal(chan2.data[0], chan1.data[0], ignore_phase=True)) # Test depolarizing channels rho = np.diag([1, 0]) for p in [0.25, 0.5, 0.75, 1]: targ = Stinespring(self.depol_stine(p))._evolve(rho) chan = Stinespring(PTM(self.depol_ptm(p))) self.assertAllClose(chan._evolve(rho), targ)
def test_ptm_to_stinespring(self): """Test PTM to Stinespring transformation.""" # Test unitary channels for mat, ptm in zip(self.unitary_mat, self.unitary_ptm): chan1 = Kraus(mat) chan2 = Kraus(PTM(ptm)) self.assertTrue( matrix_equal(chan2.data[0], chan1.data[0], ignore_phase=True)) # Test depolarizing channels rho = DensityMatrix(np.diag([1, 0])) for p in [0.25, 0.5, 0.75, 1]: target = rho.evolve(Stinespring(self.depol_stine(p))) output = rho.evolve(Stinespring(PTM(self.depol_ptm(p)))) self.assertEqual(output, target)
def test_ptm_compose(self): """Test compose of PTM matrices is correct.""" mats = [self.UI, self.UX, self.UY, self.UZ, self.UH] chans = [ PTM(mat) for mat in [self.ptmI, self.ptmX, self.ptmY, self.ptmZ, self.ptmH] ] self._compare_compose_to_operator(chans, mats)
def test_ptm_compose(self): """Test compose of PTM matrices is correct.""" mats = [self.matI, self.matX, self.matY, self.matZ, self.matH] chans = [ PTM(mat) for mat in [self.ptmI, self.ptmX, self.ptmY, self.ptmZ, self.ptmH] ] self._compare_compose_to_unitary(chans, mats)
def _ptm_to_other(self, rep, qubits_test_cases, repetitions): """Test PTM to Other evolution.""" for nq in qubits_test_cases: dim = 2**nq for _ in range(repetitions): rho = self.rand_rho(dim) mat = self.rand_matrix(dim**2, dim**2, real=True) chan = PTM(mat) rho1 = DensityMatrix(rho).evolve(chan).data rho2 = DensityMatrix(rho).evolve(rep(chan)).data assert_allclose(rho1, rho2)
def test_ptm_transpose(self): """Test transpose of PTM matrices is correct.""" mats = self.unitaries chans = [PTM(mat) for mat in self.ptms] self._compare_transpose_to_operator(chans, mats)
def test_ptm_subtract_other_rep(self): """Test subtraction of PTM matrices is correct.""" chan = PTM(self.ptmI) self._check_subtract_other_reps(chan)
def test_ptm_add_other_rep(self): """Test addition of PTM matrices is correct.""" chan = PTM(self.ptmI) self._check_add_other_reps(chan)
def test_ptm_compose_other_reps(self): """Test compose of PTM works with other reps.""" chan = PTM(self.ptmI) self._check_compose_other_reps(chan)
def test_ptm_expand_other_reps(self): """Test expand of PTM works with other reps.""" chan = PTM(self.ptmI) self._check_expand_other_reps(chan)
def test_ptm_expand_random(self): """Test expand of PTM matrices is correct.""" mats = [self.rand_matrix(2, 2) for _ in range(4)] chans = [PTM(Operator(mat)) for mat in mats] self._compare_expand_to_operator(chans, mats)
def test_ptm_tensor_other_reps(self): """Test tensor of PTM works with other reps.""" chan = PTM(self.ptmI) self._check_tensor_other_reps(chan)
def test_ptm_compose_random(self): """Test compose of PTM matrices is correct.""" mats = [self.rand_matrix(4, 4) for _ in range(4)] chans = [PTM(UnitaryChannel(mat)) for mat in mats] self._compare_compose_to_unitary(chans, mats)
def test_ptm_adjoint(self): """Test adjoint of PTM matrices is correct.""" mats = self.unitaries chans = [PTM(mat) for mat in self.ptms] self._compare_adjoint_to_operator(chans, mats)
def test_ptm_adjoint_random(self): """Test adjoint of PTM matrices is correct.""" mats = [self.rand_matrix(4, 4) for _ in range(4)] chans = [PTM(Operator(mat)) for mat in mats] self._compare_adjoint_to_operator(chans, mats)
def test_ptm_conjugate(self): """Test conjugate of PTM matrices is correct.""" mats = self.unitaries chans = [PTM(mat) for mat in self.ptms] self._compare_conjugate_to_unitary(chans, mats)