예제 #1
0
def conditional_entropy(state, qubit_a, qubit_b):
    """Conditional entropy S(A|B) = S(AB) - S(B)
    
    Args:
        state: a vector or density operator
        qubit_a: 0-based index of the qubit A
        qubit_b: 0-based index of the qubit B
        
    Returns:
        int: the conditional entropy
    """
    return entropy(state) - entropy(partial_trace(state, [qubit_b]))
예제 #2
0
def classical_correlation(rho, qubit=0):
    """
    Calculate the truly classical correlations between two qubits.
    
    The classical correlations are defined e.g. in Eq. (8) 
    of Phys. Rev. A 83, 052108 (2011). 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)
        
    Returns:
        float: classical correlations
    """
    assert rho.shape == (4, 4), "Not a two-qubit density matrix"
    cc = lambda x: quantum_conditional_entropy(rho, x[0], x[1], qubit=qubit)
    f = minimize(cc, [np.pi/2, np.pi])
    return (entropy(partial_trace(rho, [qubit])) - f.fun)/np.log(2)
예제 #3
0
 def test_entropy_1d(self):
     input_vector = np.array([0.5, 1, 0])
     res = entropy(input_vector)
     self.assertEqual(0, res)
예제 #4
0
 def test_entropy(self):
     input_density_matrix = np.array([[0.5, 0.0], [0.0, 0.5]])
     res = entropy(input_density_matrix)
     self.assertAlmostEqual(0.6931471805599453, res)