(self, matrix, qubit, **options)
return new_matrix
Compute the reduced density matrix by tracing out one qubit.
           The qubit argument should be of type python int, since it is used
           in bit operations
Compute the reduced density matrix by tracing out one qubit.
           The qubit argument should be of type python int, since it is used
           in bit operations
Compute the reduced density matrix by tracing out one qubit . The qubit argument should be of type python int since it is used in bit operations
def _reduced_density(self, matrix, qubit, **options):
        """Compute the reduced density matrix by tracing out one qubit.
           The qubit argument should be of type python int, since it is used
           in bit operations
        """
        def find_index_that_is_projected(j, k, qubit):
            bit_mask = 2**qubit - 1
            return ((j >> qubit) << (1 + qubit)) + (j & bit_mask) + (k << qubit)

        old_matrix = represent(matrix, **options)
        old_size = old_matrix.cols
        #we expect the old_size to be even
        new_size = old_size//2
        new_matrix = Matrix().zeros(new_size)

        for i in xrange(new_size):
            for j in xrange(new_size):
                for k in range(2):
                    col = find_index_that_is_projected(j, k, qubit)
                    row = find_index_that_is_projected(i, k, qubit)
                    new_matrix[i, j] += old_matrix[row, col]

        return new_matrix
def _reduced_density ( self , matrix , qubit , * * options ) : def find_index_that_is_projected ( j , k , qubit ) : bit_mask = 2 ** qubit - 1 return ( ( j >> qubit ) << ( 1 + qubit ) ) + ( j & bit_mask ) + ( k << qubit ) old_matrix = represent ( matrix , * * options ) old_size = old_matrix . cols #we expect the old_size to be even new_size = old_size // 2 new_matrix = Matrix ( ) . zeros ( new_size ) for i in xrange ( new_size ) : for j in xrange ( new_size ) : for k in range ( 2 ) : col = find_index_that_is_projected ( j , k , qubit ) row = find_index_that_is_projected ( i , k , qubit ) new_matrix [ i , j ] += old_matrix [ row , col ] return new_matrix