neml2.solvers

Python-native linear and nonlinear solvers.

class neml2.solvers.DenseLU[source]

Bases: object

Dense LU linear solver. Assembles the (possibly) sparse matrix into a dense one and uses a standard LU decomposition.

The dense-vs-block-diagonal dispatch is implicit in the wrapped Tensor operand: Tensor.solve forwards to torch.linalg.solve on the trailing matrix dims, so leading sub-batch axes (if any) batch naturally as independent LUs per site – no special-case code at this layer.

SECTION = 'Solvers'
classmethod from_hit(node, factory)[source]
Parameters:
  • node (nmhit.Node)

  • factory (_NativeInputFile)

Return type:

DenseLU

hit = <neml2.schema.HitSchema object>
solve(A: AssembledMatrix, b: AssembledVector) AssembledVector[source]
solve(A: AssembledMatrix, b: AssembledMatrix) AssembledMatrix
class neml2.solvers.Newton(*, linear_solver=None, atol=1e-10, rtol=1e-08, miters=25, verbose=False)[source]

Bases: object

The standard Newton-Raphson solver which always takes the ‘full’ Newton step.

Parameters:
SECTION = 'Solvers'

Inherited by NewtonWithLineSearch.

classmethod from_hit(node, factory)[source]
Parameters:
  • node (nmhit.Node)

  • factory (_NativeInputFile)

Return type:

Newton

hit = <neml2.schema.HitSchema object>
solve(system)[source]

Solve the nonlinear system via the shared C++ Newton solver.

The iteration control (convergence test, line search) lives in C++ and is shared with the AOTI runtime; this wrapper supplies the residual / Newton-step callbacks (the RHS / NewtonStep export modules, run eagerly) plus the per-group layouts, then commits the converged iterate back into the system.

Parameters:

system (ModelNonlinearSystem)

Return type:

NonlinearResult

class neml2.solvers.NewtonWithLineSearch(*, linear_solver=None, atol=1e-10, rtol=1e-08, miters=25, verbose=False, linesearch_type='BACKTRACKING', max_linesearch_iterations=10, linesearch_cutback=2.0, linesearch_stopping_criteria=0.001, check_negative_criterion=False)[source]

Bases: Newton

The Newton-Raphson solver with line search.

Parameters:
classmethod from_hit(node, factory)[source]
Parameters:
  • node (nmhit.Node)

  • factory (_NativeInputFile)

Return type:

NewtonWithLineSearch

hit = <neml2.schema.HitSchema object>
class neml2.solvers.NonlinearResult(ret, iterations)[source]

Bases: object

Result metadata returned by a nonlinear solve.

Parameters:
iterations: int
ret: RetCode
class neml2.solvers.RetCode(value)[source]

Bases: Enum

Nonlinear solver return code.

FAILURE = 2
MAXITER = 1
SUCCESS = 0
class neml2.solvers.SchurComplement(*, residual_primary_group=0, unknown_primary_group=0, primary_solver=None, schur_solver=None)[source]

Bases: object

Schur complement linear solver. Solves a block-partitioned system A x = b by forming and solving the Schur complement of the primary block.

The six-step factorisation reads naturally on top of the Tensor-backed AssembledMatrix / AssembledVector arithmetic – A_pp.solve(...), A_sp @ Y, A_ss - A_sp @ Y all forward to the typed primitive.

Parameters:
  • residual_primary_group (int)

  • unknown_primary_group (int)

SECTION = 'Solvers'
classmethod from_hit(node, factory)[source]
Parameters:
  • node (nmhit.Node)

  • factory (_NativeInputFile)

Return type:

SchurComplement

hit = <neml2.schema.HitSchema object>
solve(A: AssembledMatrix, b: AssembledVector) AssembledVector[source]
solve(A: AssembledMatrix, b: AssembledMatrix) AssembledMatrix