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,
)[source]#

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, optional M). 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 batched LinearOperator inputs, the batch_offsets array and max_batch_length value 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_every iteration with the current iteration number, residual and tolerance.

  • check_every (int) – number of iterations every which to call callback and 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. None captures on CUDA devices only, and True also 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_graph instead.

Raises:

TypeError – If use_cuda_graph is passed with a use_graph other than None.

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, and GMRES, or obtain one by calling the corresponding solver function (cg(), cr(), bicgstab(), gmres()) with run=False.