A modular, package-based MeshGraphNets project for shell mechanics, built on top of NVIDIA Modulus, DGL, PyTorch, and Hydra, to predict structural displacements in static simulations.
This repository has been refactored from a script-first layout to a package-first layout so training, inference, losses, dataloading, and preprocessing are easier to maintain, test, and extend.
ShellMGN trains a GNN - (MeshGraphNet) to predict displacement components from mesh-based input data for static structural analysis.
This implementation is aligned with:
- the MeshGraphNets paper: Pfaff et al., “Learning Mesh-Based Simulation with Graph Networks” (arXiv:2010.03409) — https://arxiv.org/abs/2010.03409
- the NVIDIA Modulus MeshGraphNet implementation and ecosystem — https://docs.nvidia.com/modulus/
Core capabilities:
- Hydra-driven training with configurable losses and normalization.
- Hydra-driven inference/rollout for checkpoint-based evaluation and VTK output export.
- Modular package structure under
src/shellmgn. - Separated concerns for model, trainer, dataloader, losses, and utilities.
- WandB integration for experiment tracking.
The preprocessing pipeline is designed to take in the raw solver files (i.e., Optistruct/Nastran) and extract the helpful features and store them in HDF5 format. The hdf5 dataset is then transformed to a DGL graph dataset that's accepted by the MeshGraphNet model.
Each sample included keys used by ShellDataset:
connectivity: edge list / mesh connectivitypos: node coordinatesntypes: node type markersthickness: shell thickness per nodespc: support / constraint featuresload: applied load featuresetypes: edge type markersy: target displacement components, shaped like[num_nodes, 3]for(disp_x, disp_y, disp_z)
Current dataset split logic expects top-level HDF5 grouping like:
variant/subcase/...sample arrays...
See:
src/shellmgn/dataloader/dataloader.pysrc/shellmgn/utils.py
for the exact assumptions used during graph construction, normalization, and splitting.
Note: This preprocessing pipeline is highly specific to Optistruct/Nastran format(s) but the logic can still be adapted to other data formats.
lts-modulus/
├── pyproject.toml
├── uv.lock
├── src/
│ ├── shellmgn/
│ │ ├── main.py # training entrypoint (Hydra)
│ │ ├── conf/
│ │ │ ├── single_run_conf/
│ │ │ │ └── config.yaml # default train/infer config
│ │ │ └── multi_comp/
│ │ │ ├── config.yaml # multi-component training config
│ │ │ └── sweep.yaml # sweep config
│ │ ├── dataloader/
│ │ │ └── dataloader.py # HDF5 + DGL dataset pipeline
│ │ ├── models/
│ │ │ └── meshgraphnet.py # model definition
│ │ ├── trainer/
│ │ │ └── trainer.py # training loop and validation
│ │ ├── inference/
│ │ │ └── inference.py # rollout/prediction entrypoint
│ │ ├── losses/
│ │ │ ├── logcosh.py
│ │ │ ├── mrae.py
│ │ │ ├── multi_comp.py
│ │ │ ├── multi_comp_uncertain.py
│ │ │ └── weighted_logcosh.py
│ │ └── utils.py # metrics + split/test-index helpers
│ └── preprocess/
│ ├── main.py # preprocessing CLI entrypoint
│ └── ...
└── .venv/
This project uses:
- PEP 517 backend:
hatchling - Dependency manager / resolver:
uv - Package source root:
src/
Configured scripts in pyproject.toml:
shellmgn-train→shellmgn.main:mainshellmgn-infer→shellmgn.inference.inference:mainpreprocess→preprocess.main:main
uv venv
source .venv/bin/activateuv syncThis project uses GPU-oriented dependencies (torch, dgl, nvidia-modulus).
pyproject.toml is configured with:
- a
find-linkssource for DGL CUDA wheels - a dedicated PyTorch CUDA index (
cu124) fortorch
If you still hit platform-specific wheel issues, install the problematic package first, then re-run sync. Example:
uv pip install dgl -f https://data.dgl.ai/wheels/torch-2.4/cu124/repo.html
uv syncActive Hydra configs live in:
src/shellmgn/conf/single_run_conf/config.yamlsrc/shellmgn/conf/multi_comp/config.yamlsrc/shellmgn/conf/multi_comp/sweep.yaml
Important paths in config:
data_path: expected HDF5 dataset path (currently./data/shellmgn/dataset.hdf5)ckpt_path: checkpoint directoryresults_dir: output directorytest_idx: persisted test index file path for train→infer consistency
Default training (uses Hydra defaults in single_run_conf/config.yaml):
uv run shellmgn-trainRun with Hydra overrides:
uv run shellmgn-train loss=MSELoss normalization=z_score epochs=100Example with explicit output/checkpoint override:
uv run shellmgn-train ckpt_path=./runs/shellmgn/exp1/checkpoints results_dir=./runs/shellmgn/exp1/resultsRun inference with current defaults:
uv run shellmgn-inferWith overrides:
uv run shellmgn-infer ckpt_path=./runs/shellmgn/exp1/checkpoints results_dir=./runs/shellmgn/exp1/results test_idx=./runs/shellmgn/exp1/outputs/test_idx.ptInference exports .vtp graph files to results_dir.
The preprocessing CLI entrypoint is:
uv run preprocess generate-dataset --base-dir <raw_data_dir> --hdf5-name <output_name> --log-name <log_name>Use this to generate the HDF5 dataset consumed by data_path in Hydra configs.
Training integrates Weights & Biases. Set your API key before run:
export WANDB_API_KEY=<your_key>Then run training normally. Metrics such as training loss, LR, and validation errors are logged.
W&B Report - View-only link
This project is licensed under the Apache License 2.0.
- You are free to use, modify, and share the code.
- Keep license and attribution notices when redistributing.
See LICENSE for the full terms.
This repository is intended to contain code and configuration. If you use private/proprietary simulation data, ensure you follow your organization’s data-sharing and confidentiality policies before distributing datasets.