Example #1
0
def calculate_ground_state(hamiltonian,
                           initial_wf=None,
                           min_lanczos_iterations=3,
                           too_many_iterations=1000,
                           precision=0.000001):
    """Calculates the ground state energy and wavefunction.

    Parameters
    ----------
    hamiltonian : a CompositeOperator
        The hamiltonian you want to diagonalize.
    initial_wf : a Wavefunction, optional
        The wavefunction that will be used as seed. If None, a random one
	if used.
    min_lanczos_iterations : an int, optional.
        The number of iterations before starting the diagonalizations.
    too_many_iterations : a int, optional.
        The maximum number of iterations allowed.
    precision : a double, optional.
        The accepted precision to which the ground state energy is
	considered not improving.
    
    Returns 
    -------
    gs_energy : a double.
        The ground state energy.
    gs_wf : a Wavefunction.
        The ground state wavefunction (normalized.)
    """
    if initial_wf is None:
        initial_wf = Wavefunction(hamiltonian.left_dim, hamiltonian.right_dim)
        initial_wf.randomize()

    gs_energy, d, e, saved_lanczos_vectors = (calculate_ground_state_energy(
        hamiltonian, initial_wf, min_lanczos_iterations, too_many_iterations,
        precision))
    gs_wf = calculate_ground_state_wf(d, e, saved_lanczos_vectors)

    return gs_energy, gs_wf
Example #2
0
def calculate_ground_state(hamiltonian, initial_wf = None, 
			   min_lanczos_iterations = 3, 
		           too_many_iterations = 1000, 
			   precision = 0.000001):
    """Calculates the ground state energy and wavefunction.

    Parameters
    ----------
    hamiltonian : a CompositeOperator
        The hamiltonian you want to diagonalize.
    initial_wf : a Wavefunction, optional
        The wavefunction that will be used as seed. If None, a random one
	if used.
    min_lanczos_iterations : an int, optional.
        The number of iterations before starting the diagonalizations.
    too_many_iterations : a int, optional.
        The maximum number of iterations allowed.
    precision : a double, optional.
        The accepted precision to which the ground state energy is
	considered not improving.
    
    Returns 
    -------
    gs_energy : a double.
        The ground state energy.
    gs_wf : a Wavefunction.
        The ground state wavefunction (normalized.)
    """
    if initial_wf is None:
        initial_wf = Wavefunction(hamiltonian.left_dim,
			          hamiltonian.right_dim)
	initial_wf.randomize()

    gs_energy, d, e, saved_lanczos_vectors = (
        calculate_ground_state_energy(hamiltonian, initial_wf, min_lanczos_iterations, 
		                      too_many_iterations, precision) )
    gs_wf = calculate_ground_state_wf(d, e, saved_lanczos_vectors)

    return gs_energy, gs_wf