gemseo / algos / linear_solvers

linear_problem module

Linear equations problem.

class gemseo.algos.linear_solvers.linear_problem.LinearProblem(lhs, rhs=None, solution=None, is_symmetric=False, is_positive_def=False, is_converged=None)[source]

Bases: object

Representation of the linear equations’ system A.x = b.

It also contains the solution, and some properties of the system such as the symmetry or positive definiteness.

  • lhs (ndarray | spmatrix | LinearOperator) – The left-hand side (matrix or linear operator) of the problem.

  • rhs (ndarray | None) – The right-hand side (vector) of the problem.

  • solution (ndarray | None) – The current solution.

  • is_symmetric

    Whether to assume that the LHS is symmetric.

    By default it is set to False.

  • is_positive_def

    Whether to assume that the LHS is positive definite.

    By default it is set to False.

  • is_converged – Whether the solution is converged to the specified tolerance. If False, the algorithm stopped before convergence. If None, no run was performed.


Check the consistency of the dimensions of the LHS and RHS.


ValueError – When the shapes are inconsistent.

Return type:


compute_residuals(relative_residuals=True, store=False, current_x=None)[source]

Compute the L2 norm of the residuals of the problem.

  • relative_residuals

    If True, return norm(lhs.solution-rhs)/norm(rhs), else return norm(lhs.solution-rhs).

    By default it is set to True.

  • store

    Whether to store the residuals value in the residuals_history attribute.

    By default it is set to False.

  • current_x – Compute the residuals associated with current_x, If None, compute then from the solution attribute.


The residuals value.


ValueError – If self.solution is None and current_x is None.

Return type:



Plot the residuals’ convergence in log scale.


The matplotlib figure.


ValueError – When the residuals’ history is empty.

Return type:


convergence_info: int | str

The information provided by the solver if convergence occurred or not.

is_converged: bool

If the solution is_converged.

is_lhs_linear_operator: bool

Whether the LHS is symmetric.

is_positive_def: bool

Whether the LHS is positive definite.

is_symmetric: bool

Whether the LHS is symmetric.

lhs: ndarray | LinearOperator | spmatrix

The left-hand side of the equation. If None, the problem can’t be solved and the user has to set it after init.

residuals_history: list[float]

The convergence history of residuals.

rhs: ndarray

The right-hand side of the equation.

solution: ndarray

The current solution of the problem.

solver_name: str

The solver name.

solver_options: dict[str, Any]

The options passed to the solver.