Esempio n. 1
0
 def test_mutual_information_equivalence(self):
     """Test mutual_information is same for equivalent inputs"""
     for alpha, beta in [(0, 0), (0, 0.25), (0.25, 0), (0.33, 0.33),
                         (0.5, 0.5), (0.75, 0.25), (0, 0.75)]:
         psi = Statevector(
             [alpha, beta, 0, 1j * np.sqrt(1 - alpha**2 - beta**2)])
         rho = DensityMatrix(psi)
         self.assertAlmostEqual(mutual_information(psi),
                                mutual_information(rho))
Esempio n. 2
0
 def test_mutual_information_density_matrix(self):
     """Test mutual_information  function on density matrix inputs"""
     # Density matrix input
     rho1 = DensityMatrix([[0.5, 0, 0, 0.5], [0, 0, 0, 0], [0, 0, 0, 0], [0.5, 0, 0, 0.5]])
     rho2 = DensityMatrix([[0, 0, 0, 0], [0, 0.5, -0.5j, 0], [0, 0.5j, 0.5, 0], [0, 0, 0, 0]])
     self.assertAlmostEqual(mutual_information(rho1), 2)
     self.assertAlmostEqual(mutual_information(rho2), 2)
     # List input
     rho = [[0.5, 0.5, 0, 0], [0.5, 0.5, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
     self.assertEqual(mutual_information(rho), 0)
     # Array input
     rho = np.diag([0.25, 0.25, 0.25, 0.25])
     self.assertEqual(mutual_information(rho), 0)
Esempio n. 3
0
def discord(rho, qubit=0):
    """
    The quantum discord between two qubits

    Quantum discord is defined in Phys. Rev. Lett. 88, 017901 (2001).
    We use base 2 for log.

    Args:
        rho (Array): a two-qubit density operator
        qubit (int): 0 or 1, the qubit on which the measurement is done (default 0)

    Return:
        float: quantum discord, between [0, 1]
    """
    return (mutual_information(rho, 2) / np.log(2) -
            classical_correlation(rho, qubit=qubit))
Esempio n. 4
0
 def test_mutual_information_statevector(self):
     """Test mutual_information function on statevector inputs"""
     # Statevector input
     psi = Statevector([0.70710678118654746, 0, 0, -0.70710678118654746j])
     self.assertAlmostEqual(mutual_information(psi), 2)
     # List input
     psi = [1, 0, 0, 0]
     self.assertAlmostEqual(mutual_information(psi), 0)
     # Array input
     psi = np.array([0.5, 0.5, 0.5, 0.5])
     self.assertAlmostEqual(mutual_information(psi), 0)
     # Larger than 2 qubit input
     psi_ls = [0.70710678118654746] + (14 * [0]) + [0.70710678118654746j]
     psi = Statevector(psi_ls, dims=(2, 8))
     self.assertAlmostEqual(mutual_information(psi), 2)
     psi = Statevector(psi_ls, dims=(4, 4))
     self.assertAlmostEqual(mutual_information(psi), 2)
     psi = Statevector(psi_ls, dims=(8, 2))
     self.assertAlmostEqual(mutual_information(psi), 2)