augernet.gnn_train_utils¶
CosineAnnealingWarmupScheduler
¶
Bases: _LRScheduler
Cosine Annealing with Linear Warmup scheduler.
During warmup phase: linearly increases LR from 0 to max_lr During cosine phase: decreases LR using cosine annealing to min_lr
Args: optimizer: PyTorch optimizer warmup_epochs: Number of epochs for linear warmup max_epochs: Total number of epochs min_lr: Minimum learning rate (default: 1e-7) last_epoch: The index of last epoch (default: -1)
Source code in src/augernet/gnn_train_utils.py
get_lr()
¶
Calculate learning rate for current epoch.
Source code in src/augernet/gnn_train_utils.py
EquivariantMPNNLayer
¶
Bases: MessagePassing
Source code in src/augernet/gnn_train_utils.py
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 | |
__init__(emb_dim=64, edge_dim=4, aggr='add')
¶
Message Passing Neural Network Layer This layer is equivariant to 3D rotations and translations.
Args:
emb_dim: (int) - hidden dimension d
edge_dim: (int) - edge feature dimension d_e
aggr: (str) - aggregation function ⊕ (sum/mean/max)
Source code in src/augernet/gnn_train_utils.py
aggregate(inputs, index, ptr=None, dim_size=None)
¶
Aggregates messages from neighboring nodes.
Since message() returns a tuple (feature_message, coordinate_message), we aggregate each component separately using the chosen aggregator.
Source code in src/augernet/gnn_train_utils.py
forward(h, pos, edge_index, edge_attr)
¶
Forward pass: one round of message passing.
Args: h: (n, d) - initial node features pos: (n, 3) - initial node coordinates edge_index: (2, e) - edge index tensor with shape [2, num_edges] edge_attr: (e, d_e) - edge features
Returns: out: tuple of [(n, d), (n, 3)] - updated node features and coordinates
Source code in src/augernet/gnn_train_utils.py
message(h_i, h_j, pos_i, pos_j, edge_attr)
¶
Message function.
For each edge (i, j): - Compute the invariant squared distance: d2 = ||pos_i - pos_j||^2. - Compute a feature message based on h_i, h_j, edge_attr, and d2. - Compute a scalar weight (via mlp_coord) and form the coordinate message as: weight * (pos_i - pos_j)
Returns a tuple of (feature_message, coordinate_message).
Source code in src/augernet/gnn_train_utils.py
update(aggr_out, h, pos)
¶
Updates the node features and coordinates.
- The new node features are computed as φ(concat(old features, aggregated feature messages)). This update is invariant.
- The new coordinates are given by pos + (aggregated coordinate messages). Because the coordinate messages are equivariant, this update is equivariant.
Source code in src/augernet/gnn_train_utils.py
InvariantMPNNLayer
¶
Bases: MessagePassing
Source code in src/augernet/gnn_train_utils.py
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
__init__(emb_dim=64, edge_dim=4, aggr='add')
¶
Message Passing Neural Network Layer This layer is equivariant to 3D rotations and translations.
Args:
emb_dim: (int) - hidden dimension d
edge_dim: (int) - edge feature dimension d_e
aggr: (str) - aggregation function ⊕ (sum/mean/max)
Source code in src/augernet/gnn_train_utils.py
aggregate(inputs, index, ptr=None, dim_size=None)
¶
Aggregates messages from neighboring nodes.
Since message() returns a tuple (feature_message, coordinate_message), we aggregate each component separately using the chosen aggregator.
Source code in src/augernet/gnn_train_utils.py
forward(h, pos, edge_index, edge_attr)
¶
Forward pass: one round of message passing.
Args: h: (n, d) - initial node features pos: (n, 3) - initial node coordinates edge_index: (2, e) - edge index tensor with shape [2, num_edges] edge_attr: (e, d_e) - edge features
Returns: out: tuple of [(n, d), (n, 3)] - updated node features and coordinates
Source code in src/augernet/gnn_train_utils.py
message(h_i, h_j, pos_i, pos_j, edge_attr)
¶
Message function.
For each edge (i, j): - Compute the invariant squared distance: d2 = ||pos_i - pos_j||^2. - Compute a feature message based on h_i, h_j, edge_attr, and d2. - Compute a scalar weight (via mlp_coord) and form the coordinate message as: weight * (pos_i - pos_j)
Returns a tuple of (feature_message, coordinate_message).
Source code in src/augernet/gnn_train_utils.py
update(aggr_out, h, pos)
¶
Updates the node features and coordinates.
- The new node features are computed as φ(concat(old features, aggregated feature messages)). This update is invariant.
- The new coordinates are given by pos + (aggregated coordinate messages). Because the coordinate messages are equivariant, this update is equivariant.
Source code in src/augernet/gnn_train_utils.py
LoadDataset
¶
Bases: InMemoryDataset
Generic wrapper around a pre-collated (data, slices) file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str | Path
|
Directory that contains the processed file. |
required |
file_name
|
str
|
Name of the processed file to load. |
"data.pt"
|
**kwargs
|
Forwarded to |
{}
|
Source code in src/augernet/gnn_train_utils.py
MPNN
¶
Bases: Module
Source code in src/augernet/gnn_train_utils.py
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 | |
__init__(num_layers=4, emb_dim=64, in_dim=11, edge_dim=4, out_dim=1, layer_type='IN', pred_type='AUGER', spectrum_type='stick', spectrum_dim=300, dropout=0.0)
¶
Message Passing Neural Network model for graph property prediction
This model uses both node features and coordinates as inputs, and is invariant to 3D rotations and translations (the constituent MPNN layers are equivariant to 3D rotations and translations).
Args:
num_layers: (int) - number of message passing layers L
emb_dim: (int) - hidden dimension d
in_dim: (int) - initial node feature dimension d_n
edge_dim: (int) - edge feature dimension d_e
out_dim: (int) - output dimension (CEBE only, fixed to 1)
spectrum_type: (str) - 'stick' or 'fitted'
stick: two heads (energy + intensity), each → spectrum_dim (default 300)
total output = 2 * spectrum_dim = 600
fitted: single intensity head → spectrum_dim (default 731)
spectrum_dim: (int) - per-head output dimension
stick mode: 300 (energy 300 + intensity 300 = 600)
fitted mode: 731 (intensity only on common energy grid)
dropout: (float) - dropout probability between message passing layers (0 = off)
Source code in src/augernet/gnn_train_utils.py
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 | |
forward(data)
¶
Args: data: (PyG.Data) - batch of PyG graphs
Returns: out: (batch_size, out_dim) - prediction for each graph
Source code in src/augernet/gnn_train_utils.py
eval_mpnn(data_loader, model, device, layer_type, pred_type, spectrum_type='stick')
¶
One pass over data_loader without gradient to compute mean loss.
Args: spectrum_type: 'stick' (600-dim energy+intensity) or 'fitted' (n_points intensity)
Source code in src/augernet/gnn_train_utils.py
permutation_equivariance_unit_test_layer(module, dataloader, lin_in=None)
¶
Unit test for checking whether a single MPNN layer is permutation equivariant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
MessagePassing layer
|
|
required |
dataloader
|
DataLoader
|
|
required |
lin_in
|
Module
|
The model's input projection ( |
None
|
Source code in src/augernet/gnn_train_utils.py
permutation_equivariance_unit_test_model(module, dataloader)
¶
Unit test for checking whether a node-level GNN model is permutation equivariant.
For a node-level model (no global pooling), permuting the input nodes should permute the output rows in the same way: out(π(G))[i] == out(G)[π⁻¹(i)] ⟺ out_2 == out_1[perm]
Note: The old test checked out_1 == out_2 which is invariance —
correct only for graph-level (pooled) models, not node-level ones.
Source code in src/augernet/gnn_train_utils.py
permute_graph(data, perm)
¶
Helper function for permuting PyG Data object attributes consistently.
Source code in src/augernet/gnn_train_utils.py
random_orthogonal_matrix(dim=3)
¶
Helper function to build a random orthogonal matrix of shape (dim, dim)
rot_trans_equivariance_unit_test(module, dataloader, lin_in=None)
¶
Unit test for checking whether a module (GNN layer) is rotation and translation equivariant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lin_in
|
Module
|
The model's input projection ( |
None
|
Source code in src/augernet/gnn_train_utils.py
rot_trans_invariance_unit_test(module, dataloader, lin_in=None)
¶
Unit test for checking whether a module (GNN model/layer) is rotation and translation invariant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lin_in
|
Module
|
The model's input projection ( |
None
|
Source code in src/augernet/gnn_train_utils.py
run_unit_tests(model, data_list, layer_type='IN', batch_size=1)
¶
Run permutation and rotation/translation symmetry unit tests on a trained GNN model and its first message-passing layer.
For a node-level model (no global pooling), the correct symmetry property is permutation equivariance — permuting the input nodes should permute the output rows in the same way.
For the layer-level tests, model.lin_in is used to project the raw
node features down to emb_dim before feeding them into the bare
layer, avoiding a dimension mismatch.
Args: model: (MPNN) — the trained model (in eval mode). data_list: list[Data] — dataset (at least 1 graph). layer_type: (str) — 'EQ' or 'IN'. batch_size: (int) — batch size for the test dataloader (default 1).
Returns: results: dict mapping test name → bool (pass/fail).
Source code in src/augernet/gnn_train_utils.py
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | |
train_loop(data_list, model, device, num_epochs=100, batch_size=64, max_lr=0.01, pct_start=0.6, verbose=True, layer_type='IN', pred_type='AUGER', plot_results=False, val_data_list=None, patience=50, optimizer_type='adamw', weight_decay=0.0001, gradient_clip_norm=0.5, warmup_epochs=10, min_lr=1e-07, spectrum_type='stick', scheduler_type='cosine')
¶
Advanced training loop with gradient clipping, configurable optimizer and LR scheduler.
Args: data_list: Training data model: Neural network model device: Device to train on num_epochs: Number of training epochs batch_size: Batch size max_lr: Maximum learning rate pct_start: For OneCycleLR, percentage of training steps allocated to warmup verbose: Whether to print training progress layer_type: Layer type (IN/EQ/PE) pred_type: Prediction type (CEBE/AUGER) plot_results: Whether to plot training results val_data_list: Validation data (if None, will split from training data) optimizer_type: 'adam', 'adamw' (default: 'adamw') weight_decay: L2 regularization weight gradient_clip_norm: Max gradient norm for clipping (default: 1.0) warmup_epochs: Number of epochs for warmup in cosine scheduler (default: 10) min_lr: Minimum learning rate for cosine scheduler (default: 1e-7) spectrum_type: 'stick' (600-dim energy+intensity with mask) or 'fitted' (n_points intensity on common grid, no mask) scheduler_type: 'cosine' (CosineAnnealingWarmup, per-epoch) or 'onecycle' (OneCycleLR, per-batch — original AUGER schedule)
Source code in src/augernet/gnn_train_utils.py
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 703 704 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 | |