This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
General Physics Transformer (GPhyT) — a foundation model for physics simulation that combines a transformer-based neural differentiator with numerical integration. Trains on HDF5 datasets (The Well format) spanning diverse physical systems (Navier-Stokes, heat transfer, two-phase flow, etc.).
Paper: https://arxiv.org/abs/2509.13805
# Uses uv with hatchling build backend. PyTorch from cu129 index.
pip install -e ".[dev]"Requires Python >= 3.13.
# All tests
pytest tests/
# Single test file
pytest tests/test_models/test_transformer/test_model.py
# Single test
pytest tests/test_models/test_transformer/test_model.py::TestClassName::test_method -vKnown: ~21 data tests fail because the dummy HDF5 fixtures in tests/conftest.py use generic field names (e.g. "variable_field1") instead of physics field names like "pressure". These are pre-existing failures.
# Single-GPU training
python gphyt/train/run_training.py --config_path <path_to_config.yaml>
# Multi-GPU with torchrun
torchrun --standalone --nproc_per_node=N gphyt/train/run_training.py --config_path <config>
# Evaluation
python gphyt/train/model_eval.py --config_file <config> --sim_name <name> --log_dir <dir> --data_dir <dir> --checkpoint_name <best_model|epoch_num> --forecast_horizons 1 4 8SLURM scripts in gphyt/train/scripts/ (train_riv.sh, eval.sh).
gphyt/
├── data/ # Data loading & preprocessing
├── models/ # Model definitions
└── train/ # Training loop, evaluation, utilities
├── scripts/ # Shell scripts (SLURM launchers)
└── utils/ # Checkpointing, logging, LR scheduling, visualization
gphyt/models/model_utils.py—get_model(model_config): dispatches togphyt,unet, orfnobased onarchitecturekeygphyt/data/dataset.py—get_dataset(config, split): buildsSuperDatasetofPhysicsDatasetsgphyt/train/run_training.py— CLI entry point; parses YAML config, builds model/data/optimizer, createsTrainer
- GPhyT (
gphyt/models/transformer/): Tokenizer → Transformer (attention blocks with RoPE or absolute pos encoding) → Finite-difference derivative estimation → Numerical integration (Euler/RK4/Heun) → Detokenizer. Size variants: GPT_S, GPT_M, GPT_L, GPT_XL (inmodel_specs.py). - FNO (
gphyt/models/fno.py): Fourier Neural Operator wrapper usingneuraloperatorlibrary'sFNOclass withn_modes=(t,h,w)tuple. - UNet (
gphyt/models/unet.py): Convolutional U-Net. Variants: UNet_S, UNet_M.
PhysicsDataset(gphyt/data/phys_dataset.py): wrapsWellDataset(HDF5 loader), handles input/output windowing (n_steps_input,n_steps_output), z-score normalization, spatial resizing, dt_stride, and data augmentation (flips).SuperDataset: concatenates multiplePhysicsDatasets, supportsmax_samplesper dataset.- Data format: HDF5 per The Well spec — fields stored in
t0_fields/,t1_fields/,t2_fields/groups with shape(n_trajectories, n_steps, x, y [, n_dim]).
Trainer(gphyt/train/train_base.py): full training loop with DDP support, AMP (bfloat16/float16), gradient checkpointing viamem_budget, autoregressive training (n_ar_steps), W&B logging.Evaluator(gphyt/train/eval.py): validation loop supporting AR rollout evaluation.model_eval.py: standalone detailed evaluation with per-dataset, per-horizon metrics and visualization.
Nested YAML with top-level keys: wandb, logging, model, training, data. See gphyt/train/train.yml for the reference config. Also supports a flat format for backward compatibility.
- Generic: MSE, MAE, RMSE, NRMSE, VRMSE in
gphyt/models/loss_fns.py - GPhyT-specific: NMSELoss, VMSELoss, RNMSELoss, RVMSELoss in
gphyt/models/transformer/loss_fns.py(supportreturn_scalarand dimension selection)