Blocks¤
pdequinox.blocks.ClassicDoubleConvBlock
¤
Bases: Block
Source code in pdequinox/blocks/_classic_double_conv_block.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
activation: Callable = jax.nn.relu,
kernel_size: int = 3,
use_norm: bool = True,
num_groups: int = 1,
use_bias: bool = True,
zero_bias_init: bool = False,
boundary_mode: Literal[
"periodic", "dirichlet", "neumann"
],
key: PRNGKeyArray
)
Block that performs two sequential convolutions with activation and optional group normalization in between.
Arguments:
num_spatial_dims
: The number of spatial dimensions. For example traditional convolutions for image processing have this set to2
.in_channels
: The number of input channels.out_channels
: The number of output channels.boundary_mode
: The boundary mode to use for the convolution. (Keyword only argument)key
: Ajax.random.PRNGKey
used to provide randomness for parameter initialisation. (Keyword only argument.)activation
: The activation function to use after each convolution. Default isjax.nn.relu
.kernel_size
: The size of the convolutional kernel. Default is3
.use_norm
: Whether to use group normalization. Default isTrue
.num_groups
: The number of groups to use for group normalization. Default is1
.use_bias
: Whether to use bias in the convolutional layers. Default isTrue
.zero_bias_init
: Whether to initialise the bias to zero. Default isFalse
.
Source code in pdequinox/blocks/_classic_double_conv_block.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
__call__
¤
__call__(x)
Source code in pdequinox/blocks/_classic_double_conv_block.py
87 88 89 90 |
|
pdequinox.blocks.ClassicResBlock
¤
Bases: Module
Source code in pdequinox/blocks/_classic_res_block.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
activation: Callable = jax.nn.relu,
kernel_size: int = 3,
use_norm: bool = False,
num_groups: int = 1,
use_bias: bool = True,
zero_bias_init: bool = False,
boundary_mode: Literal[
"periodic", "dirichlet", "neumann"
],
key: PRNGKeyArray
)
Classical Block of a ResNet with postactivation and optional group normalization in between (Default: off)
If in_channels != out_channels, a bypass convolution (1x1 conv) and
group normalization (if use_norm=True
) is added to the residual
connection.
Arguments:
num_spatial_dims
: The number of spatial dimensions. For example traditional convolutions for image processing have this set to2
.in_channels
: The number of input channels.out_channels
: The number of output channels.boundary_mode
: The boundary mode to use for the convolution. (Keyword only argument)key
: Ajax.random.PRNGKey
used to provide randomness for parameter initialisation. (Keyword only argument.)activation
: The activation function to use after each convolution. Default isjax.nn.relu
.kernel_size
: The size of the convolutional kernel. Default is3
.use_norm
: Whether to use group normalization. Default isFalse
.num_groups
: The number of groups to use for group normalization. Default is1
.use_bias
: Whether to use bias in the convolutional layers. Default isTrue
.zero_bias_init
: Whether to initialise the bias to zero. Default isFalse
.
Source code in pdequinox/blocks/_classic_res_block.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
__call__
¤
__call__(x)
Source code in pdequinox/blocks/_classic_res_block.py
112 113 114 115 116 117 118 119 120 121 |
|
pdequinox.blocks.ModernResBlock
¤
Bases: Module
Source code in pdequinox/blocks/_modern_res_block.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
activation: Callable = jax.nn.relu,
kernel_size: int = 3,
use_norm: bool = True,
num_groups: int = 1,
use_bias: bool = True,
zero_bias_init: bool = False,
boundary_mode: Literal[
"periodic", "dirichlet", "neumann"
],
key: PRNGKeyArray
)
Block that performs two sequential convolutions with activation and optional group normalization in between. The order of operations is based on "pre-activation" to allow for a clean bypass/residual connection.
If the number of input channels is different from the number of output channels, a pointwise convolution (without bias) is used to match the number of channels.
If use_norm
is True
, group normalization is used after each
convolution. If there is a convolution that matches the number of
channels, the bypass will also have group normalization.
Arguments:
num_spatial_dims
: The number of spatial dimensions. For example traditional convolutions for image processing have this set to2
.in_channels
: The number of input channels.out_channels
: The number of output channels.boundary_mode
: The boundary mode to use for the convolution. (Keyword only argument)key
: Ajax.random.PRNGKey
used to provide randomness for parameter initialisation. (Keyword only argument.)activation
: The activation function to use after each convolution. Default isjax.nn.relu
.kernel_size
: The size of the convolutional kernel. Default is3
.use_norm
: Whether to use group normalization. Default isTrue
.num_groups
: The number of groups to use for group normalization. Default is1
.use_bias
: Whether to use bias in the convolutional layers. Default isTrue
.zero_bias_init
: Whether to initialise the bias to zero. Default isFalse
.
Source code in pdequinox/blocks/_modern_res_block.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
__call__
¤
__call__(x)
Source code in pdequinox/blocks/_modern_res_block.py
133 134 135 136 137 138 139 140 |
|
pdequinox.blocks.ClassicSpectralBlock
¤
Bases: Block
Source code in pdequinox/blocks/_classic_spectral_block.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
activation: Callable = jax.nn.gelu,
num_modes: int = 8,
use_bias: bool = True,
zero_bias_init: bool = False,
key: PRNGKeyArray
)
Residual-style block as used in vanilla FNOs; combines a spectral convolution with a bypass.
Does not have argument boundary_mode
because it would not respect it.
In the original FNO paper it is argued that the bypass helps recover the
boundary condition.
Arguments:
num_spatial_dims
: The number of spatial dimensions. For example traditional convolutions for image processing have this set to2
.in_channels
: The number of input channels.out_channels
: The number of output channels.key
: Ajax.random.PRNGKey
used to provide randomness for parameter initialisation. (Keyword only argument.)activation
: The activation function to use after each convolution. Default isjax.nn.relu
.num_modes
: How many modes to consider in Fourier space. At max this can be N//2+1, with N being the number of spatial points. Think of it as the analogy of the kernel size.use_bias
: Whether to use a bias in the bypass convolution. DefaultTrue
.zero_bias_init
: Whether to initialise the bias to zero. Default isFalse
.
Source code in pdequinox/blocks/_classic_spectral_block.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
__call__
¤
__call__(x)
Source code in pdequinox/blocks/_classic_spectral_block.py
72 73 74 75 |
|
pdequinox.blocks.DilatedResBlock
¤
Bases: Module
Source code in pdequinox/blocks/_dilated_res_block.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
activation: Callable = jax.nn.relu,
kernel_size: int = 3,
dilation_rates: tuple[int] = (1, 2, 4, 8, 4, 2, 1),
use_norm: bool = True,
num_groups: int = 1,
use_bias: bool = True,
zero_bias_init: bool = False,
boundary_mode: Literal[
"periodic", "dirichlet", "neumann"
],
key: PRNGKeyArray
)
Block that performs a sequence of convolutions with varying dilation rates. Dilation refers to how many (virtual) zeros are inserted between kernel elements, effectively resulting into a larger receptive field. A bypass is added turning this block into a residual element.
Arguments:
num_spatial_dims
: The number of spatial dimensions. For example traditional convolutions for image processing have this set to2
.in_channels
: The number of input channels.out_channels
: The number of output channels.boundary_mode
: The boundary mode to use for the convolution. (Keyword only argument)key
: Ajax.random.PRNGKey
used to provide randomness for parameter initialisation. (Keyword only argument.)activation
: The activation function to use after each convolution. Default isjax.nn.relu
.kernel_size
: The size of the convolutional kernel. Default is3
.dilation_rates
: A sequence of integers. Their length identifies the number of sequential convolutions performed. Each integer is the dilation performed at that convolution. Typically, this list follows the pattern of first increasing in dilation rate, and then decreasing again. Default is(1, 2, 4, 8, 4, 2, 1)
.use_norm
: Whether to use group normalization. Default isTrue
.num_groups
: The number of groups to use for group normalization. Default is1
.use_bias
: Whether to use bias in the convolutional layers. Default isTrue
.zero_bias_init
: Whether to initialise the bias to zero. Default isFalse
.
Source code in pdequinox/blocks/_dilated_res_block.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
__call__
¤
__call__(x)
Source code in pdequinox/blocks/_dilated_res_block.py
141 142 143 144 145 146 147 148 149 150 151 |
|
pdequinox.blocks.LinearConvBlock
¤
Bases: PhysicsConv
Source code in pdequinox/blocks/_linear_conv_block.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
kernel_size: int = 3,
use_bias: bool = True,
zero_bias_init: bool = False,
boundary_mode: Literal[
"periodic", "dirichlet", "neumann"
],
key: PRNGKeyArray
)
Source code in pdequinox/blocks/_linear_conv_block.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
__call__
¤
__call__(
x: Array, *, key: Optional[PRNGKeyArray] = None
) -> Array
Arguments:
x
: The input. Should be a JAX array of shape(in_channels, dim_1, ..., dim_N)
, whereN = num_spatial_dims
.key
: Ignored; provided for compatibility with the rest of the Equinox API. (Keyword only argument.)
Returns:
A JAX array of shape (out_channels, new_dim_1, ..., new_dim_N)
.
Source code in pdequinox/conv/_conv.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
pdequinox.blocks.LinearConvDownBlock
¤
Bases: PhysicsConv
Source code in pdequinox/blocks/_linear_conv_down_block.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
kernel_size: int = 3,
factor: int = 2,
use_bias: bool = True,
zero_bias_init: bool = False,
boundary_mode: Literal[
"periodic", "dirichlet", "neumann"
],
key: PRNGKeyArray
)
Source code in pdequinox/blocks/_linear_conv_down_block.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
__call__
¤
__call__(
x: Array, *, key: Optional[PRNGKeyArray] = None
) -> Array
Arguments:
x
: The input. Should be a JAX array of shape(in_channels, dim_1, ..., dim_N)
, whereN = num_spatial_dims
.key
: Ignored; provided for compatibility with the rest of the Equinox API. (Keyword only argument.)
Returns:
A JAX array of shape (out_channels, new_dim_1, ..., new_dim_N)
.
Source code in pdequinox/conv/_conv.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
pdequinox.blocks.LinearConvUpBlock
¤
Bases: PhysicsConvTranspose
Source code in pdequinox/blocks/_linear_conv_up_block.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
__init__
¤
__init__(
num_spatial_dims: int,
in_channels: int,
out_channels: int,
*,
kernel_size: int = 3,
factor: int = 2,
output_padding: int = 1,
use_bias: bool = True,
zero_bias_init: bool = False,
boundary_mode: Literal[
"periodic", "dirichlet", "neumann"
],
key: PRNGKeyArray
)
Source code in pdequinox/blocks/_linear_conv_up_block.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
__call__
¤
__call__(
x: Array,
*,
output_padding: Optional[
Union[int, Sequence[int]]
] = None,
key: Optional[PRNGKeyArray] = None
) -> Array
Arguments:
x
: The input. Should be a JAX array of shape(in_channels, dim_1, ..., dim_N)
, whereN = num_spatial_dims
.key
: Ignored; provided for compatibility with the rest of the Equinox API. (Keyword only argument.)output_padding
: Additional padding for the output shape. If not provided, theoutput_padding
used in the initialisation is used.
Returns:
A JAX array of shape (out_channels, new_dim_1, ..., new_dim_N)
.
Source code in pdequinox/conv/_conv.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
pdequinox.blocks.Block
¤
Bases: Module
, ABC
Source code in pdequinox/blocks/_base_block.py
8 9 |
|