scimba_torch.numerical_solvers.pinn_preconditioners¶
Implementations of PINN preconditioners.
- class AnagramPreconditioner(space, pde, **kwargs)[source]¶
Bases:
MatrixPreconditionerPinnAnagram preconditioner.
This preconditioner is based on the anagram method, which aims to improve convergence by transforming the problem into a more favorable form.
- Parameters:
space (
AbstractApproxSpace) – The approximation space.pde (
EllipticPDE|TemporalPDE|KineticPDE|LinearOrder2PDE|RitzFormEllipticPDE|DivAGradUPDE) – The PDE to be solved, which can be an instance of EllipticPDE, TemporalPDE, KineticPDE, or LinearOrder2PDE.**kwargs – Additional keyword arguments:
- Keyword Arguments:
svd_threshold (
float) – Threshold for singular value decomposition (default: 1e-6).
- compute_preconditioning_matrix(labels, *args, **kwargs)[source]¶
Compute the preconditioning matrix using the main operator.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The preconditioning matrix.
- compute_preconditioning_matrix_bc(labels, *args, **kwargs)[source]¶
Compute the boundary condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The boundary condition preconditioning matrix.
- compute_preconditioning_matrix_ic(labels, *args, **kwargs)[source]¶
Compute the initial condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The initial condition preconditioning matrix.
- compute_preconditioning_matrix_dl(*args, **kwargs)[source]¶
Computes the Gram matrix of the network for the given input tensors.
- Parameters:
*args (
Tensor) – Input tensors for computing the Gram matrix.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The computed Gram matrix.
- assemble_right_member(data, res_l, res_r)[source]¶
Assemble the right-hand side of the equation.
- Parameters:
data (
tuple|dict) – Input data, either as a tuple or a dictionary.res_l (
tuple) – Left residuals.res_r (
tuple) – Right residuals.
- Return type:
Tensor- Returns:
The assembled right-hand side tensor.
- assemble_right_member_bc(data, res_l, res_r)[source]¶
Assemble the right-hand side for boundary conditions.
- Parameters:
data (
tuple|dict) – Input data, either as a tuple or a dictionary.res_l (
tuple) – Left residuals.res_r (
tuple) – Right residuals.
- Return type:
Tensor- Returns:
The assembled right-hand side tensor for boundary conditions.
- assemble_right_member_ic(data, res_l, res_r)[source]¶
Assemble the right-hand side for initial conditions.
- Parameters:
data (
tuple|dict) – Input data, either as a tuple or a dictionary.res_l (
tuple) – Left residuals.res_r (
tuple) – Right residuals.
- Return type:
Tensor- Returns:
The assembled right-hand side tensor for initial conditions.
- assemble_right_member_dl(data, res_l, res_r)[source]¶
Assembles the right member for the preconditioning.
- Parameters:
data (
tuple|dict) – The input data for assembling the right member.res_l (
tuple) – The left residuals.res_r (
tuple) – The right residuals.
- Return type:
Tensor- Returns:
The assembled right member.
- class EnergyNaturalGradientPreconditioner(space, pde, **kwargs)[source]¶
Bases:
MatrixPreconditionerPinnEnergy-based natural gradient preconditioner.
- Parameters:
space (
AbstractApproxSpace) – The approximation space.pde (
EllipticPDE|TemporalPDE|KineticPDE|LinearOrder2PDE|RitzFormEllipticPDE|DivAGradUPDE) – The PDE to be solved, which can be an instance of EllipticPDE, TemporalPDE, KineticPDE, or LinearOrder2PDE.**kwargs – Additional keyword arguments.
- Keyword Arguments:
matrix_regularization (float) – Regularization parameter for the preconditioning matrix (default: 1e-6).
adaptive_matrix_regularization (
bool, default=False)training (If True, adaptively adjusts the regularization parameter during)
Levenberg-Marquardt). ((à la)
parameter (If False, uses the fixed regularization)
matrix_regularization. (specified by)
adaptive_matrix_regularization_increase (
float, default=10.0)search (Factor by which to decrease the regularization parameter if the line)
size. (quickly succeeds in finding a suitable step)
adaptive_matrix_regularization_decrease (
float, default=0.5)search
size.
adaptive_matrix_regularization_min (
float, default=1e-12)adjustment. (Minimum value for the regularization parameter when using adaptive)
use_lstsq (bool) – Whether to use least squares solver for
(default (computing the preconditioner) – True).
inversion. (If False, uses direct matrix)
- compute_preconditioning_matrix(labels, *args, **kwargs)[source]¶
Compute the preconditioning matrix using the main operator.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The preconditioning matrix.
- compute_preconditioning_matrix_bc(labels, *args, **kwargs)[source]¶
Compute the boundary condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The boundary condition preconditioning matrix.
- compute_preconditioning_matrix_ic(labels, *args, **kwargs)[source]¶
Compute the initial condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The initial condition preconditioning matrix.
- compute_preconditioning_matrix_dl(*args, **kwargs)[source]¶
Computes the Gram matrix of the network for the given input tensors.
- Parameters:
*args (
Tensor) – Input tensors for computing the Gram matrix.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The computed Gram matrix.
- compute_full_preconditioning_matrix(data, **kwargs)[source]¶
Compute the full preconditioning matrix.
Include contributions from the main operator, boundary conditions, and initial conditions.
- Parameters:
data (
tuple|dict) – Input data, either as a tuple or a dictionary.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The full preconditioning matrix.
- update_matrix_regularization(n_steps, loss_has_decreased)[source]¶
Updates the regularization parameter for the preconditioning matrix.
This method adaptively adjusts the regularization parameter during training based on the number of line search steps taken and whether the loss has decreased.
- Parameters:
n_steps (
int) – The number of line search steps taken.loss_has_decreased (
bool) – Whether the loss has decreased after the line search.
- class NystromNaturalGradientPreconditioner(space, pde, **kwargs)[source]¶
Bases:
MatrixPreconditionerPinnRandomized matrix-free natural gradient preconditioner.
Implements [Bioli and al. 2025]
- Parameters:
space (
AbstractApproxSpace) – The approximation space.pde (
EllipticPDE|TemporalPDE|KineticPDE|LinearOrder2PDE|RitzFormEllipticPDE|DivAGradUPDE) – The PDE to be solved, which can be an instance of EllipticPDE, TemporalPDE, KineticPDE, or LinearOrder2PDE.**kwargs – Additional keyword arguments:
- Keyword Arguments:
matrix_free (
bool) – Use jvp and vjp to compute the matrix vector product function instead of Phi matrix. (default: False).eps (
float) – The eps for adaptive matrix regularization. (default:torch.finfo(torch.get_default_dtype()).eps).debug (
bool) – Debugging mode - check that gram matrices are coherent. (default: False).
- Raises:
NotImplementedError – data loss and matrix free option not implemented
- [Bioli and al. 2025] Accelerating Natural Gradient Descent for PINNs with
Randomized Nyström Preconditioning, I. Bioli, C. Marcati, G. Sangalli https://arxiv.org/abs/2505.11638v3
- compute_preconditioning_matrix(labels, *args, **kwargs)[source]¶
Compute the preconditioning matrix using the main operator.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The preconditioning matrix.
- compute_preconditioning_matrix_bc(labels, *args, **kwargs)[source]¶
Compute the boundary condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The boundary condition preconditioning matrix.
- compute_preconditioning_matrix_ic(labels, *args, **kwargs)[source]¶
Compute the initial condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The initial condition preconditioning matrix.
- class SketchyNaturalGradientPreconditioner(space, pde, **kwargs)[source]¶
Bases:
MatrixPreconditionerPinnSketchy natural gradient preconditioner.
Implements [McKay and al. 2025].
- Parameters:
space (
AbstractApproxSpace) – The approximation space.pde (
EllipticPDE|TemporalPDE|KineticPDE|LinearOrder2PDE|RitzFormEllipticPDE|DivAGradUPDE) – The PDE to be solved, which can be an instance of EllipticPDE, TemporalPDE, KineticPDE, or LinearOrder2PDE.**kwargs – Additional keyword arguments:
- Keyword Arguments:
tol (
float) – The threshold for deciding the size of the sketch matrix, r in the paper. (default: 1e-13).single_pass (
bool) – single pass or two pass (default False, means two pass).
- [McKay and al. 2025] Near-optimal Sketchy Natural Gradients
for Physics-Informed Neural Networks, M. B. McKay, A. Kaur, C. Greif, B. Wetton Proceedings of the 42 nd International Conference on Machine Learning, Vancouver, Canada. PMLR 267, 2025
- compute_preconditioning_matrix(labels, *args, **kwargs)[source]¶
Compute the preconditioning matrix using the main operator.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The preconditioning matrix.
- compute_preconditioning_matrix_bc(labels, *args, **kwargs)[source]¶
Compute the boundary condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The boundary condition preconditioning matrix.
- compute_preconditioning_matrix_ic(labels, *args, **kwargs)[source]¶
Compute the initial condition preconditioning matrix.
- Parameters:
labels (
Tensor) – The labels tensor.*args (
Tensor) – Additional arguments.**kwargs – Additional keyword arguments.
- Return type:
Tensor- Returns:
The initial condition preconditioning matrix.
Modules
Preconditioner for pinns. |
|
Preconditioner for pinns. |
|
Preconditioner for pinns. |
|
Preconditioner for pinns. |