gemseo.algos.linear_solvers.linear_problem module#

Linear equations problem.

class LinearProblem(lhs, rhs=None, solution=None, is_symmetric=False, is_positive_def=False, is_converged=None)[source]#

Bases: BaseProblem

Representation of the linear equations' system \(Ax = b\).

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

Parameters:
  • lhs (SparseOrDenseRealArray | LinearOperator) -- The left-hand side (matrix or linear operator) of the problem.

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

  • solution (NumberArray | None) -- The current solution.

  • is_symmetric (bool) --

    Whether the left-hand side is symmetric.

    By default it is set to False.

  • is_positive_def (bool) --

    Whether the left-hand side is positive definite.

    By default it is set to False.

  • is_converged (bool | None) -- Whether the solution is converged to the specified tolerance. If False, the algorithm stopped before convergence. If None, no run was performed.

check()[source]#

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

Raises:

ValueError -- When the shapes are inconsistent.

Return type:

None

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

Compute the Euclidean norm of the residual.

Parameters:
  • relative_residuals (bool) --

    If True, one computes :math:` |A x_k - b|_2 / |b|_2`, else :math:` |A x_k - b|_2`.

    By default it is set to True.

  • store (bool) --

    Whether to store the residual norm in the history.

    By default it is set to False.

  • current_x (NumberArray | None) -- Compute the residuals associated with current_x, If None, compute then from the solution attribute.

Returns:

The residual norm.

Raises:
Return type:

floating[Any]

plot_residuals()[source]#

Plot the residuals' convergence in log scale.

Returns:

The matplotlib figure.

Raises:

ValueError -- When the residual norm history is empty.

Return type:

Figure

convergence_info: int | str#

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

is_converged: bool | None#

Whether the solution satisfies the specified tolerance.

If None, no run was performed.

is_lhs_linear_operator: bool#

Whether the LHS is a linear operator.

is_positive_def: bool#

Whether the LHS is positive definite.

is_symmetric: bool#

Whether the LHS is symmetric.

lhs: LinearOperator | SparseOrDenseRealArray#

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[floating[Any]]#

The convergence history of residuals.

rhs: NumberArray | None#

The right-hand side of the equation.

solution: NumberArray | None#

The current solution of the problem.

solver_name: str#

The solver name.