warp.optim.linear.LinearSolverState#
- class warp.optim.linear.LinearSolverState(
- A,
- b,
- x,
- tol=None,
- atol=None,
- maxiter=0,
- M=None,
- callback=None,
- check_every=10,
- use_graph=None,
- *,
- use_cuda_graph=_DEPRECATED_NONE,
Pre-allocated state for a linear iterative solver.
Holds all temporary buffers required by the solver plus a reference to the original problem (
A,b,x, optionalM). Calling the state runs the solver, optionally substituting a new matrix, right-hand side, solution vector, or preconditioner. Replacement operands must match the construction-time shape, dtype, device, and batch layout. For batchedLinearOperatorinputs, thebatch_offsetsarray andmax_batch_lengthvalue are part of that layout and must remain fixed. This avoids repeated buffer allocation when the same solver is applied many times.- Parameters:
A (array | BsrMatrix | LinearOperator) – the linear system’s left-hand-side
b (array) – the linear system’s right-hand-side
x (array) – initial guess and solution vector
tol (float | None) – relative tolerance for the residual, as a ratio of the right-hand-side norm
atol (float | None) – absolute tolerance for the residual
maxiter (float | None) – maximum number of iterations to perform before aborting. Defaults to the system size.
M (array | BsrMatrix | LinearOperator | None) – optional preconditioner.
callback (Callable | None) – function to be called every
check_everyiteration with the current iteration number, residual and tolerance.check_every (int) – number of iterations every which to call
callbackand check the residual against the tolerance. Set to 0 to disable host-side residual checks when running during CPU or CUDA graph capture.use_graph (bool | None) – whether to capture the solver iteration as a graph for reduced launch overhead.
Nonecaptures on CUDA devices only, andTruealso captures on CPU.use_cuda_graph (bool | None) – Deprecated since Warp 1.20 and scheduled for removal in Warp 1.24. Pass the same value as
use_graphinstead.
- Raises:
TypeError – If
use_cuda_graphis passed with ause_graphother thanNone.
- rhs_norm_sq#
Device array of the squared right-hand-side norm of each system, in the solver’s scalar type. Every solve writes it while setting its tolerances, so it is available for reporting relative residuals at no extra cost.
Instances are not directly constructible — use the solver-specific subclasses
CG,CR,BiCGSTAB, andGMRES, or obtain one by calling the corresponding solver function (cg(),cr(),bicgstab(),gmres()) withrun=False.