We present cod-bench containing 12 operators and 10 datasets.
The datasets used for benchmarking can be downloaded from here.
4 steps are required to take a pair of model and dataset and to perform the training and testing.
- Loading data
- Creating the Pytorch Model
- Choosing optimizer, scheduler, loss function and hyperparameter for training.
- Putting them all together, create a training and testing loop to use the model.
All these functionalities are written using a specific module for each task. More details about each of the module is given below. Completely functional code (Run_files) are attached for more working examples.
The codebase contains 4 major modules.
- Loader Modules: Provides functionality of turning datasets to PyTorch DataLoaders.
- Operator Modules: Contains Implementation of all models benchamrked in the paper in fully functional form using PyTorch Framework.
- Utility Modules: Helper functions providing utilities such as transforms, loss functions, optimizers etc.
- Trainer Module: Provides a common interface for training and testing any pair of model, dataset.
Loader Modules:
A. dataloader.py: Provides the functionality of processing the raw dataset provided and split it into pytorch tensors of train, validation and test set. eg. code:
- PATH = 'data/Biaxial_N70000_D28.npz'.
- loader = npzloader(path=PATH).
- x_train, y_train, x_val, y_val, x_test, y_test = loader.split(ntrain, nval, ntest).
B. loader_1d.py, loader_2d.py: Provides the tool to convert the pytorch tensors of data into Pytorch dataloader that can be directly used in the traning process. Provides functionality such as input/output normalization, grid_data appended loader etc. eg. code:
- train_obj = DataLoader_2D(X=x_train, y=y_train, n=ntrain, res=training_data_resolution,
grid_size=grid_size, batch_size=batch_size, x_normalizer=x_normalizer) - train_grid_loader = train_obj.get_grid_loader()
C. loader_gnot.py: GNOT combines all data in the form of a graph before training phase. This module allows to create the graph dataloader for all datasets for use with the GNOT model.
Given model and the choice of optimization and loss functions, hyperparameters, it create a suitable Trainer instance. Fit function in each of the class of this module trains the model till convergence on the given train_loader. Test function can be used to see the performance of the model on test set once trained. eg. code:
- hyperparameters = {
- 'lr': 1e-3,
- 'weight_decay': 1e-4,
- 'step_size': 100,
- 'gamma': 0.5,
- 'optimizer': 'Adam',
- 'scheduler': 'StepLR',
- 'loss_fn': 'RelL2',
- 'loss_metric': 'MSE',
- 'batch_size': batch_size,
- 'random_seed': random_seed,
- }
- model = FNO2d()
- trainer = Trainer(model_name=FNO+Biaxial", model=model, hyperparams=hyperparameters,
output_transform=out_transform, device=device) - trainer.fit(train_dataloader=train_grid_loader, val_dataloader=val_grid_loader, test_dataloader=test_grid_loader)
- loss1, loss2 = trainer.test(test_dataloader=test_grid_loader)
- All code used for experimentation is provided in form of run_{model_name}_{dataset_name}.py python scripts.
- Since the input output data processing for 5 of the models: FNO, WNO, FNN, ResNet, UNet is similar they all are included in a single file. Such code can be found in scripts like run1_darcy.py, run1_nvs.py etc.
- The basic data processing is similar for the models: DeepONet, POD-DeepONet, SNO. Code for running these models can be found in files run2_{dataset_name}.py files.
- Code for running model_name in {'CGAN', 'GNOT', 'OFORMER', 'LSM'} can be found in files named as run_{model_name}_{dataset_name}.py files.