Skip to content

Commit b9a0955

Browse files
committed
Fix PyTorch 2.6 serialization Exception in data generation
1 parent 90729cc commit b9a0955

20 files changed

+372
-231
lines changed

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Set up Python
2424
uses: actions/setup-python@v2
2525
with:
26-
python-version: 3.8
26+
python-version: 3.10
2727

2828
- name: Install pip
2929
run: python -m pip install --upgrade pip

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
## Summary
44

5-
This repository features two parts:
5+
This repository contains mainly two parts:
66

77
### Part I: a native PyTorch port of [Google's Computational Fluid Dynamics package in Jax](https://github.com/google/jax-cfd)
88
The main changes are documented in the `README.md` under the [`torch_cfd` directory](./torch_cfd/). The most significant changes in all routines include:
9-
- Routines that rely on the functional programming of Jax have been rewritten to be a more debugger-friendly PyTorch tensor-in-tensor-out style.
9+
- Routines that rely on the functional programming of Jax have been rewritten to be the PyTorch's tensor-in-tensor-out style, which is arguably more user-friendly to debugging as one can view immediate tensors using Data Wrangler in VS Code.
1010
- Functions and operators are in general implemented as `nn.Module` like a factory template.
1111
- Jax-cfd's `funcutils.trajectory` function supports tracking only one field variable (vorticity or velocity). For this port, extra fields computation and tracking are made more accessible, such as time derivatives $\partial_t\boldsymbol{v}$ and PDE residual $R(\boldsymbol{v}):=\boldsymbol{f}-\partial_t \boldsymbol{v}-(\boldsymbol{v}\cdot\nabla)\boldsymbol{v} + \nu \Delta \boldsymbol{v}$.
12-
- All ops take into consideration the batch dimension of tensors `(b, *, n, n)` regardless of `*` dimension, which is similar to PyTorch behavior, not a single trajectory like Google's original Jax-CFD package.
12+
- All ops take into consideration the batch dimension of tensors `(b, *, n, m)` regardless of `*` dimension, for example, `(b, T, C, n, n)`, which is similar to PyTorch behavior, not a single trajectory like Google's original Jax-CFD package.
1313

14-
### Part II: Spectral-Refiner: Neural Operator-Assisted Navier-Stokes Equations solver.
15-
- The **Spatiotempoeral Fourier Neural Operator** (SFNO) is a spacetime tensor-to-tensor learner (or trajectory-to-trajectory), available in the [`sfno` directory](./sfno/). We draw inspiration from the [3D FNO in Nvidia's Neural Operator repo](https://github.com/neuraloperator/neuraloperator), as well as Temam's book on functional analysis for NSE. Major architectural changes can be found in [the documentation of the `SFNO` class](https://github.com/scaomath/torch-cfd/blob/c88607dd9c87e4232c01102233c4ddc74398c9d8/sfno/sfno.py#L465).
14+
### Part II: Spectral-Refiner: Neural Operator-Assisted Navier-Stokes Equations simulator.
15+
- The **Spatiotemporal Fourier Neural Operator** (SFNO) is a spacetime tensor-to-tensor learner (or trajectory-to-trajectory), available in the [`sfno` directory](./sfno/). We draw inspiration from the [3D FNO in Nvidia's Neural Operator repo](https://github.com/neuraloperator/neuraloperator), as well as Temam's book on functional analysis for NSE. Major architectural changes can be found in [the documentation of the `SFNO` class](./sfno/sfno.py#L547).
1616
- Data generation for the meta-example of the isotropic turbulence in [McWilliams1984]. After the warmup phase, the energy spectra match the inverse cascade of Kolmogorov flow in a periodic box.
1717
- Pipelines for the *a posteriori* error estimation to fine-tune the SFNO to reach the scientific computing level of accuracy ($\le 10^{-6}$) in Bochner norm using FLOPs on par with a single evaluation, and only a fraction of FLOPs of a single `.backward()`.
1818
- [Examples](#examples) can be found below.
@@ -25,6 +25,11 @@ To install `torch-cfd`'s current release, simply do:
2525
pip install torch-cfd
2626
```
2727
If one wants to play with the neural operator part, it is recommended to clone this repo and play it locally by creating a venv using `requirements.txt`. Note: using PyTorch version >=2.0.0 for the broadcasting semantics.
28+
```bash
29+
python3.11 -m venv venv
30+
source venv/bin/activate
31+
pip install -r requirements.txt
32+
```
2833

2934
## Data
3035
The data are available at [https://huggingface.co/datasets/scaomath/navier-stokes-dataset](https://huggingface.co/datasets/scaomath/navier-stokes-dataset).
@@ -34,7 +39,7 @@ Data generation instructions are available in the [SFNO folder](./sfno/).
3439
## Examples
3540
- Demos of different simulation setups:
3641
- [2D simulation with a pseudo-spectral solver](./examples/Kolmogrov2d_rk4_cn_forced_turbulence.ipynb)
37-
- Demos of Spatiotemporal FNO's training and evaluation
42+
- Demos of Spatiotemporal FNO's training and evaluation using the neural operator-assisted fluid simulation pipelines
3843
- [Training of SFNO for only 15 epochs for the isotropic turbulence example](./examples/ex2_SFNO_train.ipynb)
3944
- [Training of SFNO for only ***10*** epochs with 1k samples and reach `1e-2` level of relative error](./examples/ex2_SFNO_train_fnodata.ipynb) using the data in the FNO paper, which to our best knowledge no operator learner can do this in <100 epochs in the small data regime.
4045
- [Fine-tuning of SFNO on a `256x256` grid for only 50 ADAM iterations to reach `1e-6` residual in the functional norm using FNO data](./examples/ex2_SFNO_finetune_fnodata.ipynb)
@@ -43,7 +48,7 @@ Data generation instructions are available in the [SFNO folder](./sfno/).
4348
- [Baseline of FNO3d for fixed step size that requires preloading a normalizer](./examples/ex2_FNO3d_train_normalized.ipynb)
4449

4550
## Licenses
46-
The Apache 2.0 License in the root folder applies to the `torch-cfd` folder of the repo that is inherited from Google's original license file for `Jax-cfd`. The `fno` folder has the MIT license inherited from [NVIDIA's Neural Operator repo](https://github.com/neuraloperator/neuraloperator). Note: the license(s) in the subfolder takes precedence.
51+
The Apache 2.0 License in the root folder applies to the `torch-cfd` folder of the repo that is inherited from Google's original license file for `Jax-cfd`. The `sfno` folder has the MIT license inherited from [NVIDIA's Neural Operator repo](https://github.com/neuraloperator/neuraloperator). Note: the license(s) in the subfolder takes precedence.
4752

4853
## Contributions
4954
PR welcome. Currently, the port of `torch-cfd` currently includes:
@@ -52,18 +57,22 @@ PR welcome. Currently, the port of `torch-cfd` currently includes:
5257
- Boundary conditions: only periodic boundary conditions.
5358

5459
## Reference
60+
61+
If you like to use `torch-cfd` please use the following [paper](https://arxiv.org/abs/2405.17211) as citation.
62+
5563
```bibtex
56-
@article{2024SpectralRefiner,
57-
title={Spectral-Refiner: Fine-Tuning of Accurate Spatiotemporal Neural Operator for Turbulent Flows},
58-
author={Shuhao Cao and Francesco Brarda and Ruipeng Li and Yuanzhe Xi},
59-
journal={arXiv preprint arXiv:2405.17211},
60-
year={2024},
61-
primaryClass={cs.LG}
64+
@inproceedings{2025SpectralRefiner,
65+
title = {Spectral-Refiner: Accurate Fine-Tuning of Spatiotemporal Fourier Neural Operator for Turbulent Flows},
66+
author = {Shuhao Cao and Francesco Brarda and Ruipeng Li and Yuanzhe Xi},
67+
booktitle = {The Thirteenth International Conference on Learning Representations},
68+
year = {2025},
69+
url = {https://openreview.net/forum?id=MKP1g8wU0P},
70+
eprint = {arXiv:2405.17211},
6271
}
6372
```
6473

6574
## Acknowledgments
66-
The research of Brarda and Xi is supported by the National Science Foundation award DMS-2208412.
67-
The work of Li was performed under the auspices of
68-
the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DEAC52-07NA27344 and was supported by the LLNL-LDRD program under Project No. 24ERD033. Cao is grateful for the support from [Long Chen (UC Irvine)](https://github.com/lyc102/ifem) and
69-
[Ludmil Zikatanov (Penn State)](https://github.com/HAZmathTeam/hazmath) over the years, and their efforts in open-sourcing scientific computing codes. Cao also appreciates the support from the National Science Foundation DMS-2309778, and the free A6000 credits at the SSE ML cluster from the University of Missouri.
75+
I am grateful for the support from [Long Chen (UC Irvine)](https://github.com/lyc102/ifem) and
76+
[Ludmil Zikatanov (Penn State)](https://github.com/HAZmathTeam/hazmath) over the years, and their efforts in open-sourcing scientific computing codes. I also appreciate the support from the National Science Foundation (NSF) to junior researchers. I also want to thank the free A6000 credits at the SSE ML cluster from the University of Missouri.
77+
78+
For individual paper's acknowledgement please see [here](./sfno/README.md).

0 commit comments

Comments
 (0)