scimba_torch.numerical_solvers.preconditioner_deep_ritz

Deep Ritz preconditioners.

Classes

EnergyNaturalGradientPreconditioner(space, ...)

Energy Natural Gradient preconditioner for Deep Ritz methods.

MatrixPreconditionerDeepRitz(space, pde, ...)

Matrix-based preconditioner for pinns.

class MatrixPreconditionerDeepRitz(space, pde, **kwargs)[source]

Bases: MatrixPreconditionerSolver

Matrix-based preconditioner for pinns.

Parameters:
Raises:
  • AttributeError – If the input PDE does not have the required attributes.

  • NotImplementedError – when used with data loss.

vectorize_along_physical_variables(func)[source]

Vectorizes a function along physical variables based on the type of space.

Parameters:

func (VarArgAnyCallable) – The function to be vectorized.

Return type:

VarArgAnyCallable

Returns:

The vectorized function.

Raises:

NotImplementedError – If the type of space is not supported.

class EnergyNaturalGradientPreconditioner(space, pde, **kwargs)[source]

Bases: MatrixPreconditionerDeepRitz

Energy Natural Gradient preconditioner for Deep Ritz methods.

Parameters:
Raises:

ValueError – If the number of unknowns in the space is greater than 1.

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)

eval_and_gradx(*args)[source]

Evaluate the function and compute its gradient.

Parameters:

*args (Tensor | dict[str, Parameter]) – Input arguments where the last argument is the parameters of the network.

Returns:

A tensor containing the function evaluation and its gradient.

eval_and_gradx_and_jactheta(*args)[source]

Evaluate the function, compute its gradient, and the Jacobian.

Parameters:

*args (Tensor | dict[str, Parameter]) – Input arguments where the last argument is the parameters of the network.

Returns:

A tensor containing the function evaluation, its gradient, and the Jacobian

compute_preconditioning_matrix(labels, *args, **kwargs)[source]

Compute the preconditioning matrix.

Parameters:
  • labels (Tensor) – Tensor of labels corresponding to the input data.

  • *args (Tensor) – Additional arguments required for computing the matrix.

  • **kwargs – Additional keyword arguments.

Return type:

Tensor

Returns:

The computed preconditioning matrix as a tensor.

compute_preconditioning_matrix_bc(labels, *args, **kwargs)[source]

Compute the boundary condition preconditioning matrix.

Parameters:
  • labels (Tensor) – Tensor of labels corresponding to the boundary condition data.

  • *args (Tensor) – Additional arguments required for computing the matrix.

  • **kwargs – Additional keyword arguments.

Return type:

Tensor

Returns:

The computed boundary condition preconditioning matrix as a tensor.

compute_preconditioning_matrix_ic(labels, *args, **kwargs)[source]

Compute the initial condition preconditioning matrix.

Parameters:
  • labels (Tensor) – Tensor of labels corresponding to the boundary condition data.

  • *args (Tensor) – Additional arguments required for computing the matrix.

  • **kwargs – Additional keyword arguments.

Return type:

Tensor

Returns:

NotImplementedError.

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.

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.

reset_matrix_regularization()[source]

Resets the regularization parameter to its initial value.