cg_solver

psi4.driver.p4util.cg_solver(rhs_vec, hx_function, preconditioner, guess=None, printer=None, printlvl=1, maxiter=20, rcond=1e-06)[source]

Solves the \(Ax = b\) linear equations via Conjugate Gradient. The A matrix must be a hermitian, positive definite matrix.

Parameters:
  • rhs_vec (List[Matrix]) – The RHS vector in the Ax=b equation.

  • hx_function (Callable) – Takes in a list of Matrix objects and a mask of active indices. Returns the Hessian-vector product.

  • preconditioner (Callable) – Takes in a list of Matrix objects and a mask of active indices. Returns the preconditioned value.

  • guess (Optional[List[Matrix]]) – Starting vectors. If None, use a preconditioner (rhs) guess

  • printer (Optional[Callable]) – Takes in a list of current x and residual vectors and provides a print function. This function can also return a value that represents the current residual.

  • printlvl (int) – The level of printing provided by this function.

  • maxiter (int) – The maximum number of iterations this function will take.

  • rcond (float) – The residual norm for convergence.

Returns:

ret – Solved x vectors and r vectors.

Return type:

List[Matrix]

Notes

This is a generalized cg solver that can also take advantage of solving multiple RHS’s simultaneously when it is advantageous to do so.