Beispiel #1
0
def test_hamiltonian_solver_stress_eigval_sep(a_sep):
    BIGDIM = 100
    nroot = 3
    guess = list(np.random.randn(BIGDIM, nroot).T)
    test_engine = HSProblemSimulate(BIGDIM, a_sep=a_sep, b_sep=a_sep / 10)
    test_vals, test_rvecs, test_lvecs, _ = hamiltonian_solver(
        engine=test_engine,
        guess=guess,
        nroot=nroot,
        # Don't let the ss grow to size of real thing
        max_vecs_per_root=20,
        # Don't assault stdout with logging
        verbose=0,
        maxiter=1000)

    assert test_vals is not None, "The solver failed to converge"

    # compute the reference values, Use the partially reduced non-hermitian form of the problem, solve for RH-eigenvectors
    ref_H = np.dot(test_engine.A - test_engine.B,
                   test_engine.A + test_engine.B)
    ref_vals, ref_rvecs = np.linalg.eig(ref_H)
    # Associated eigenvalues are the squares of the 2N dimensional problem
    ref_vals = np.sqrt(ref_vals)
    # sort the values/vectors
    sort_idx = ref_vals.argsort()
    ref_vals = ref_vals[sort_idx]
    ref_rvecs = ref_rvecs[:, sort_idx]

    # truncate to number of roots found
    ref_vals = ref_vals[:nroot]
    ref_rvecs = ref_rvecs[:, :nroot]

    # compare values
    compare_arrays(ref_vals, test_vals, 5, "Hamiltonian Eigenvalues")
Beispiel #2
0
 def rpa_solver(e, n, g, m):
     return solvers.hamiltonian_solver(engine=e,
                                       nroot=n,
                                       guess=g,
                                       r_convergence=r_convergence,
                                       max_ss_size=max_vecs_per_root * n,
                                       verbose=verbose)
Beispiel #3
0
def test_hamiltonian_solver_stress_eigval_sep(a_sep):
    BIGDIM = 100
    nroot = 3
    guess = list(np.random.randn(BIGDIM, nroot).T)
    test_engine = HSProblemSimulate(BIGDIM, a_sep=a_sep, b_sep=a_sep / 10)
    test_vals, test_rvecs, test_lvecs, _ = hamiltonian_solver(
        engine=test_engine,
        guess=guess,
        nroot=nroot,
        # Don't let the ss grow to size of real thing
        max_vecs_per_root=20,
        # Don't assault stdout with logging
        verbose=0,
        maxiter=1000)

    assert test_vals is not None, "The solver failed to converge"

    # compute the reference values, Use the partially reduced non-hermitian form of the problem, solve for RH-eigenvectors
    ref_H = np.dot(test_engine.A - test_engine.B, test_engine.A + test_engine.B)
    ref_vals, ref_rvecs = np.linalg.eig(ref_H)
    # Associated eigenvalues are the squares of the 2N dimensional problem
    ref_vals = np.sqrt(ref_vals)
    # sort the values/vectors
    sort_idx = ref_vals.argsort()
    ref_vals = ref_vals[sort_idx]
    ref_rvecs = ref_rvecs[:, sort_idx]

    # truncate to number of roots found
    ref_vals = ref_vals[:nroot]
    ref_rvecs = ref_rvecs[:, :nroot]

    # compare values
    compare_arrays(ref_vals, test_vals, 5, "Hamiltonian Eigenvalues")
Beispiel #4
0
def test_hamiltonian_solver():
    BIGDIM = 100
    nroot = 3
    guess = list(np.eye(BIGDIM)[:, :nroot * 2].T)
    test_engine = HSProblemSimulate(BIGDIM)
    ret = hamiltonian_solver(
        engine=test_engine,
        guess=guess,
        nroot=nroot,
        # Don't let the ss grow to size of real thing
        max_ss_size=20,
        # Don't assault stdout with logging
        verbose=0,
        maxiter=100)

    test_vals = ret["eigvals"]
    assert test_vals is not None, "The solver failed to converge"

    # compute the reference values, Use the partially reduced non-hermitian form of the problem, solve for RH-eigenvectors
    ref_H = np.dot(test_engine.A - test_engine.B,
                   test_engine.A + test_engine.B)
    ref_vals, ref_rvecs = np.linalg.eig(ref_H)
    # Associated eigenvalues are the squares of the 2N dimensional problem
    ref_vals = np.sqrt(ref_vals)
    # sort the values/vectors
    sort_idx = ref_vals.argsort()
    ref_vals = ref_vals[sort_idx]
    ref_rvecs = ref_rvecs[:, sort_idx]

    # truncate to number of roots found
    ref_vals = ref_vals[:nroot]
    ref_rvecs = ref_rvecs[:, :nroot]

    # compare values
    compare_arrays(ref_vals, test_vals, 5, "Hamiltonian Eigenvalues")

    # compare roots
    # NOTE: The returned eigenvectors are a list of (whatever the engine used is using for a vector)
    # So in this case, we need to put the columns together into a matrix to compare directly to the np.LA.eig result
    test_rvecs = [x[0] for x in ret["eigvecs"]]
    compare_arrays(ref_rvecs, np.column_stack(test_rvecs), 6,
                   "Hamiltonian Right Eigenvectors")

    #Can't compute LH eigenvectors with numpy but we have the RH, and the matrix
    # solver computed Vl^T * H
    test_lvecs = [x[1] for x in ret["eigvecs"]]
    vl_T_H = np.column_stack(
        [np.dot(test_lvecs[i], ref_H) for i in range(nroot)])
    # value * right_vector (should not matter which one since we just checked them equal)
    w_Vr = np.column_stack(
        [test_rvecs[i] * test_vals[i] for i in range(nroot)])
    #compare
    compare_arrays(vl_T_H, w_Vr, 6, "Hamiltonian Left Eigenvectors")
Beispiel #5
0
def test_hamiltonian_solver():
    BIGDIM = 100
    nroot = 3
    guess = list(np.eye(BIGDIM)[:, :nroot * 2].T)
    test_engine = HSProblemSimulate(BIGDIM)
    test_vals, test_rvecs, test_lvecs, _ = hamiltonian_solver(
        engine=test_engine,
        guess=guess,
        nroot=nroot,
        # Don't let the ss grow to size of real thing
        max_vecs_per_root=20,
        # Don't assault stdout with logging
        verbose=0,
        maxiter=100)

    assert test_vals is not None, "The solver failed to converge"

    # compute the reference values, Use the partially reduced non-hermitian form of the problem, solve for RH-eigenvectors
    ref_H = np.dot(test_engine.A - test_engine.B, test_engine.A + test_engine.B)
    ref_vals, ref_rvecs = np.linalg.eig(ref_H)
    # Associated eigenvalues are the squares of the 2N dimensional problem
    ref_vals = np.sqrt(ref_vals)
    # sort the values/vectors
    sort_idx = ref_vals.argsort()
    ref_vals = ref_vals[sort_idx]
    ref_rvecs = ref_rvecs[:, sort_idx]

    # truncate to number of roots found
    ref_vals = ref_vals[:nroot]
    ref_rvecs = ref_rvecs[:, :nroot]

    # compare values
    compare_arrays(ref_vals, test_vals, 5, "Hamiltonian Eigenvalues")

    # compare roots
    # NOTE: The returned eigenvectors are a list of (whatever the engine used is using for a vector)
    # So in this case, we need to put the columns together into a matrix to compare directly to the np.LA.eig result
    compare_arrays(ref_rvecs, np.column_stack(test_rvecs), 6, "Hamiltonian Right Eigenvectors")

    #Can't compute LH eigenvectors with numpy but we have the RH, and the matrix
    # solver computed Vl^T * H
    vl_T_H = np.column_stack([np.dot(test_lvecs[i], ref_H) for i in range(nroot)])
    # value * right_vector (should not matter which one since we just checked them equal)
    w_Vr = np.column_stack([test_rvecs[i] * test_vals[i] for i in range(nroot)])
    #compare
    compare_arrays(vl_T_H, w_Vr, 6, "Hamiltonian Left Eigenvectors")