Beispiel #1
0
 def test_invalid_dim(self):
     """Tests for invalid dim."""
     rho = np.array([[1 / 2, 0, 0, 1 / 2], [0, 0, 0, 0], [0, 0, 0, 0],
                     [1 / 2, 0, 0, 1 / 2]])
     sigma = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
     with self.assertRaises(ValueError):
         fidelity(rho, sigma)
Beispiel #2
0
 def test_fidelity_non_identical_states_2(self):
     """Test the fidelity between two non-identical states."""
     e_0, e_1 = ket(2, 0), ket(2, 1)
     rho = 3 / 4 * e_0 * e_0.conj().T + 1 / 4 * e_1 * e_1.conj().T
     sigma = 1 / 8 * e_0 * e_0.conj().T + 7 / 8 * e_1 * e_1.conj().T
     self.assertEqual(np.isclose(fidelity(rho, sigma), 0.774, rtol=1e-03),
                      True)
Beispiel #3
0
    def test_fidelity_default(self):
        """Test fidelity default arguments."""
        rho = np.array([[1 / 2, 0, 0, 1 / 2], [0, 0, 0, 0], [0, 0, 0, 0],
                        [1 / 2, 0, 0, 1 / 2]])
        sigma = rho

        res = fidelity(rho, sigma)
        self.assertEqual(np.isclose(res, 1), True)
Beispiel #4
0
    def test_fidelity_cvx(self):
        """Test fidelity for cvx objects."""
        rho = cvxpy.bmat([[1 / 2, 0, 0, 1 / 2], [0, 0, 0, 0], [0, 0, 0, 0],
                          [1 / 2, 0, 0, 1 / 2]])
        sigma = rho

        res = fidelity(rho, sigma)
        self.assertEqual(np.isclose(res, 1), True)
Beispiel #5
0
    def test_sub_fidelity_lower_bound_2(self):
        """Test sub_fidelity is lower bound on fidelity for rho and pi."""
        e_0, e_1 = ket(2, 0), ket(2, 1)
        rho = 3 / 4 * e_0 * e_0.conj().T + 1 / 4 * e_1 * e_1.conj().T
        sigma = 1 / 8 * e_0 * e_0.conj().T + 7 / 8 * e_1 * e_1.conj().T

        res = sub_fidelity(rho, sigma)
        self.assertLessEqual(res, fidelity(rho, sigma))