ConvNet¶
Residual convolutional network for PDE data.
convnet
¶
Unified Convolutional Neural Network for FlowPDE.
Dimension-agnostic CNN that handles both 1D and 2D spatial data through explicit configuration rather than heuristic inference.
ResidualBlock
¶
Bases: Module
Dimension-agnostic residual block with time conditioning.
Pre-activation ResNet block: Norm → Act → Conv → Norm → Act → Conv Time embedding is added after the first convolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial_dim
|
int
|
Spatial dimensionality (1 or 2) |
required |
channels
|
int
|
Number of input/output channels |
required |
kernel_size
|
int
|
Convolution kernel size |
3
|
time_emb_dim
|
int
|
Dimension of time embedding |
64
|
norm_type
|
str
|
Normalization type ('group', 'batch', 'instance', 'none') |
'group'
|
activation
|
str
|
Activation function name |
'swish'
|
dropout
|
float
|
Dropout probability (0 = no dropout) |
0.0
|
Source code in flowpde/models/convnet.py
forward(x, t_emb)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor (B, C, L) for 1D or (B, C, H, W) for 2D |
required |
t_emb
|
Tensor
|
Time embedding (B, time_emb_dim) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Output with residual connection, same shape as input |
Source code in flowpde/models/convnet.py
ConvNet
¶
Bases: Module
Unified Convolutional Neural Network for flow matching on PDE data.
A dimension-agnostic CNN that uses residual blocks with time conditioning. Suitable for both 1D problems (e.g., Burgers equation) and 2D problems (e.g., Poisson equation).
Architecture
Input Conv → [ResidualBlock × num_blocks] → Output Norm → Output Conv
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial_dim
|
int
|
Spatial dimensionality (1 or 2) |
required |
spatial_size
|
int
|
Size of spatial domain (int for 1D, int for square 2D) |
required |
hidden_channels
|
int
|
Number of hidden channels |
required |
num_blocks
|
int
|
Number of residual blocks |
required |
solution_channels
|
int
|
Number of channels in solution (default: 1) |
1
|
condition_channels
|
int
|
Number of channels in condition (default: 1) |
1
|
kernel_size
|
int
|
Convolution kernel size (default: 3) |
3
|
norm_type
|
str
|
Normalization type ('group', 'batch', 'instance', 'none') |
'group'
|
activation
|
str
|
Activation function name ('swish', 'relu', 'gelu') |
'swish'
|
dropout
|
float
|
Dropout probability (default: 0.0) |
0.0
|
return_spatial
|
bool
|
If True, return spatial tensor; if False, flatten (default: False) |
False
|
Source code in flowpde/models/convnet.py
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 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 | |
forward(x, f, t)
¶
Predict velocity field for flow matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
State x_t, shape (B, C, spatial) or flattened (B, Cspatial) |
required |
f
|
Tensor
|
Condition, shape (B, C', spatial) or flattened (B, C'spatial) |
required |
t
|
Tensor
|
Time t ∈ [0, 1], shape (B,) or (B, 1) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Velocity field v(x, f, t), same shape as x (or flattened if return_spatial=False) |