def test_unitary_to_stinespring(self): """Test UnitaryChannel to Stinespring transformation.""" # Test unitary channels for mat in self.unitary_mat: chan1 = Stinespring(mat) chan2 = Stinespring(UnitaryChannel(chan1)) self.assertEqual(chan1, chan2)
def test_operator_to_stinespring(self): """Test Operator to Stinespring transformation.""" # Test unitary channels for mat in self.unitary_mat: chan1 = Stinespring(mat) chan2 = Stinespring(Operator(chan1)) self.assertEqual(chan1, chan2)
def test_stinespring_to_unitary(self): """Test Stinespring to UnitaryChannel transformation.""" for mat in self.unitary_mat: chan1 = UnitaryChannel(mat) chan2 = UnitaryChannel(Stinespring(mat)) self.assertTrue( matrix_equal(chan2.data, chan1.data, ignore_phase=True)) self.assertRaises(QiskitError, UnitaryChannel, Stinespring(self.depol_stine(0.5)))
def test_stinespring_to_operator(self): """Test Stinespring to Operator transformation.""" for mat in self.unitary_mat: chan1 = Operator(mat) chan2 = Operator(Stinespring(mat)) self.assertTrue( matrix_equal(chan2.data, chan1.data, ignore_phase=True)) self.assertRaises(QiskitError, Operator, Stinespring(self.depol_stine(0.5)))
def test_stinespring_to_chi(self): """Test Stinespring to Chi transformation.""" # Test unitary channels for mat, chi in zip(self.unitary_mat, self.unitary_chi): chan1 = Chi(chi) chan2 = Chi(Stinespring(mat)) 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(Stinespring(self.depol_stine(p))) self.assertEqual(chan1, chan2)
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_stinespring_to_stinespring(self): """Test Stinespring to Stinespring transformation.""" # Test unitary channels for mat in self.unitary_mat: chan1 = Stinespring(mat) chan2 = Stinespring(chan1) self.assertEqual(chan1, chan2) # Test depolarizing channels for p in [0.25, 0.5, 0.75, 1]: chan1 = Stinespring(self.depol_stine(p)) chan2 = Stinespring(chan1) self.assertEqual(chan1, chan2)
def _stinespring_to_other_single(self, rep, qubits_test_cases, repetitions): """Test single Stinespring 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) chan1 = Stinespring(mat) rho1 = chan1._evolve(rho) chan2 = rep(chan1) rho2 = chan2._evolve(rho) self.assertAllClose(rho1, rho2)
def test_superop_to_stinespring(self): """Test SuperOp to Stinespring transformation.""" # Test unitary channels for mat, sop in zip(self.unitary_mat, self.unitary_sop): chan1 = Stinespring(mat) chan2 = Stinespring(SuperOp(sop)) 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(SuperOp(self.depol_sop(p)))) self.assertEqual(output, target)
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 _stinespring_to_other_single(self, rep, qubits_test_cases, repetitions): """Test single Stinespring 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) chan = Stinespring(mat) rho1 = DensityMatrix(rho).evolve(chan).data rho2 = DensityMatrix(rho).evolve(rep(chan)).data assert_allclose(rho1, rho2)
def test_stinespring_to_superop(self): """Test Stinespring to SuperOp transformation.""" # Test unitary channels for mat, sop in zip(self.unitary_mat, self.unitary_sop): chan1 = SuperOp(sop) chan2 = SuperOp(Kraus(mat)) 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(Stinespring(self.depol_stine(p))) self.assertEqual(chan1, chan2)
def _stinespring_to_other_double(self, rep, qubits_test_cases, repetitions): """Test double Stinespring to Other evolution.""" for nq in qubits_test_cases: dim = 2**nq for _ in range(repetitions): rho = self.rand_rho(dim) mat_l = self.rand_matrix(dim**2, dim) mat_r = self.rand_matrix(dim**2, dim) chan = Stinespring((mat_l, mat_r)) rho1 = DensityMatrix(rho).evolve(chan).data rho2 = DensityMatrix(rho).evolve(rep(chan)).data self.assertAllClose(rho1, rho2)
def test_superop_to_stinespring(self): """Test SuperOp to Stinespring transformation.""" # Test unitary channels for mat, sop in zip(self.unitary_mat, self.unitary_sop): chan1 = Stinespring(mat) chan2 = Stinespring(SuperOp(sop)) 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(SuperOp(self.depol_sop(p))) self.assertAllClose(chan._evolve(rho), targ)
def test_kraus_to_stinespring(self): """Test Kraus to Stinespring transformation.""" # Test unitary channels for mat in self.unitary_mat: chan1 = Stinespring(mat) chan2 = Stinespring(Kraus(mat)) 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(Kraus(self.depol_kraus(p))) self.assertAllClose(chan._evolve(rho), targ)
def test_stinespring_transpose(self): """Test transpose of Stinespring matrices is correct.""" mats = self.unitaries chans = [Stinespring(mat) for mat in mats] self._compare_transpose_to_operator(chans, mats)
def test_stinespring_subtract_other_rep(self): """Test subtraction of Stinespring matrices is correct.""" chan = Stinespring(self.UI) self._check_subtract_other_reps(chan)
def test_stinespring_add_other_rep(self): """Test addition of Stinespring matrices is correct.""" chan = Stinespring(self.UI) self._check_add_other_reps(chan)
def test_stinespring_compose_other_reps(self): """Test compose of Stinespring works with other reps.""" chan = Stinespring(self.UI) self._check_compose_other_reps(chan)
def test_stinespring_compose(self): """Test compose of Stinespring matrices is correct.""" mats = [self.UI, self.UX, self.UY, self.UZ, self.UH] chans = [Stinespring(mat) for mat in mats] self._compare_compose_to_operator(chans, mats)
def test_stinespring_expand_other_reps(self): """Test expand of Stinespring works with other reps.""" chan = Stinespring(self.UI) self._check_expand_other_reps(chan)
def test_stinespring_expand_random(self): """Test expand of Stinespring matrices is correct.""" mats = [self.rand_matrix(2, 2) for _ in range(4)] chans = [Stinespring(Operator(mat)) for mat in mats] self._compare_expand_to_operator(chans, mats)
def test_stinespring_tensor_other_reps(self): """Test tensor of Stinespring works with other reps.""" chan = Stinespring(self.UI) self._check_tensor_other_reps(chan)
def test_stinespring_compose(self): """Test compose of Stinespring matrices is correct.""" mats = [self.matI, self.matX, self.matY, self.matZ, self.matH] chans = [Stinespring(mat) for mat in mats] self._compare_compose_to_unitary(chans, mats)
def test_stinespring_compose_random(self): """Test compose of Stinespring matrices is correct.""" mats = [self.rand_matrix(4, 4) for _ in range(4)] chans = [Stinespring(UnitaryChannel(mat)) for mat in mats] self._compare_compose_to_unitary(chans, mats)
def test_stinespring_adjoint(self): """Test adjoint of Stinespring matrices is correct.""" mats = self.unitaries chans = [Stinespring(mat) for mat in mats] self._compare_adjoint_to_operator(chans, mats)
def test_stinespring_adjoint_random(self): """Test adjoint of Stinespring matrices is correct.""" mats = [self.rand_matrix(4, 4) for _ in range(4)] chans = [Stinespring(Operator(mat)) for mat in mats] self._compare_adjoint_to_operator(chans, mats)
def test_stinespring_conjugate(self): """Test conjugate of Stinespring matrices is correct.""" mats = self.unitaries chans = [Stinespring(mat) for mat in mats] self._compare_conjugate_to_unitary(chans, mats)