Available conditioned PDE Surrogate Modules¤
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/conditioned/twod_unet.py
__init__(n_channels, n_heads=1, d_k=None, n_groups=1)
¤
Source code in pdearena/modules/conditioned/twod_unet.py
DownBlock
¤
Bases: ConditionedBlock
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 |
cond_channels |
int
|
Number of channels in the conditioning vector. |
required |
has_attn |
bool
|
Whether to use attention block |
False
|
activation |
Module
|
Activation function |
'gelu'
|
norm |
bool
|
Whether to use normalization |
False
|
use_scale_shift_norm |
bool
|
Whether to use scale and shift approach to conditoning (also termed as |
False
|
Source code in pdearena/modules/conditioned/twod_unet.py
Downsample
¤
Bases: Module
Scale down the feature map by \(\frac{1}{2} \times\)
Source code in pdearena/modules/conditioned/twod_unet.py
FourierDownBlock
¤
Bases: ConditionedBlock
Down block This combines ResidualBlock
and AttentionBlock
.
These are used in the first half of U-Net at each resolution.
Source code in pdearena/modules/conditioned/twod_unet.py
FourierResidualBlock
¤
Bases: ConditionedBlock
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 |
cond_channels |
int
|
Number of channels in the conditioning vector. |
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
|
use_scale_shift_norm |
bool
|
Whether to use scale and shift approach to conditoning (also termed as |
False
|
Source code in pdearena/modules/conditioned/twod_unet.py
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 |
|
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
|
param_conditioning |
Optional[str]
|
Type of conditioning to use. Defaults to None. |
None
|
use_scale_shift_norm |
bool
|
Whether to use scale and shift approach to conditoning (also termed as |
False
|
use1x1 |
bool
|
Whether to use 1x1 convolutions in the initial and final layer. |
False
|
Source code in pdearena/modules/conditioned/twod_unet.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 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 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 |
|
FourierUpBlock
¤
Bases: ConditionedBlock
Up block This combines ResidualBlock
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/conditioned/twod_unet.py
MiddleBlock
¤
Bases: ConditionedBlock
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 |
cond_channels |
int
|
Number of channels in the conditioning vector. |
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
|
use_scale_shift_norm |
bool
|
Whether to use scale and shift approach to conditoning (also termed as |
False
|
Source code in pdearena/modules/conditioned/twod_unet.py
ResidualBlock
¤
Bases: ConditionedBlock
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 |
cond_channels |
int
|
Number of channels in the conditioning vector. |
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
|
use_scale_shift_norm |
bool
|
Whether to use scale and shift approach to conditoning (also termed as |
False
|
Source code in pdearena/modules/conditioned/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
|
param_conditioning |
Optional[str]
|
Type of conditioning to use. Defaults to None. |
None
|
use_scale_shift_norm |
bool
|
Whether to use scale and shift approach to conditoning (also termed as |
False
|
use1x1 |
bool
|
Whether to use 1x1 convolutions in the initial and final layers |
False
|
Note
Currently, only scalar
parameter conditioning is supported.
Source code in pdearena/modules/conditioned/twod_unet.py
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 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
UpBlock
¤
Bases: ConditionedBlock
Up block This 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 |
cond_channels |
int
|
Number of channels in the conditioning vector. |
required |
has_attn |
bool
|
Whether to use attention block |
False
|
activation |
str
|
Activation function |
'gelu'
|
norm |
bool
|
Whether to use normalization |
False
|
use_scale_shift_norm |
bool
|
Whether to use scale and shift approach to conditoning (also termed as |
False
|
Source code in pdearena/modules/conditioned/twod_unet.py
fourier_embedding(timesteps, dim, max_period=10000)
¤
Create sinusoidal timestep embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timesteps |
Tensor
|
a 1-D Tensor of N indices, one per batch element. These may be fractional. |
required |
dim |
int
|
the dimension of the output. |
required |
max_period |
int
|
controls the minimum frequency of the embeddings. |
10000
|
Returns: embedding (torch.Tensor): [N \(\times\) dim] Tensor of positional embeddings.