File size: 7,796 Bytes
3d1047d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
177
178
179
180
181
182
183
184
185
186
187
---
license: mit
language:
- en
library_name: pytorch
tags:
- OneScience
- fluid-dynamics
- neural-operator
- multiwavelet
datasets:
- OneScience-Group/fno
---

<p align="center">
  <strong><span style="font-size: 30px;">MWT</span></strong>
</p>

# Model Introduction

MWT (Multiwavelet-based Operator Learning), proposed by Gaurav Gupta, Xiongye Xiao, and Paul Bogdan, is a multiwavelet operator-learning framework. It builds fixed decomposition and reconstruction filters from orthogonal polynomials and learns differential-equation solution operators in a multiscale space, enabling data-efficient physical-field prediction and generalization across resolutions.

This repository is an independent OneScience reproduction of the two-dimensional Navier–Stokes vorticity experiment described in the paper. On a periodic unit torus, the model combines the first 10 vorticity frames with spatial and temporal coordinates and predicts the remaining \(T-10\) frames in one shot. The experiment uses a regular `64 x 64` grid downsampled from `256 x 256` data.

Paper: [Multiwavelet-based Operator Learning for Differential Equations](https://arxiv.org/abs/2109.13459)

# Model Description

MWT is a multiscale neural architecture for learning differential operators. Its pipeline is input lifting, multiwavelet decomposition, multiscale operator mapping, multiwavelet reconstruction, and vorticity projection. A linear layer first lifts the 13-dimensional input to \(c k^2=36\) features, where \(c=4\) and the Legendre multiwavelet order is \(k=3\). Fixed Legendre filter matrices from the paper and their two-dimensional Kronecker products recursively decompose both spatial dimensions.

At each scale, learnable \(A\), \(B\), and \(C\) operators transform detail and smooth coefficients. This implementation uses three-dimensional Fourier spectral and pointwise convolutions over \((x,y,t)\). The coarsest scale is processed by the \(\bar{T}\) map and reconstructed to the original resolution with fixed filters.

For the two-dimensional Navier–Stokes experiment, four MWT blocks are stacked with BatchNorm3d and ReLU between blocks. A `36 -> 128 -> 1` output head maps reconstructed features to vorticity at each grid point and prediction time.

## Intended Uses

| Use case | Description |
| --- | --- |
| Navier–Stokes vorticity prediction | Predict the remaining vorticity trajectory from the first 10 two-dimensional frames. |
| Regular-grid operator learning | Learn mappings between input and output functions on periodic regular grids. |
| Multiscale physical-field modeling | Combine fixed multiwavelet decomposition with learnable within-scale operators. |
| Fast spatiotemporal inference | Approximate a numerical solver for batched prediction within the training distribution and viscosity regime. |

# Usage

## 1. OneCode

[Launch the OneCode AI-for-Science environment](https://web-2069360198568017922-iaaj.ksai.scnet.cn:58043/home)

## 2. Manual Setup

**Hardware requirements**

- A GPU or DCU is recommended.
- A CPU can run imports and small connectivity checks, but full training and inference will be slow.
- DCU users should install DTK 25.04.2 or later, or the OneScience-recommended version for the cluster.

### Download the model repository from Hugging Face

```bash
pip install -U huggingface_hub
hf download OneScience-Group/MWT --local-dir ./MWT
cd MWT
```

### Install the runtime environment

**DCU environment**

```bash
# Activate DTK first.
conda create -n onescience311 python=3.11 -y
conda activate onescience311
pip install onescience[cfd-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
```

**GPU environment**

```bash
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
conda activate onescience311
pip install onescience[cfd-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
```

### Download the training dataset from Hugging Face

```bash
hf download OneScience-Group/fno --repo-type dataset --local-dir ./data
```

Set `paths.data_root` in `config/config.yaml` to the downloaded directory. The experiments use:

- `ns_V1e-3_N5000_T50.mat`: \(\nu=10^{-3}\), 5,000 samples, and 50 frames.
- `ns_V1e-4_N10000_T30.mat`: \(\nu=10^{-4}\), 10,000 samples; the experiment uses the first 30 frames.
- `NavierStokes_V1e-5_N1200_T20.mat`: \(\nu=10^{-5}\), 1,200 samples, and 20 frames.

The main MAT variables are:

- `u`: the Navier–Stokes vorticity trajectory, converted to `[num_samples, 64, 64, T]` after loading.
- `t`: temporal coordinates, converted to `[T]`.
- `a`: the initial condition used by the numerical solver. The model uses the first 10 frames of `u` directly and does not load `a` as a separate input.

### Train

`config/config.yaml` defines four MWT Navier–Stokes experiments. The default is `ns_1e-3_t50`; choose another with `--experiment`.

```bash
python scripts/train.py \
  --config config/config.yaml \
  --experiment ns_1e-3_t50 \
  --seed 0
```

Supported experiments:

- `ns_1e-3_t50`: \(\nu=10^{-3}\), \(T=50\), nominally 1,000 training samples, 500 epochs.
- `ns_1e-4_t30_n1000`: \(\nu=10^{-4}\), \(T=30\), nominally 1,000 training samples, 500 epochs.
- `ns_1e-4_t30_n10000`: \(\nu=10^{-4}\), \(T=30\), nominally 10,000 training samples, 200 epochs.
- `ns_1e-5_t20`: \(\nu=10^{-5}\), \(T=20\), nominally 1,000 training samples, 500 epochs.

### Pretrained weights

`weight/best_model.pt` contains an MWT checkpoint trained on Navier–Stokes data and can be used directly for inference and numerical evaluation.

### Inference

Run one-shot inference on the fixed 200-sample test set recorded by the checkpoint and report the mean relative L2 error in physical space:

```bash
python scripts/inference.py \
  --config config/config.yaml \
  --checkpoint weight/best_model.pt
```

For explicit device, batch-size, and output options:

```bash
python scripts/inference.py \
  --config config/config.yaml \
  --checkpoint weight/best_model.pt \
  --device auto \
  --batch-size 1 \
  --output-dir results
```

Outputs:

```text
results/
├── inference_metrics.json
├── predictions.npy
├── targets.npy
└── sample_indices.npy
```

### Evaluation and visualization

```bash
python scripts/result.py --config config/config.yaml --sample 0
```

Generated files:

```text
results/
├── field_comparison.png
├── relative_l2_over_time.png
└── result_summary.json
```

- `field_comparison.png` compares ground-truth vorticity, MWT prediction, and absolute error at the beginning, middle, and end of the forecast interval.
- `relative_l2_over_time.png` plots spatial relative L2 over the full one-shot forecast interval.
- `result_summary.json` records experiment settings, sample counts, array shapes, error metrics, paper-reference values, comparability notes, and visualization paths.

# OneScience

| Platform | OneScience repository | OneSkills repository |
| --- | --- | --- |
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |

# Citation and License

- Paper: [Multiwavelet-based Operator Learning for Differential Equations](https://proceedings.neurips.cc/paper/2021/file/c9e5c2b59d98488fe1070e744041ea0e-Paper.pdf), NeurIPS 2021; [arXiv:2109.13459](https://arxiv.org/abs/2109.13459).
- Official implementation: [gaurav71531/mwt-operator](https://github.com/gaurav71531/mwt-operator).
- This repository uses the Hugging Face-compatible MIT identifier (`mit`). The paper, upstream implementation, datasets, and all other third-party materials remain subject to their original licenses and terms.