Available PDE Surrogate Modules¤
SpectralConv1d
¤
Bases: Module
1D Fourier layer. Does FFT, linear transform, and Inverse FFT. Implemented in a way to allow multi-gpu training. Args: in_channels (int): Number of input channels out_channels (int): Number of output channels modes (int): Number of Fourier modes paper
Source code in pdearena/modules/fourier.py
SpectralConv2d
¤
Bases: Module
2D Fourier layer. Does FFT, linear transform, and Inverse FFT. Implemented in a way to allow multi-gpu training. Args: in_channels (int): Number of input channels out_channels (int): Number of output channels modes1 (int): Number of Fourier modes to keep in the first spatial direction modes2 (int): Number of Fourier modes to keep in the second spatial direction paper
Source code in pdearena/modules/fourier.py
SpectralConv3d
¤
Bases: Module
3D Fourier layer. Does FFT, linear transform, and Inverse FFT. Implemented in a way to allow multi-gpu training. Args: in_channels (int): Number of input channels out_channels (int): Number of output channels modes1 (int): Number of Fourier modes to keep in the first spatial direction modes2 (int): Number of Fourier modes to keep in the second spatial direction modes3 (int): Number of Fourier modes to keep in the third spatial direction paper
Source code in pdearena/modules/fourier.py
DilatedBasicBlock
¤
Bases: Module
Basic block for Dilated ResNet
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_planes |
int
|
number of input channels |
required |
planes |
int
|
number of output channels |
required |
stride |
int
|
stride of the convolution. Defaults to 1. |
1
|
activation |
str
|
activation function. Defaults to "relu". |
'relu'
|
norm |
bool
|
whether to use group normalization. Defaults to True. |
True
|
num_groups |
int
|
number of groups for group normalization. Defaults to 1. |
1
|
Source code in pdearena/modules/twod_resnet.py
FourierBasicBlock
¤
Bases: Module
Basic block for Fourier Neural Operators
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_planes |
int
|
number of input channels |
required |
planes |
int
|
number of output channels |
required |
stride |
int
|
stride of the convolution. Defaults to 1. |
1
|
modes1 |
int
|
number of modes for the first spatial dimension. Defaults to 16. |
16
|
modes2 |
int
|
number of modes for the second spatial dimension. Defaults to 16. |
16
|
activation |
str
|
activation function. Defaults to "relu". |
'gelu'
|
norm |
bool
|
whether to use group normalization. Defaults to False. |
False
|
Source code in pdearena/modules/twod_resnet.py
ResNet
¤
Bases: Module
Class to support ResNet like feedforward architectures
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_input_scalar_components |
int
|
Number of input scalar components in the model |
required |
n_input_vector_components |
int
|
Number of input vector components in the model |
required |
n_output_scalar_components |
int
|
Number of output scalar components in the model |
required |
n_output_vector_components |
int
|
Number of output vector components in the model |
required |
block |
Callable
|
BasicBlock or DilatedBasicBlock or FourierBasicBlock |
required |
num_blocks |
List[int]
|
Number of blocks in each layer |
required |
time_history |
int
|
Number of time steps to use in the input |
required |
time_future |
int
|
Number of time steps to predict in the output |
required |
hidden_channels |
int
|
Number of channels in the hidden layers |
64
|
activation |
str
|
Activation function to use |
'gelu'
|
norm |
bool
|
Whether to use normalization |
True
|
Source code in pdearena/modules/twod_resnet.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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
OperatorBlock_2D
¤
Bases: Module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_codim |
int
|
Input co-domian dimension |
required |
out_codim |
int
|
output co-domain dimension |
required |
dim1 |
int
|
Default output grid size along x (or 1st dimension) |
required |
dim2 |
int
|
Default output grid size along y ( or 2nd dimension) |
required |
modes1 |
int
|
Number of fourier modes to consider along 1st dimension |
required |
modes2 |
int
|
Number of fourier modes to consider along 2nd dimension |
required |
norm |
bool
|
Whether to use normalization (torch.nn.InstanceNorm2d) |
True
|
nonlin |
bool
|
Whether to use non-linearity (torch.nn.GELU) |
True
|
All variables are consistent with the SpectralConv2d_Uno
.
Source code in pdearena/modules/twod_uno.py
Pointwise_op_2D
¤
Bases: Module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_codim |
int
|
Input co-domian dimension |
required |
out_codim |
int
|
output co-domain dimension |
required |
dim1 |
int
|
Default output grid size along x (or 1st dimension) |
required |
dim2 |
int
|
Default output grid size along y ( or 2nd dimension) |
required |
Source code in pdearena/modules/twod_uno.py
SpectralConv2d_Uno
¤
Bases: Module
2D Fourier layer. It does FFT, linear transform, and Inverse FFT.
Modified to support multi-gpu training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_codim |
int
|
Input co-domian dimension |
required |
out_codim |
int
|
output co-domain dimension |
required |
dim1 |
int
|
Default output grid size along x (or 1st dimension of output domain) |
required |
dim2 |
int
|
Default output grid size along y ( or 2nd dimension of output domain) Ratio of grid size of the input and the output implecitely set the expansion or contraction farctor along each dimension. |
required |
modes1 |
int), modes2 (int
|
Number of fourier modes to consider for the ontegral operator Number of modes must be compatibale with the input grid size and desired output grid size. i.e., modes1 <= min( dim1/2, input_dim1/2). Here "input_dim1" is the grid size along x axis (or first dimension) of the input domain. Other modes also the have same constrain. |
None
|
Source code in pdearena/modules/twod_uno.py
UNO
¤
Bases: Module
UNO model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_input_scalar_components |
int
|
Number of scalar components in the model |
required |
n_input_vector_components |
int
|
Number of vector components in the model |
required |
n_output_scalar_components |
int
|
Number of output scalar components in the model |
required |
n_output_vector_components |
int
|
Number of output vector components in the model |
required |
time_history |
int
|
Number of time steps to include in the model |
required |
time_future |
int
|
Number of time steps to predict in the model |
required |
hidden_channels |
int
|
Number of hidden channels in the model |
required |
pad |
int
|
Padding to use in the model |
0
|
factor |
int
|
Scaling factor to use in the model |
3 / 4
|
activation |
str
|
Activation function to use in the model |
'gelu'
|
Source code in pdearena/modules/twod_uno.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
Unet2015
¤
Bases: Module
Two-dimensional UNet based on original architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_input_scalar_components |
int
|
Number of scalar components in the model |
required |
n_input_vector_components |
int
|
Number of vector components in the model |
required |
n_output_scalar_components |
int
|
Number of output scalar components in the model |
required |
n_output_vector_components |
int
|
Number of output vector components in the model |
required |
time_history |
int
|
Number of time steps in the input. |
required |
time_future |
int
|
Number of time steps in the output. |
required |
hidden_channels |
int
|
Number of hidden channels. |
required |
activation |
str
|
Activation function. |
required |
Source code in pdearena/modules/twod_unet2015.py
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 |
|
Unetbase
¤
Bases: Module
Our interpretation of the original U-Net architecture.
Uses torch.nn.GroupNorm instead of torch.nn.BatchNorm2d. Also there is no BottleNeck
block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_input_scalar_components |
int
|
Number of scalar components in the model |
required |
n_input_vector_components |
int
|
Number of vector components in the model |
required |
n_output_scalar_components |
int
|
Number of output scalar components in the model |
required |
n_output_vector_components |
int
|
Number of output vector components in the model |
required |
time_history |
int
|
Number of time steps in the input. |
required |
time_future |
int
|
Number of time steps in the output. |
required |
hidden_channels |
int
|
Number of channels in the hidden layers. |
required |
activation |
str
|
Activation function to use. One of ["gelu", "relu", "silu"]. |
'gelu'
|
Source code in pdearena/modules/twod_unetbase.py
AttentionBlock
¤
Bases: Module
Attention block This is similar to [transformer multi-head attention]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_channels |
int
|
the number of channels in the input |
required |
n_heads |
int
|
the number of heads in multi-head attention |
1
|
d_k |
Optional[int]
|
the number of dimensions in each head |
None
|
n_groups |
int
|
the number of groups for group normalization. |
1
|
Source code in pdearena/modules/twod_unet.py
DownBlock
¤
Bases: Module
Down block This combines ResidualBlock
and AttentionBlock
.
These are used in the first half of U-Net at each resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels |
required |
out_channels |
int
|
Number of output channels |
required |
has_attn |
bool
|
Whether to use attention block |
False
|
activation |
Module
|
Activation function |
'gelu'
|
norm |
bool
|
Whether to use normalization |
False
|
Source code in pdearena/modules/twod_unet.py
Downsample
¤
Bases: Module
Scale down the feature map by \(\frac{1}{2} \times\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_channels |
int
|
Number of channels in the input and output. |
required |
Source code in pdearena/modules/twod_unet.py
FourierDownBlock
¤
Bases: Module
Down block This combines FourierResidualBlock
and AttentionBlock
.
These are used in the first half of U-Net at each resolution.
Source code in pdearena/modules/twod_unet.py
FourierResidualBlock
¤
Bases: Module
Fourier Residual Block to be used in modern Unet architectures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
modes1 |
int
|
Number of modes in the first dimension. |
16
|
modes2 |
int
|
Number of modes in the second dimension. |
16
|
activation |
str
|
Activation function to use. |
'gelu'
|
norm |
bool
|
Whether to use normalization. |
False
|
n_groups |
int
|
Number of groups for group normalization. |
1
|
Source code in pdearena/modules/twod_unet.py
FourierUnet
¤
Bases: Module
Unet with Fourier layers in early downsampling blocks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_input_scalar_components |
int
|
Number of scalar components in the model |
required |
n_input_vector_components |
int
|
Number of vector components in the model |
required |
n_output_scalar_components |
int
|
Number of output scalar components in the model |
required |
n_output_vector_components |
int
|
Number of output vector components in the model |
required |
time_history |
int
|
Number of time steps in the input. |
required |
time_future |
int
|
Number of time steps in the output. |
required |
hidden_channels |
int
|
Number of channels in the first layer. |
required |
activation |
str
|
Activation function to use. |
required |
modes1 |
int
|
Number of Fourier modes to use in the first spatial dimension. |
12
|
modes2 |
int
|
Number of Fourier modes to use in the second spatial dimension. |
12
|
norm |
bool
|
Whether to use normalization. |
False
|
ch_mults |
list
|
List of integers to multiply the number of channels by at each resolution. |
(1, 2, 2, 4)
|
is_attn |
list
|
List of booleans indicating whether to use attention at each resolution. |
(False, False, False, False)
|
mid_attn |
bool
|
Whether to use attention in the middle block. |
False
|
n_blocks |
int
|
Number of blocks to use at each resolution. |
2
|
n_fourier_layers |
int
|
Number of early downsampling layers to use Fourier layers in. |
2
|
mode_scaling |
bool
|
Whether to scale the number of modes with resolution. |
True
|
use1x1 |
bool
|
Whether to use 1x1 convolutions in the initial and final layer. |
False
|
Source code in pdearena/modules/twod_unet.py
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
|
FourierUpBlock
¤
Bases: Module
Up block that combines FourierResidualBlock
and AttentionBlock
.
These are used in the second half of U-Net at each resolution.
Note
We currently don't recommend using this block.
Source code in pdearena/modules/twod_unet.py
MiddleBlock
¤
Bases: Module
Middle block
It combines a ResidualBlock
, AttentionBlock
, followed by another
ResidualBlock
.
This block is applied at the lowest resolution of the U-Net.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_channels |
int
|
Number of channels in the input and output. |
required |
has_attn |
bool
|
Whether to use attention block. Defaults to False. |
False
|
activation |
str
|
Activation function to use. Defaults to "gelu". |
'gelu'
|
norm |
bool
|
Whether to use normalization. Defaults to False. |
False
|
Source code in pdearena/modules/twod_unet.py
ResidualBlock
¤
Bases: Module
Wide Residual Blocks used in modern Unet architectures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
str
|
Activation function to use. |
'gelu'
|
norm |
bool
|
Whether to use normalization. |
False
|
n_groups |
int
|
Number of groups for group normalization. |
1
|
Source code in pdearena/modules/twod_unet.py
Unet
¤
Bases: Module
Modern U-Net architecture
This is a modern U-Net architecture with wide-residual blocks and spatial attention blocks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_input_scalar_components |
int
|
Number of scalar components in the model |
required |
n_input_vector_components |
int
|
Number of vector components in the model |
required |
n_output_scalar_components |
int
|
Number of output scalar components in the model |
required |
n_output_vector_components |
int
|
Number of output vector components in the model |
required |
time_history |
int
|
Number of time steps in the input |
required |
time_future |
int
|
Number of time steps in the output |
required |
hidden_channels |
int
|
Number of channels in the hidden layers |
required |
activation |
str
|
Activation function to use |
required |
norm |
bool
|
Whether to use normalization |
False
|
ch_mults |
list
|
List of channel multipliers for each resolution |
(1, 2, 2, 4)
|
is_attn |
list
|
List of booleans indicating whether to use attention blocks |
(False, False, False, False)
|
mid_attn |
bool
|
Whether to use attention block in the middle block |
False
|
n_blocks |
int
|
Number of residual blocks in each resolution |
2
|
use1x1 |
bool
|
Whether to use 1x1 convolutions in the initial and final layers |
False
|
Source code in pdearena/modules/twod_unet.py
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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
UpBlock
¤
Bases: Module
Up block that combines ResidualBlock
and AttentionBlock
.
These are used in the second half of U-Net at each resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels |
required |
out_channels |
int
|
Number of output channels |
required |
has_attn |
bool
|
Whether to use attention block |
False
|
activation |
str
|
Activation function |
'gelu'
|
norm |
bool
|
Whether to use normalization |
False
|
Source code in pdearena/modules/twod_unet.py
Upsample
¤
Bases: Module
Scale up the feature map by \(2 \times\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_channels |
int
|
Number of channels in the input and output. |
required |
Source code in pdearena/modules/twod_unet.py
CliffordMaxwellResNet3D
¤
Bases: Module
3D building block for Clifford architectures with ResNet backbone network. The backbone networks follows these three steps: 1. Clifford vector+bivector encoding. 2. Basic blocks as provided. 3. Clifford vector+bivector decoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
Union[tuple, list, Tensor]
|
Signature of Clifford algebra. |
required |
block |
Module
|
Choice of basic blocks. |
required |
num_blocks |
list
|
List of basic blocks in each residual block. |
required |
time_history |
int
|
Number of input timesteps. |
required |
time_future |
int
|
Number of output timesteps. |
required |
hidden_channels |
int
|
Number of hidden channels. |
required |
activation |
Callable
|
Activation function. Defaults to F.gelu. |
'gelu'
|
norm |
bool
|
Whether to use Clifford (group) normalization. Defaults to False. |
False
|
num_groups |
int
|
Number of groups when using Clifford (group) normalization. Defaults to 1. |
1
|
Source code in pdearena/modules/threed.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
FourierBasicBlock3D
¤
Bases: Module
Basic 3d FNO ResNet building block consisting of two 3d convolutional layers, two 3d SpectralConv layers and skip connections.
Source code in pdearena/modules/threed.py
__init__(in_planes, planes, modes1, modes2, modes3, stride=1, activation='gelu', norm=False)
¤
Initialize basic 3d FNO ResNet building block Args: in_planes (int): Input channels planes (int): Output channels modes1 (int): Fourier modes for x direction. modes2 (int): Fourier modes for y direction. modes3 (int): Fourier modes for z direction. stride (int, optional): stride of 2d convolution. Defaults to 1. norm (bool): Wether to use normalization. Defaults to False.
Source code in pdearena/modules/threed.py
forward(x)
¤
Forward pass of basic 3d Fourier ResNet building block. Args: x (torch.Tensor): input of shape [batch, in_planes, x, y, z] Returns: torch.Tensor: output of shape [batch, planes, x, y, z]
Source code in pdearena/modules/threed.py
MaxwellResNet3D
¤
Bases: Module
3d ResNet model for Maxwell equations, difference to default ResNet architectures is that spatial resolution and channels (in_planes) stay constant throughout the network.
Source code in pdearena/modules/threed.py
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 159 160 161 162 163 164 165 166 167 168 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 |
|
__init__(block, num_blocks, time_history, time_future, hidden_channels=64, activation='gelu', diffmode=False)
¤
Initialize 3d ResNet model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block |
Module
|
basic 3d ResNet building block |
required |
num_blocks |
list
|
list of basic building blocks per layer |
required |
time_history |
int
|
input timesteps |
required |
time_future |
int
|
prediction timesteps |
required |
hidden_channels |
int
|
hidden channels in the ResNet blocks |
64
|
Source code in pdearena/modules/threed.py
forward(x)
¤
Forward pass of the ResNet in 3 spatial dimensions consisting of embedding layer(s), ResNet building blogs and output layer. Args: x (torch.Tensor): input tensor of shape [b, time_history, 6, x, y, z] Returns: torch.Tensor: output tensor of shape [b, time_future, 6, x, y, z]