ResNet¶
Fully convolutional ResNet architecture.
resnet
¶
ResNet architecture for FlowPDE.
Residual Network optimized for PDE solving with flow matching. Unlike classification ResNets, this preserves spatial resolution (no global pooling) to output full velocity fields.
BasicBlock
¶
Bases: Module
Basic residual block with time conditioning.
Structure: Conv → Norm → Act → Conv → Norm → (+skip) → Act
This is the standard ResNet BasicBlock adapted for: 1. Dimension-agnostic operation (1D/2D) 2. Time conditioning via additive embedding 3. Optional channel expansion for skip connection
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial_dim
|
int
|
Spatial dimensionality (1 or 2) |
required |
in_channels
|
int
|
Number of input channels |
required |
out_channels
|
int
|
Number of output channels |
required |
kernel_size
|
int
|
Convolution kernel size |
3
|
time_emb_dim
|
int
|
Dimension of time embedding |
128
|
stride
|
int
|
Convolution stride (default: 1) |
1
|
norm_type
|
str
|
Normalization type |
'group'
|
activation
|
str
|
Activation function name |
'swish'
|
use_film
|
bool
|
Whether to apply FiLM conditioning inside the block |
False
|
film_condition_dim
|
Optional[int]
|
Conditioning vector dimension for FiLM |
None
|
film_hidden_dim
|
Optional[int]
|
Hidden dimension for FiLM parameter generation |
None
|
Source code in flowpde/models/resnet.py
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 | |
forward(x, t_emb, condition=None)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
t_emb
|
Tensor
|
Time embedding (B, time_emb_dim) |
required |
condition
|
Optional[Tensor]
|
Optional conditioning tensor for FiLM |
None
|
Source code in flowpde/models/resnet.py
ResNetStage
¶
Bases: Module
A stage (group of blocks) in ResNet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial_dim
|
int
|
Spatial dimensionality (1 or 2) |
required |
in_channels
|
int
|
Input channels to stage |
required |
out_channels
|
int
|
Output channels from stage |
required |
num_blocks
|
int
|
Number of BasicBlocks in stage |
required |
time_emb_dim
|
int
|
Dimension of time embedding |
128
|
stride
|
int
|
Stride for first block (for downsampling) |
1
|
norm_type
|
str
|
Normalization type |
'group'
|
activation
|
str
|
Activation function name |
'swish'
|
use_film
|
bool
|
Whether to apply FiLM conditioning inside blocks |
False
|
film_condition_dim
|
Optional[int]
|
Conditioning vector dimension for FiLM |
None
|
film_hidden_dim
|
Optional[int]
|
Hidden dimension for FiLM parameter generation |
None
|
Source code in flowpde/models/resnet.py
ResNet
¶
Bases: Module
ResNet architecture for flow matching on PDE data.
This is a fully convolutional ResNet designed for PDE solving: - No global average pooling (preserves spatial structure) - No classification head (outputs full velocity field) - Time conditioning at every residual block - Configurable depth and width
Architecture
Stem → [Stage1 → Stage2 → ... → StageN] → Output Conv
For PDE solving, we typically don't downsample (stride=1 everywhere) to preserve spatial resolution for the velocity field output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial_dim
|
int
|
Spatial dimensionality (1 or 2) |
required |
spatial_size
|
int
|
Size of spatial domain |
required |
base_channels
|
int
|
Base number of channels (doubled at each stage if downsample) |
64
|
blocks_per_stage
|
Optional[List[int]]
|
Number of blocks in each stage (list or int) |
None
|
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') |
'group'
|
activation
|
str
|
Activation function name ('swish', 'relu', 'gelu') |
'swish'
|
downsample
|
bool
|
Whether to downsample between stages (default: False for PDEs) |
False
|
return_spatial
|
bool
|
If True, return spatial tensor; if False, flatten |
False
|
Example configurations
ResNet-8: blocks_per_stage=[1, 1, 1, 1] with base_channels=32 ResNet-14: blocks_per_stage=[2, 2, 2] with base_channels=64 ResNet-18: blocks_per_stage=[2, 2, 2, 2] with base_channels=64
Source code in flowpde/models/resnet.py
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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 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 | |
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
|
Optional[Tensor]
|
Condition, shape (B, C', spatial) or flattened (B, C'spatial). Optional when using NullConditioner. |
required |
t
|
Tensor
|
Time t ∈ [0, 1], shape (B,) or (B, 1) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Velocity field v(x, f, t) |
Source code in flowpde/models/resnet.py
resnet8(spatial_dim, spatial_size, **kwargs)
¶
ResNet-8: Lightweight model for small grids.
Source code in flowpde/models/resnet.py
resnet14(spatial_dim, spatial_size, **kwargs)
¶
ResNet-14: Medium model for moderate complexity.
Source code in flowpde/models/resnet.py
resnet18(spatial_dim, spatial_size, **kwargs)
¶
ResNet-18: Standard model for most PDE problems.
Source code in flowpde/models/resnet.py
resnet26(spatial_dim, spatial_size, **kwargs)
¶
ResNet-26: Deeper model for complex PDEs.