# Linear solver algorithms¶

Warning

Some algorithms may require the installation of GEMSEO with all its features and some others may depend on plugins.

Note

All the features of the wrapped optimization libraries may not be exposed through GEMSEO.

## BICG¶

Module: `gemseo.algos.linear_solvers.lib_scipy_linalg`

Linear solver implemented in the SciPy library.

More details about the algorithm and its options on https://docs.scipy.org/doc/scipy/reference/generated/BICG.html.

- Optional parameters
**atol**:*float | None, optional*The absolute tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to None.

**inner_m**:*int, optional*By default it is set to 30.

**max_iter**:*int, optional*The maximum number of iterations.

By default it is set to 1000.

**outer_k**:*int, optional*The number of vectors to carry between inner GMRES iterations.

By default it is set to 3.

**outer_v**:*list[tuple] | None, optional*The data used to augment the Krylov subspace.

By default it is set to None.

**preconditioner**:*ndarray | LinearOperator | None, optional*The preconditionner, approximation of RHS^-1. If None, no preconditioner is used.

By default it is set to None.

**prepend_outer_v**:*bool, optional*Whether to put outer_v augmentation vectors before the Krylov iterates.

By default it is set to False.

**save_when_fail**:*bool, optional*Whether to save the linear system to the disk when the solver failed to converge.

By default it is set to False.

**store_outer_av**:*bool, optional*The description is missing.

By default it is set to True.

**store_residuals**:*bool, optional*Whether to store the residuals convergence history.

By default it is set to False.

**tol**:*float, optional*The relative tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to 1e-12.

**use_ilu_precond**:*bool, optional*Whether to use superLU to compute an incomplete LU factorization as preconditioner. inner_m int: The number of inner GMRES iterations per outer iteration.

By default it is set to True.

**x0**:*ndarray | None, optional*The initial guess for the solution. M{sparse matrix, dense matrix, LinearOperator}. If None, solvers usually start from the null vector.

By default it is set to None.

## BICGSTAB¶

Module: `gemseo.algos.linear_solvers.lib_scipy_linalg`

Linear solver implemented in the SciPy library.

More details about the algorithm and its options on https://docs.scipy.org/doc/scipy/reference/generated/BICGSTAB.html.

- Optional parameters
**atol**:*float | None, optional*The absolute tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to None.

**inner_m**:*int, optional*By default it is set to 30.

**max_iter**:*int, optional*The maximum number of iterations.

By default it is set to 1000.

**outer_k**:*int, optional*The number of vectors to carry between inner GMRES iterations.

By default it is set to 3.

**outer_v**:*list[tuple] | None, optional*The data used to augment the Krylov subspace.

By default it is set to None.

**preconditioner**:*ndarray | LinearOperator | None, optional*The preconditionner, approximation of RHS^-1. If None, no preconditioner is used.

By default it is set to None.

**prepend_outer_v**:*bool, optional*Whether to put outer_v augmentation vectors before the Krylov iterates.

By default it is set to False.

**save_when_fail**:*bool, optional*Whether to save the linear system to the disk when the solver failed to converge.

By default it is set to False.

**store_outer_av**:*bool, optional*The description is missing.

By default it is set to True.

**store_residuals**:*bool, optional*Whether to store the residuals convergence history.

By default it is set to False.

**tol**:*float, optional*The relative tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to 1e-12.

**use_ilu_precond**:*bool, optional*Whether to use superLU to compute an incomplete LU factorization as preconditioner. inner_m int: The number of inner GMRES iterations per outer iteration.

By default it is set to True.

**x0**:*ndarray | None, optional*The initial guess for the solution. M{sparse matrix, dense matrix, LinearOperator}. If None, solvers usually start from the null vector.

By default it is set to None.

## DEFAULT¶

Module: `gemseo.algos.linear_solvers.lib_scipy_linalg`

This starts by LGMRES, but if it fails, switches to GMRES, then direct method super LU factorization.

More details about the algorithm and its options on https://docs.scipy.org/doc/scipy/reference/generated/DEFAULT.html.

- Optional parameters
**atol**:*float | None, optional*The absolute tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to None.

**inner_m**:*int, optional*By default it is set to 30.

**max_iter**:*int, optional*The maximum number of iterations.

By default it is set to 1000.

**outer_k**:*int, optional*The number of vectors to carry between inner GMRES iterations.

By default it is set to 3.

**outer_v**:*list[tuple] | None, optional*The data used to augment the Krylov subspace.

By default it is set to None.

**preconditioner**:*ndarray | LinearOperator | None, optional*The preconditionner, approximation of RHS^-1. If None, no preconditioner is used.

By default it is set to None.

**prepend_outer_v**:*bool, optional*Whether to put outer_v augmentation vectors before the Krylov iterates.

By default it is set to False.

**save_when_fail**:*bool, optional*Whether to save the linear system to the disk when the solver failed to converge.

By default it is set to False.

**store_outer_av**:*bool, optional*The description is missing.

By default it is set to True.

**store_residuals**:*bool, optional*Whether to store the residuals convergence history.

By default it is set to False.

**tol**:*float, optional*The relative tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to 1e-12.

**use_ilu_precond**:*bool, optional*Whether to use superLU to compute an incomplete LU factorization as preconditioner. inner_m int: The number of inner GMRES iterations per outer iteration.

By default it is set to True.

**x0**:*ndarray | None, optional*The initial guess for the solution. M{sparse matrix, dense matrix, LinearOperator}. If None, solvers usually start from the null vector.

By default it is set to None.

## GMRES¶

Module: `gemseo.algos.linear_solvers.lib_scipy_linalg`

Linear solver implemented in the SciPy library.

More details about the algorithm and its options on https://docs.scipy.org/doc/scipy/reference/generated/GMRES.html.

- Optional parameters
**atol**:*float | None, optional*The absolute tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to None.

**inner_m**:*int, optional*By default it is set to 30.

**max_iter**:*int, optional*The maximum number of iterations.

By default it is set to 1000.

**outer_k**:*int, optional*The number of vectors to carry between inner GMRES iterations.

By default it is set to 3.

**outer_v**:*list[tuple] | None, optional*The data used to augment the Krylov subspace.

By default it is set to None.

**preconditioner**:*ndarray | LinearOperator | None, optional*The preconditionner, approximation of RHS^-1. If None, no preconditioner is used.

By default it is set to None.

**prepend_outer_v**:*bool, optional*Whether to put outer_v augmentation vectors before the Krylov iterates.

By default it is set to False.

**save_when_fail**:*bool, optional*Whether to save the linear system to the disk when the solver failed to converge.

By default it is set to False.

**store_outer_av**:*bool, optional*The description is missing.

By default it is set to True.

**store_residuals**:*bool, optional*Whether to store the residuals convergence history.

By default it is set to False.

**tol**:*float, optional*The relative tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to 1e-12.

**use_ilu_precond**:*bool, optional*By default it is set to True.

**x0**:*ndarray | None, optional*By default it is set to None.

## LGMRES¶

Module: `gemseo.algos.linear_solvers.lib_scipy_linalg`

Linear solver implemented in the SciPy library.

More details about the algorithm and its options on https://docs.scipy.org/doc/scipy/reference/generated/LGMRES.html.

- Optional parameters
**atol**:*float | None, optional*The absolute tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to None.

**inner_m**:*int, optional*By default it is set to 30.

**max_iter**:*int, optional*The maximum number of iterations.

By default it is set to 1000.

**outer_k**:*int, optional*The number of vectors to carry between inner GMRES iterations.

By default it is set to 3.

**outer_v**:*list[tuple] | None, optional*The data used to augment the Krylov subspace.

By default it is set to None.

**preconditioner**:*ndarray | LinearOperator | None, optional*The preconditionner, approximation of RHS^-1. If None, no preconditioner is used.

By default it is set to None.

**prepend_outer_v**:*bool, optional*Whether to put outer_v augmentation vectors before the Krylov iterates.

By default it is set to False.

**save_when_fail**:*bool, optional*Whether to save the linear system to the disk when the solver failed to converge.

By default it is set to False.

**store_outer_av**:*bool, optional*The description is missing.

By default it is set to True.

**store_residuals**:*bool, optional*Whether to store the residuals convergence history.

By default it is set to False.

**tol**:*float, optional*The relative tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to 1e-12.

**use_ilu_precond**:*bool, optional*By default it is set to True.

**x0**:*ndarray | None, optional*By default it is set to None.

## PETSC_KSP¶

Note

The plugin gemseo_petsc is required.

Module: `gemseo_petsc.linear_solvers.ksp_lib`

- Optional parameters
**atol**:*float, optional*The absolute convergence tolerance of the (possibly preconditioned) residual norm.

By default it is set to 1e-50.

**dtol**:*float, optional*The divergence tolerance, e.g. the amount the (possibly preconditioned) residual norm can increase.

By default it is set to 100000.0.

**ksp_pre_processor**:*bool | None, optional*A callback function that is called with (KSP problem, options dict) as arguments before calling ksp.solve(). It allows the user to obtain an advanced configuration that is not supported by the current wrapper. If None, do not perform any call.

By default it is set to None.

**max_iter**:*int, optional*The maximum number of iterations.

By default it is set to 100000.

**monitor_residuals**:*bool, optional*Whether to store the residuals during convergence. WARNING: as said in Petsc documentation, “the routine is slow and should be used only for testing or convergence studies, not for timing.”

By default it is set to False.

**options_cmd**:*dict[str, Any] | None, optional*The options to pass to the PETSc KSP solver. If None, use the default options.

By default it is set to None.

**preconditioner_type**:*str, optional*The type of the precondtioner, see `https://www.mcs.anl.gov/petsc/petsc4py-current/docs/apiref/petsc4py.PETSc.PC.Type-class.html`_ # noqa: B950

By default it is set to ilu.

**set_from_options**:*bool, optional*Whether the options are set from sys.argv, a classical Petsc configuration mode.

By default it is set to False.

**solver_type**:*str, optional*The KSP solver type. See `https://petsc.org/release/docs/manualpages/KSP/KSPType.html#KSPType`_

By default it is set to gmres.

**tol**:*float, optional*The relative convergence tolerance, relative decrease in the (possibly preconditioned) residual norm.

By default it is set to 1e-05.

**view_config**:*bool, optional*Whether to call ksp.view() to view the configuration of the solver before run.

By default it is set to False.

## QMR¶

Module: `gemseo.algos.linear_solvers.lib_scipy_linalg`

Linear solver implemented in the SciPy library.

More details about the algorithm and its options on https://docs.scipy.org/doc/scipy/reference/generated/QMR.html.

- Optional parameters
**atol**:*float | None, optional*The absolute tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to None.

**inner_m**:*int, optional*By default it is set to 30.

**max_iter**:*int, optional*The maximum number of iterations.

By default it is set to 1000.

**outer_k**:*int, optional*The number of vectors to carry between inner GMRES iterations.

By default it is set to 3.

**outer_v**:*list[tuple] | None, optional*The data used to augment the Krylov subspace.

By default it is set to None.

**preconditioner**:*ndarray | LinearOperator | None, optional*The preconditionner, approximation of RHS^-1. If None, no preconditioner is used.

By default it is set to None.

**prepend_outer_v**:*bool, optional*Whether to put outer_v augmentation vectors before the Krylov iterates.

By default it is set to False.

**save_when_fail**:*bool, optional*Whether to save the linear system to the disk when the solver failed to converge.

By default it is set to False.

**store_outer_av**:*bool, optional*The description is missing.

By default it is set to True.

**store_residuals**:*bool, optional*Whether to store the residuals convergence history.

By default it is set to False.

**tol**:*float, optional*The relative tolerance for convergence, norm(RHS.dot(sol)) <= max(tol*norm(LHS), atol).

By default it is set to 1e-12.

**use_ilu_precond**:*bool, optional*By default it is set to True.

**x0**:*ndarray | None, optional*By default it is set to None.