예제 #1
0
def lanczos_nth_iteration(alpha, beta, lv, saved_lanczos_vectors, hamiltonian,
                          iteration):
    """Performs the n-th iteration for the Lanczos.

    It calculates the new values for `alpha` and `beta` for this
    `iteration`.

    Parameters
    ----------
    alpha : a list of doubles.
        The alpha's in the Lanczos algorithm.
    beta :  a list of doubles.
        The beta's in the Lanczos algorithm.
    lv : the 3 tuple of Wavefunctions.
        With the three Lanczos vectors in use.
    saved_lanczos_vectors : a list of Wavefunctions.
        The Lanczos vectors that are saved.
    hamiltonian : a CompositeOperator
        The hamiltonian you want to diagonalize.
    iteration : an int
        The iteration number.

    Notes
    -----
    Postcond : The 3rd Lanczos vector in the tuple is modified. The first
    two are *not*.

    Raises
    ------
    DMRGException 
        if `alpha.size` is not equal to `beta.size` 
    """
    if len(alpha) != len(beta):
        DMRGException("alpha and beta have wrong sizes")

    lv[2] = hamiltonian.apply(lv[1])
    alpha.append(get_real(braket(lv[1], lv[2])))
    lv[2].as_matrix -= (alpha[iteration] * lv[1].as_matrix +
                        beta[iteration - 1] * lv[0].as_matrix)
    beta.append(lv[2].get_norm())
    lv[2].normalize()
    cycle_lanczos_vectors(lv, saved_lanczos_vectors)
    assert (len(alpha) == iteration + 1)
    assert (len(beta) == iteration + 1)
예제 #2
0
def lanczos_nth_iteration(alpha, beta, lv, saved_lanczos_vectors,
		          hamiltonian, iteration):
    """Performs the n-th iteration for the Lanczos.

    It calculates the new values for `alpha` and `beta` for this
    `iteration`.

    Parameters
    ----------
    alpha : a list of doubles.
        The alpha's in the Lanczos algorithm.
    beta :  a list of doubles.
        The beta's in the Lanczos algorithm.
    lv : the 3 tuple of Wavefunctions.
        With the three Lanczos vectors in use.
    saved_lanczos_vectors : a list of Wavefunctions.
        The Lanczos vectors that are saved.
    hamiltonian : a CompositeOperator
        The hamiltonian you want to diagonalize.
    iteration : an int
        The iteration number.

    Notes
    -----
    Postcond : The 3rd Lanczos vector in the tuple is modified. The first
    two are *not*.

    Raises
    ------
    DMRGException 
        if `alpha.size` is not equal to `beta.size` 
    """
    if len(alpha) != len(beta):
        DMRGException("alpha and beta have wrong sizes")

    lv[2] = hamiltonian.apply(lv[1])
    alpha.append(get_real(braket(lv[1], lv[2])))
    lv[2].as_matrix -= (alpha[iteration]*lv[1].as_matrix +
    		        beta[iteration-1]*lv[0].as_matrix)
    beta.append(lv[2].get_norm())
    lv[2].normalize()
    cycle_lanczos_vectors(lv, saved_lanczos_vectors)
    assert(len(alpha) == iteration + 1)
    assert(len(beta) == iteration + 1)
예제 #3
0
def lanczos_zeroth_iteration(alpha, beta, lv, hamiltonian):
    """Performs the zero-th iteration for the Lanczos.

    The zero-th (i.e. the first at all) Lanczos iteration is slightly
    different to the rest.

    Parameters
    ----------
    alpha : a list of doubles.
        The alpha's in the Lanczos algorithm.
    beta :  a list of doubles.
        The beta's in the Lanczos algorithm.
    lv : a 3-tuple of numpy arrays of ndim = 2.
        The Lanczos vectors.
    hamiltonian : a CompositeOperator
        The hamiltonian you want to diagonalize.

    Returns
    -------
    already_the_ground_state : a bool
        Whether the zeroth iteration gives you the ground state. This
	happens when the initial wavefunction for the Lanczos is already
	the groudn state.
    
    Raises
    ------
    DMRGException :
        if the `alpha` or `beta` lists are not empty.
    """
    if alpha and beta:
        raise DMRGException("Lists not empty at zeroth Lanczos iter")
    lv[1] = hamiltonian.apply(lv[0])
    alpha.append(get_real(braket(lv[0], lv[1])))
    lv[1].as_matrix -= alpha[0] * lv[0].as_matrix
    beta.append(lv[1].get_norm())
    lv[1].normalize()
    assert (len(alpha) == 1)
    assert (len(beta) == 1)
    already_the_ground_state = (beta[0] < float_info.epsilon)
    return already_the_ground_state
예제 #4
0
def lanczos_zeroth_iteration(alpha, beta, lv, hamiltonian):
    """Performs the zero-th iteration for the Lanczos.

    The zero-th (i.e. the first at all) Lanczos iteration is slightly
    different to the rest.

    Parameters
    ----------
    alpha : a list of doubles.
        The alpha's in the Lanczos algorithm.
    beta :  a list of doubles.
        The beta's in the Lanczos algorithm.
    lv : a 3-tuple of numpy arrays of ndim = 2.
        The Lanczos vectors.
    hamiltonian : a CompositeOperator
        The hamiltonian you want to diagonalize.

    Returns
    -------
    already_the_ground_state : a bool
        Whether the zeroth iteration gives you the ground state. This
	happens when the initial wavefunction for the Lanczos is already
	the groudn state.
    
    Raises
    ------
    DMRGException :
        if the `alpha` or `beta` lists are not empty.
    """
    if alpha and beta:
        raise DMRGException("Lists not empty at zeroth Lanczos iter")
    lv[1] = hamiltonian.apply(lv[0])
    alpha.append(get_real(braket(lv[0], lv[1])))
    lv[1].as_matrix -= alpha[0]*lv[0].as_matrix
    beta.append(lv[1].get_norm())
    lv[1].normalize()
    assert(len(alpha) == 1)
    assert(len(beta) == 1)
    already_the_ground_state = ( beta[0] < float_info.epsilon )
    return already_the_ground_state