Skip to content

liblaf.peach.linalg.base

Base protocols and result containers for linear solvers.

Classes:

  • BaseProblem

    Marker protocol for linear-system problems.

  • LinearSolver

    Base class for linear solvers.

  • Problem

    Protocol for a linear system A x = b.

  • Result

    Result code returned by linear solvers.

  • Solution

    Linear-solver output bundle.

  • State

    Protocol for solver states that expose solution parameters.

  • Stats

    Protocol for solver-specific summary statistics.

BaseProblem

Bases: Protocol


              flowchart TD
              liblaf.peach.linalg.base.BaseProblem[BaseProblem]

              

              click liblaf.peach.linalg.base.BaseProblem href "" "liblaf.peach.linalg.base.BaseProblem"
            

Marker protocol for linear-system problems.

LinearSolver

Base class for linear solvers.

Methods:

  • compute

    Run one complete solve from an initialized state.

  • init

    Create solver state from an initial parameter vector.

  • postprocess

    Wrap final state and result metadata in a solution object.

  • solve

    Initialize, compute, and postprocess a linear solve.

compute

compute(problem: BaseProblem, state: S) -> Result

Run one complete solve from an initialized state.

Source code in src/liblaf/peach/linalg/base/_solver.py
def compute(self, problem: BaseProblem, state: S) -> Result:
    """Run one complete solve from an initialized state."""
    raise NotImplementedError

init

init(problem: BaseProblem, params: Vector) -> S

Create solver state from an initial parameter vector.

Source code in src/liblaf/peach/linalg/base/_solver.py
def init(self, problem: BaseProblem, params: Vector) -> S:
    """Create solver state from an initial parameter vector."""
    raise NotImplementedError

postprocess

postprocess(
    problem: BaseProblem, state: S, result: Result
) -> Solution[S, T]

Wrap final state and result metadata in a solution object.

Source code in src/liblaf/peach/linalg/base/_solver.py
def postprocess(
    self, problem: BaseProblem, state: S, result: Result
) -> Solution[S, T]:
    """Wrap final state and result metadata in a solution object."""
    del problem
    stats: T = cast("T", self.Stats())  # ty:ignore[call-non-callable]
    return Solution(result=result, state=state, stats=stats)

solve

solve(
    problem: BaseProblem, params: Vector
) -> Solution[S, T]

Initialize, compute, and postprocess a linear solve.

Source code in src/liblaf/peach/linalg/base/_solver.py
def solve(self, problem: BaseProblem, params: Vector) -> Solution[S, T]:
    """Initialize, compute, and postprocess a linear solve."""
    state: S = self.init(problem, params)
    result: Result = self.compute(problem, state)
    return self.postprocess(problem, state, result)

Problem

Bases: Protocol


              flowchart TD
              liblaf.peach.linalg.base.Problem[Problem]

              

              click liblaf.peach.linalg.base.Problem href "" "liblaf.peach.linalg.base.Problem"
            

Protocol for a linear system A x = b.

Methods:

  • matvec

    Apply the system matrix to x.

  • precondition

    Apply an optional left preconditioner to x.

  • rmatvec

    Apply the transpose or adjoint system matrix to x.

  • rprecondition

    Apply an optional transpose or adjoint preconditioner to x.

Attributes:

  • b (Vector) –

    Right-hand-side vector.

b property

b: Vector

Right-hand-side vector.

matvec

matvec(x: Vector) -> Vector

Apply the system matrix to x.

Source code in src/liblaf/peach/linalg/base/_problem.py
@not_implemented
def matvec(self, x: Vector, /) -> Vector:
    """Apply the system matrix to `x`."""

precondition

precondition(x: Vector) -> Vector

Apply an optional left preconditioner to x.

Source code in src/liblaf/peach/linalg/base/_problem.py
@not_implemented
def precondition(self, x: Vector, /) -> Vector:
    """Apply an optional left preconditioner to `x`."""

rmatvec

rmatvec(x: Vector) -> Vector

Apply the transpose or adjoint system matrix to x.

Source code in src/liblaf/peach/linalg/base/_problem.py
@not_implemented
def rmatvec(self, x: Vector, /) -> Vector:
    """Apply the transpose or adjoint system matrix to `x`."""

rprecondition

rprecondition(x: Vector) -> Vector

Apply an optional transpose or adjoint preconditioner to x.

Source code in src/liblaf/peach/linalg/base/_problem.py
@not_implemented
def rprecondition(self, x: Vector, /) -> Vector:
    """Apply an optional transpose or adjoint preconditioner to `x`."""

Result

Bases: StrEnum


              flowchart TD
              liblaf.peach.linalg.base.Result[Result]

              

              click liblaf.peach.linalg.base.Result href "" "liblaf.peach.linalg.base.Result"
            

Result code returned by linear solvers.

Attributes:

BREAKDOWN class-attribute instance-attribute

BREAKDOWN = auto()

MAX_STEPS_REACHED class-attribute instance-attribute

MAX_STEPS_REACHED = auto()

PRIMARY_SUCCESS class-attribute instance-attribute

PRIMARY_SUCCESS = auto()

SECONDARY_SUCCESS class-attribute instance-attribute

SECONDARY_SUCCESS = auto()

SUCCESS class-attribute instance-attribute

SUCCESS = auto()

UNKNOWN_ERROR class-attribute instance-attribute

UNKNOWN_ERROR = auto()

success property

success: bool

Whether the result represents an accepted solution.

Solution

Linear-solver output bundle.

Parameters:

  • result (Result) –
  • state (S) –
  • stats (T) –

Attributes:

params property

params: Vector

Final solution parameters.

result instance-attribute

result: Result

state instance-attribute

state: S

stats instance-attribute

stats: T

success property

success: bool

Whether result is successful.

State

Bases: Protocol


              flowchart TD
              liblaf.peach.linalg.base.State[State]

              

              click liblaf.peach.linalg.base.State href "" "liblaf.peach.linalg.base.State"
            

Protocol for solver states that expose solution parameters.

Attributes:

  • params (Vector) –

    Current solution estimate.

params property

params: Vector

Current solution estimate.

Stats

Bases: Protocol


              flowchart TD
              liblaf.peach.linalg.base.Stats[Stats]

              

              click liblaf.peach.linalg.base.Stats href "" "liblaf.peach.linalg.base.Stats"
            

Protocol for solver-specific summary statistics.