def calculate_ground_state_wf(d, e, saved_lanczos_vectors): """Calculates the ground state wavefunction. Parameters ---------- d : a numpy array with ndim = 1. The elements of the diagonal of the tridiagonal matrix. The size of `d`. e : a numpy array with ndim = 1. The off-diagonal elements of the tridiagonal matrix. The size of `e` equals the size of `d`, and it is padded with a zero at the end. saved_lanczos_vectors : a list of Wavefunctions. The Lanczos vectors that are saved. Returns ------- result : a Wavefunction. The ground state function (normalized). """ evals, evecs = diagonalize_tridiagonal_matrix(d, e, True) min_index = np.argsort(evals)[0] coefficients_of_gs_in_krylov_space = evecs[:, min_index] assert ( len(saved_lanczos_vectors) == len(coefficients_of_gs_in_krylov_space)) result = Wavefunction(saved_lanczos_vectors[0].left_dim, saved_lanczos_vectors[0].right_dim) result.set_to_zero() for i in range(len(saved_lanczos_vectors)): result.as_matrix += (coefficients_of_gs_in_krylov_space[i] * saved_lanczos_vectors[i].as_matrix) result.normalize() return result
def calculate_ground_state_wf(d, e, saved_lanczos_vectors): """Calculates the ground state wavefunction. Parameters ---------- d : a numpy array with ndim = 1. The elements of the diagonal of the tridiagonal matrix. The size of `d`. e : a numpy array with ndim = 1. The off-diagonal elements of the tridiagonal matrix. The size of `e` equals the size of `d`, and it is padded with a zero at the end. saved_lanczos_vectors : a list of Wavefunctions. The Lanczos vectors that are saved. Returns ------- result : a Wavefunction. The ground state function (normalized). """ evals, evecs = diagonalize_tridiagonal_matrix(d, e, True) min_index = np.argsort(evals)[0] coefficients_of_gs_in_krylov_space = evecs[:, min_index] assert(len(saved_lanczos_vectors) == len(coefficients_of_gs_in_krylov_space)) result = Wavefunction(saved_lanczos_vectors[0].left_dim, saved_lanczos_vectors[0].right_dim) result.set_to_zero() for i in range(len(saved_lanczos_vectors)): result.as_matrix += ( coefficients_of_gs_in_krylov_space[i] * saved_lanczos_vectors[i].as_matrix ) result.normalize() return result
def apply(self, wf): """ Applies the composite operator to a wavefunction. Applies each of the operator components that form the composite operator and sums up the results. 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 self.list_of_components is empty. Examples -------- >>> import numpy as np >>> from dmrg101.core.operators import CompositeOperator >>> from dmrg101.core.wavefunction import Wavefunction >>> wf = Wavefunction(2, 2) >>> wf.randomize() >>> identity_operator = CompositeOperator(2, 2) >>> identity_operator.add(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 not self.list_of_components: raise DMRGException("Composite operator is empty.") result = Wavefunction(self.left_dim, self.right_dim) result.set_to_zero() for component in self.list_of_components: result.as_matrix += component.apply(wf).as_matrix return result
def apply(self, wf): """ Applies the composite operator to a wavefunction. Applies each of the operator components that form the composite operator and sums up the results. 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 self.list_of_components is empty. Examples -------- >>> import numpy as np >>> from dmrg101.core.operators import CompositeOperator >>> from dmrg101.core.wavefunction import Wavefunction >>> wf = Wavefunction(2, 2) >>> wf.randomize() >>> identity_operator = CompositeOperator(2, 2) >>> identity_operator.add(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 not self.list_of_components: raise DMRGException("Composite operator is empty.") result = Wavefunction(self.left_dim, self.right_dim) result.set_to_zero() for component in self.list_of_components: result.as_matrix += component.apply(wf).as_matrix return result