yushuang88 commited on
Commit
557e27f
Β·
verified Β·
1 Parent(s): d8101c5

Update README and model configuration

Browse files
Files changed (1) hide show
  1. README.md +167 -0
README.md ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ library_name: pytorch
6
+ tags:
7
+ - OneScience
8
+ - fluid-dynamics
9
+ - neural-operator
10
+ - transformer
11
+ - point-cloud
12
+ datasets:
13
+ - OneScience-Group/ShapeNetCar
14
+ ---
15
+
16
+ <p align="center">
17
+ <strong><span style="font-size: 30px;">UPT</span></strong>
18
+ </p>
19
+
20
+ # Model Introduction
21
+
22
+ UPT (Universal Physics Transformer), proposed by Benedikt Alkin and collaborators, is a general-purpose physics Transformer. It encodes irregular meshes or particle data into a compact latent representation and propagates information in latent space for flexible, scalable physical-surrogate modeling.
23
+
24
+ This repository is an independent OneScience reproduction of the UPT ShapeNetCar experiment without an SDF. The model predicts steady surface pressure from three-dimensional vehicle-surface coordinates and does not use SDF values, normals, mesh connectivity, or flow variables as model inputs.
25
+
26
+ Paper: [Universal Physics Transformers: A Framework For Efficiently Scaling Neural Operators](https://proceedings.neurips.cc/paper_files/paper/2024/file/2cd36d327f33d47b372d4711edd08de0-Paper-Conference.pdf)
27
+
28
+ # Model Description
29
+
30
+ For ShapeNetCar, UPT takes vehicle-surface coordinates \((x,y,z)\) and predicts scalar pressure at specified surface-query coordinates.
31
+
32
+ The architecture consists of coordinate encoding, a Perceiver encoder, a latent-space Transformer, a Perceiver decoder, and pressure projection. Continuous sine/cosine positional encodings and an MLP first map scaled coordinates to input features. Perceiver cross-attention compresses a variable number of input points into learnable latent tokens, and Transformer blocks model global geometric relationships in latent space. During decoding, encoded query coordinates attend to the latent representation before normalization and linear projection produce surface-pressure predictions.
33
+
34
+ ## Intended Uses
35
+
36
+ | Use case | Description |
37
+ | --- | --- |
38
+ | Vehicle-surface pressure | Predict steady aerodynamic pressure from ShapeNetCar surface coordinates. |
39
+ | Irregular point-set modeling | Regress physical values on 3D surface point sets without a regular grid or explicit mesh connectivity. |
40
+ | Scientific surrogate | Approximate expensive numerical simulation within a fixed data distribution and flow regime. |
41
+ | Variable-point inference | Accept variable-size input sets and query pressure at surface coordinates within the training distribution. |
42
+
43
+ # Usage
44
+
45
+ ## 1. OneCode
46
+
47
+ [Launch the OneCode AI-for-Science environment](https://web-2069360198568017922-iaaj.ksai.scnet.cn:58043/home)
48
+
49
+ ## 2. Manual Setup
50
+
51
+ **Hardware requirements**
52
+
53
+ - A GPU or DCU is recommended.
54
+ - A CPU can run imports and small connectivity checks, but full training and inference will be slow.
55
+ - DCU users should install DTK 25.04.2 or later, or the OneScience-recommended version for the cluster.
56
+
57
+ ### Download the model repository from Hugging Face
58
+
59
+ ```bash
60
+ pip install -U huggingface_hub
61
+ hf download OneScience-Group/UPT --local-dir ./UPT
62
+ cd UPT
63
+ ```
64
+
65
+ ### Install the runtime environment
66
+
67
+ **DCU environment**
68
+
69
+ ```bash
70
+ # Activate DTK first.
71
+ conda create -n onescience311 python=3.11 -y
72
+ conda activate onescience311
73
+ pip install onescience[cfd-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
74
+ ```
75
+
76
+ **GPU environment**
77
+
78
+ ```bash
79
+ conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
80
+ conda activate onescience311
81
+ pip install onescience[cfd-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
82
+ ```
83
+
84
+ ### Download the training dataset from Hugging Face
85
+
86
+ ```bash
87
+ hf download OneScience-Group/ShapeNetCar \
88
+ --repo-type dataset \
89
+ --local-dir ./data
90
+ ```
91
+
92
+ Set `data.root` in `config/config.yaml` to the dataset's `preprocessed_data` directory. The dataset contains 889 vehicle geometries, split with a fixed random seed into 700 training and 189 test samples. Each preprocessed sample includes:
93
+
94
+ - `pos.npy`: all node coordinates, shape `[num_nodes, 3]`.
95
+ - `surf.npy`: surface-node mask, shape `[num_nodes]`.
96
+ - `y.npy`: target physical fields, shape `[num_nodes, 4]`; the first three channels are velocity and the fourth is pressure.
97
+ - `x.npy`: node features, shape `[num_nodes, 7]`. This implementation uses normals only to filter surface nodes; they are not model inputs.
98
+ - `edge_index.npy`: graph connectivity, which is not used as a model input.
99
+
100
+ The loader selects 3,586 valid surface points per mesh, rescales coordinates, and normalizes pressure with the configured mean and standard deviation. During training, 80%–100% of each sample's surface points are randomly selected as encoder inputs while the pressure loss is computed on all surface points. During testing, all valid surface points are used as both inputs and queries.
101
+
102
+ ### Train
103
+
104
+ `config/config.yaml` contains the no-SDF ShapeNetCar reproduction configuration.
105
+
106
+ ```bash
107
+ python scripts/train.py --config config/config.yaml
108
+ ```
109
+
110
+ Training uses masked MSE on normalized surface pressure. Per-epoch training and test metrics are written to `results/train_metrics.jsonl`. The script prints batch loss, learning rate, normalized pressure MSE, normalized pressure MSE Γ— 100, and original-scale pressure RMSE. The checkpoint with the lowest test normalized pressure MSE Γ— 100 is saved to `weight/best_model.pth`.
111
+
112
+ ### Pretrained weights
113
+
114
+ The repository includes `weight/best_model.pth`, trained on ShapeNetCar and ready for surface-pressure inference and numerical evaluation.
115
+
116
+ ### Inference and evaluation
117
+
118
+ Run inference on the fixed set of 189 test samples:
119
+
120
+ ```bash
121
+ python scripts/inference.py \
122
+ --config config/config.yaml \
123
+ --checkpoint weight/best_model.pth \
124
+ --device auto
125
+ ```
126
+
127
+ The script reports normalized pressure MSE, normalized pressure MSE Γ— 100, normalized pressure MAE, original-scale pressure MSE, and original-scale pressure RMSE. It writes:
128
+
129
+ ```text
130
+ results/inference_metrics.json
131
+ results/predictions/
132
+ └── <sample_id>.npz
133
+ ```
134
+
135
+ `inference_metrics.json` contains aggregate and per-sample metrics plus paper-reference values. Each `<sample_id>.npz` stores surface coordinates, normalized and original-scale predictions and targets, and absolute errors.
136
+
137
+ ### Visualization
138
+
139
+ ```bash
140
+ python scripts/result.py --config config/config.yaml
141
+ ```
142
+
143
+ Outputs:
144
+
145
+ ```text
146
+ results/figures/
147
+ β”œβ”€β”€ training_metrics.png
148
+ β”œβ”€β”€ <sample_id>_pressure_comparison.png
149
+ └── visualization_metadata.json
150
+ ```
151
+
152
+ - `training_metrics.png` shows normalized training MSE and test normalized MSE Γ— 100 with the paper reference.
153
+ - `<sample_id>_pressure_comparison.png` compares target surface pressure, UPT prediction, and absolute pressure error in 3D.
154
+ - `visualization_metadata.json` records prediction and evaluation sources, output paths, and plotting parameters.
155
+
156
+ # OneScience
157
+
158
+ | Platform | OneScience repository | OneSkills repository |
159
+ | --- | --- | --- |
160
+ | Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
161
+ | GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
162
+
163
+ # Citation and License
164
+
165
+ - Paper: [Universal Physics Transformers: A Framework For Efficiently Scaling Neural Operators](https://proceedings.neurips.cc/paper_files/paper/2024/file/2cd36d327f33d47b372d4711edd08de0-Paper-Conference.pdf).
166
+ - Official implementation: [ml-jku/UPT](https://github.com/ml-jku/UPT), released under the [MIT License](https://github.com/ml-jku/UPT/blob/main/LICENSE.md).
167
+ - This repository uses the Hugging Face-compatible MIT identifier (`mit`). ShapeNetCar and all other third-party resources remain subject to their original licenses and terms.