MgNO
Multigrid Neural Operator (MgNO)¤
neojax.models.mgno.MgNO
¤
Multigrid Neural Operator (MgNO).
Based on the mathematical structure of multigrid methods.
This class wraps all MgNO variants of the reference
implementation
in a single class. Use the MgNO.make_mgno_type convenience
function to use one of the pre-configured variants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
PRNG key for parameter initialization. |
required |
n_layers
|
int
|
The number of |
required |
n_its_per_level
|
Sequence[Sequence[int] | int]
|
Number of iterations per level. A sequence containing
a pair |
required |
n_channels_u
|
int
|
Number of channels of the solution field. |
required |
n_channels_f
|
int
|
Number of channels of the data field. |
required |
proj_hidden_dim
|
int | None
|
Whether to use an additional hidden dimension
in the projection MLP with this dimension and intermediate GeLU activation.
Default is |
None
|
use_local_pointwise
|
bool
|
Whether to use a parallel local (pointwise), non-local ( |
False
|
activation
|
Literal['relu', 'gelu', 'tanh', 'silu']
|
The type of non-linear activation function to use after each layer.
Default is |
'gelu'
|
use_residual_skip
|
bool
|
Whether to use a residual skip connection around all layers.
Requires |
True
|
use_proj_mgconv
|
bool
|
Whether to use another |
False
|
padding_mode
|
Literal['zeros', 'reflect', 'replicate', 'circular']
|
Padding mode for the convolutions. Requires |
'zeros'
|
padding_mode_smoothing
|
Optional[Literal['zeros', 'reflect', 'replicate', 'circular']]
|
Padding mode for the smoothing iterations. If set,
overrides |
None
|
padding_mode_prolongation
|
Optional[Literal['zeros', 'reflect', 'replicate', 'circular']]
|
Padding mode for the prolongations. If set,
overrides |
None
|
padding_mode_restriction
|
Optional[Literal['zeros', 'reflect', 'replicate', 'circular']]
|
Padding mode for the restrictions. If set,
override |
None
|
prolongation_padding
|
int
|
The padding to use in the transposed convolutions
of the prolongations. Requires |
1
|
restriction_padding
|
int
|
The padding to use in the convolutions
of the restrictions. Requires |
1
|
smoothing_padding
|
int
|
The padding to use in the convolutions of the
pre- and post-smoothing iterations. Is overwritten only if
|
1
|
use_smoothing_bias
|
bool
|
Whether to use bias in the smoothing convolutions. Requires
|
False
|
use_restriction_pde_bias
|
bool
|
Whether to use bias in the approx PDE operator of
the restrictions. Default is |
False
|
use_residual_restriction
|
bool
|
Whether to use residual-based restrictions
("Full approximation scheme"-style). Default is |
False
|
use_layernorm
|
bool
|
Whether to use layer normalization after each prolongation.
Requires |
True
|
use_layernorm_affine
|
bool
|
Whether the layer normalization has learnable affine parameters.
Default is |
True
|
layer_norm_type
|
Literal['helm', 'halve']
|
The type of layer normalization spatial reduction to use. Requires |
'halve'
|
in_spatial_size
|
int | None
|
Optional size of the spatial dimensions. Required
if |
None
|
prolongation_kernel_type
|
Literal['constant', 'alternating', 'helm']
|
The type of prolongation kernels to use.
Use |
'constant'
|
grow_channels_w_depth
|
bool
|
Whether to increase the number of channels
with depth ( |
False
|
use_xavier_restrict
|
bool
|
Whether to use Xavier initialization for the
restriction operators. Can be |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid activation function is passed. |
Internal Attributes
These fields store the internal layers state (and weights).
- mg_convs (
tuple[MgConv, ...]): TheMgConvblocks layers. - local_layers (
tuple[PointwiseMLP, ...] | None): The optional local 1x1 Conv layers. - activation_fn (
Callable[[Array], Array]): The non-linear activation function after each layer. - projection (
tuple[Callable, ...] | PointwiseMLP): The output projection. - n_layers (
int): The number of layers. - use_residual_skip (
bool): Whether to use a ResNet-style residual skip connection.
Cite
MgNO: Efficient Parameterization of Linear Operators via Multigrid
@inproceedings{he2024mgno,
title={MgNO: Efficient parameterization of linear operators via multigrid},
author={He, Juncai and Liu, Xinliang and Xu, Jinchao},
booktitle={International Conference on Learning Representations},
volume={2024},
pages={53409--53428},
year={2024}
}
Restricted Usability
MgNO is not a general n-dimensional implementation. This mirrors the
reference implementation.
In its current architecture, it is only usable with 2D inputs matching
the experiments of the original publication (e.g. Helmholtz, Darcy or Navier Stokes)
with their exact grid dimensions.
make_mgno_type(key: PRNGKeyArray, mgno_type: typing.Literal['MgNO_NS', 'MgNO_DC', 'MgNO_DC_smooth', 'MgNO_helm', 'MgNO_helm2'], n_layers: int, activation: typing.Literal['relu', 'gelu', 'tanh', 'silu'] = 'gelu', n_its_per_level: collections.abc.Sequence[collections.abc.Sequence[int] | int] | None = None) -> MgNO
classmethod
¤
Configures an MgNO instance for an experiment specific architecture.
The non-specific parameters still have to passed (n_layers and n_its_per_level).
The iterations per level may be omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mgno_type
|
Literal['MgNO_NS', 'MgNO_DC', 'MgNO_DC_smooth', 'MgNO_helm', 'MgNO_helm2']
|
The type of MgNO architecture to use. |
required |
n_layers
|
int
|
The number of |
required |
activation
|
Literal['relu', 'gelu', 'tanh', 'silu']
|
The type of non-linear activation function to use. Default is |
'gelu'
|
n_its_per_level
|
Sequence[Sequence[int] | int] | None
|
Number of iterations per level. A sequence containing
a pair |
None
|
Returns:
| Type | Description |
|---|---|
MgNO
|
A configured MgNO instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid |
__call__(x: Inexact[Array, 'in_c ...'], *, key: PRNGKeyArray | None = None, inference: bool = False) -> Inexact[Array, 'out_c ...']
¤
Forward pass of the MgNO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Inexact[Array, 'in_c ...']
|
Input field or forcing of shape |
required |
key
|
PRNGKeyArray | None
|
Ignored. Kept for API compatibility. |
None
|
inference
|
bool
|
Ignored. Kept for API compatibility. |
False
|
Returns:
| Type | Description |
|---|---|
Inexact[Array, 'out_c ...']
|
The predicted field of shape |