def test_davidson_solver_numpy(): BIGDIM = 100 nroot = 3 guess = list(np.random.randn(BIGDIM, nroot).T) test_engine = DSProblemSimulate(BIGDIM) test_vals, test_vectors, _ = davidson_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, "Solver Failed to converge" ref_vals, ref_vectors = np.linalg.eigh(test_engine.A) idx = ref_vals.argsort()[:nroot] ref_vals = ref_vals[idx] ref_vectors = ref_vectors[:, idx] compare_arrays(ref_vals, test_vals, 6, "Davidson eigenvalues") # 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.eigh result compare_arrays(ref_vectors, np.column_stack(test_vectors), 8, "Davidson eigenvectors")
def tda_solver(e, n, g, m): return solvers.davidson_solver(engine=e, nroot=n, guess=g, r_convergence=r_convergence, max_ss_size=max_vecs_per_root * n, verbose=verbose)
wfn.form_D() record = [(False, wfn.compute_E())] for x in range(5): prod = SCFProducts(wfn) def func(vector): return -1 * prod.H1_product(vector) def precon(resid, i, A_w): return resid nvecs = 5 guess = np.ones((prod.narot, nvecs)) evals, evecs = davidson_solver(func, precon, guess, no_eigs=nvecs, e_conv=1.e-4) # If x == 0 we take a "bad" step, require rotation next step to get back on track if (x == 0) or (evals[0] < 0): stab = True evecs = -evecs[:, 0] rot = psi4.core.Matrix.from_array(evecs.reshape(ndocc, nvir)) wfn.rotate_orbitals(wfn.Ca(), rot) else: stab = False wfn.form_C() wfn.form_D() wfn.form_G() wfn.form_F() print(wfn.compute_E())
record = [(False, wfn.compute_E())] for x in range(5): prod = SCFProducts(wfn) def func(vector): return -1 * prod.H1_product(vector) def precon(resid, i, A_w): return resid nvecs = 5 guess = np.ones((prod.narot, nvecs)) evals, evecs = davidson_solver(func, precon, guess, no_eigs=nvecs, e_conv=1.e-4) # If x == 0 we take a "bad" step, require rotation next step to get back on track if (x == 0) or (evals[0] < 0): stab = True evecs = -evecs[:, 0] rot = psi4.core.Matrix.from_array(evecs.reshape(ndocc, nvir)) wfn.rotate_orbitals(wfn.Ca(), rot) else: stab = False wfn.form_C() wfn.form_D() wfn.form_G()