CVit (Advection)¶
Note
Before running the model, please download the two files adv_a0.npy and adv_aT.npy from Zhengyu-Huang/Operator-Learning and place them in the ./examples/adv/data/ folder.
| Pretrained Model | Metrics |
|---|---|
| adv_cvit_pretrained.pdparams | L2 error(mean): 0.028 L2 error(median): 0.022 L2 error(max): 0.166 L2 error(min): 0.0015 |
1. Background Introduction¶
Current models used in the sciml field are quite different from advanced models in the CV and NLP fields, and do not make good use of the advantages provided by these advanced models. Therefore, the authors first proposed a unified perspective of operator learning, summarizing DeepONet, FNO, GNO and other models according to Global conditioning and Local Conditioning respectively, and then designed a Global conditioning model CVit based on the Transformer structure widely used in CV and NLP fields. Compared with previous operator learning models, it has fewer parameters and higher accuracy.
The model structure is shown in the figure below:
2. Problem Definition¶
As an operator learning model, CVit takes the input function \(u\) and the query coordinate \(y\) of function \(s\) as input, and outputs the function value \(s(y)\) at the query point \(y\) of the function after operator mapping.
This problem solves the following equation:
Formulation The 1D advection equation in \(\Omega=[0,1)\) is
where \(c=1\) is the constant advection speed, and periodic boundary conditions are imposed. We are interested in the map from the initial \(u_0\) to solution \(u(\cdot, T)\) at \(T=0.5\). The initial condition \(u_0\) is assumed to be
where \(\widetilde{u_0}\) a centered Gaussian
3. Problem Solving¶
Next, we will explain how to convert the problem into PaddleScience code step by step and solve the problem using deep learning methods. In order to quickly understand PaddleScience, only key steps such as model construction, equation construction, and computational domain construction are described below, while other details please refer to API Documentation.
3.1 Model Construction¶
In this problem, for each function \(u\), after being mapped to \(s\) by the operator learning model, there is a corresponding label \(s(y)\) on \(y\), so here CVit is used to represent the mapping relationship from \((u, y)\) to \(s(y)\):
In the above formula, \(G(u)\) is the CVit model itself, expressed in PaddleScience code as follows
In order to access the value of specific variables accurately and quickly during calculation, the input variable name of the network model is specified as ("u", "y") and the output variable name is ("s"), these names are consistent with the subsequent code.
Then by specifying the hyperparameters such as input dimension, coordinate dimension, output dimension, and number of model layers of CVit, a model can be instantiated.
3.2 Data Preparation¶
The data in this problem is stored in adv_a0.py and adv_aT.py files. After randomly shuffling the data, the first 20000 data are taken as training data, and the last 10000 are test data.
3.3 Constraint Construction¶
3.3.1 Supervised Constraint¶
During training, batch_size groups of data from \(u\) are randomly selected, and query_point \(y\) coordinates are randomly selected at the same time, thus constituting training input data. Label data is randomly selected from \(s\) with the same batch_size x query_point label points.
The first parameter of SupervisedConstraint is the data configuration used for training. We use ContinuousNamedArrayDataset as the dataset type, and pass in custom gen_input_batch_train and gen_label_batch_train to complete the random selection process of the above training input and label samples;
The second parameter is the calculation expression of the constraint. We only need to calculate \(s\), so we fill in an anonymous expression that directly takes out the model output result "s" without any processing;
The third parameter is the loss function, here MSELoss function is selected;
The fourth parameter is the name of the constraint condition. Each constraint condition needs to be named to facilitate subsequent indexing. Here it is named "Sup".
3.4 Hyperparameter Setting¶
Next, you need to specify the number of training epochs and learning rate. Here, based on experimental experience, 200,000 training epochs are used. The initial learning rate is 0.0001, the global gradient clipping coefficient is 1.0, the weight decay is 1e-5, and model averaging EMA is performed every 1 training epoch.
3.5 Optimizer Construction¶
The training process will call the optimizer to update model parameters. Here, the AdamW optimizer is selected, and the ExponentialDecay learning rate adjustment strategy commonly used in machine learning is used together.
3.6 Model Training and Evaluation¶
After completing the above settings, you only need to pass the instantiated objects to ppsci.solver.Solver in order, and then start training and evaluation.
4. Complete Code¶
| adv_cvit.py | |
|---|---|
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
5. Result Display¶
The prediction results, reference results and absolute value errors on the test set are shown in the figure below.

