Example #1
0
    def apply(self, wf):
        """
    	Applies the operator to a wavefunction.

    	Parameters
    	----------
    	wf : A Wavefunction
    	    The wavefunction you want to apply the operator.
    
    	Returns
    	-------
    	result : a Wavefunction
    	    The wavefunction resulting of the operation. It has the same
	    shape (i.e. is in the same Hilbert space) as the one passed as
	    argument.
    
    	Raises
    	------
    	DMRGException
	    if `wf` is has not the correct dimensions as a matrix.
	
	Examples
	--------
	>>> import numpy as np
	>>> from dmrg101.core.operators import Operator
	>>> from dmrg101.core.wavefunction import Wavefunction
	>>> wf = Wavefunction(2, 2)
	>>> wf.randomize()
	>>> identity_operator = Operator(np.eye(2, 2), np.eye(2, 2))
	>>> new_wf = identity_operator.apply(wf)
	>>> np.array_equal(new_wf.as_matrix,  wf.as_matrix)
	True
    	"""
        if wf.as_matrix.shape != ((self.left_dim, self.right_dim)):
            raise DMRGException("Wavefunction does not fit.")

        result = Wavefunction(self.left_dim, self.right_dim)

        tmp = np.dot(self.right_op, wf.as_matrix.transpose())
        result.as_matrix = self.parameter * np.dot(self.left_op,
                                                   tmp.transpose())

        return result
Example #2
0
    def apply(self, wf):
        """
    	Applies the operator to a wavefunction.

    	Parameters
    	----------
    	wf : A Wavefunction
    	    The wavefunction you want to apply the operator.
    
    	Returns
    	-------
    	result : a Wavefunction
    	    The wavefunction resulting of the operation. It has the same
	    shape (i.e. is in the same Hilbert space) as the one passed as
	    argument.
    
    	Raises
    	------
    	DMRGException
	    if `wf` is has not the correct dimensions as a matrix.
	
	Examples
	--------
	>>> import numpy as np
	>>> from dmrg101.core.operators import Operator
	>>> from dmrg101.core.wavefunction import Wavefunction
	>>> wf = Wavefunction(2, 2)
	>>> wf.randomize()
	>>> identity_operator = Operator(np.eye(2, 2), np.eye(2, 2))
	>>> new_wf = identity_operator.apply(wf)
	>>> np.array_equal(new_wf.as_matrix,  wf.as_matrix)
	True
    	"""
        if wf.as_matrix.shape != ((self.left_dim, self.right_dim)):
            raise DMRGException("Wavefunction does not fit.")

        result = Wavefunction(self.left_dim, self.right_dim)

        tmp = np.dot(self.right_op, wf.as_matrix.transpose())
        result.as_matrix = self.parameter * np.dot(self.left_op, tmp.transpose())

        return result