Skip to content

Commit 5e01942

Browse files
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleScience into fourcast
2 parents 567881d + 6e963c7 commit 5e01942

28 files changed

+382
-196
lines changed

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
1010
- 支持包括 Dirichlet、Neumann、Robin 以及自定义边界条件。
1111
- 支持物理机理驱动、数据驱动、数理融合三种问题求解方式。涵盖流体、结构、气象等领域 8+ 案例。
1212
- 支持结果可视化输出与日志结构化保存。
13-
- 完善的 type hints,用户使用和代码贡献全流程文档,所有经典案例 AI studio 一键运行,降低使用门槛,提高开发效率。
13+
- 完善的 type hints,用户使用和代码贡献全流程文档,经典案例 AI studio 快速体验,降低使用门槛,提高开发效率。
1414
- 更多特性正在开发中...
1515

1616
## 支持

docs/zh/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ ppsci INFO: [Visualize][Epoch 0] Finished visualization.
163163

164164
可以看到场景一的监督训练方式能较好地解决函数拟合问题,但一般情况下我们是无法得知拟合函数本身的解析式的,因此也无法直接构造因变量的监督数据。
165165

166-
虽然无法求出解析式直接构造监督数据,但往往可以利用相关数学知识,推导出目标拟合函数符合的某种数学关系,以训练模型以满足这种数学关系的方式,达到“间接”优化模型的目的
166+
虽然无法求出解析式直接构造监督数据,但往往可以利用相关数学知识,推导出目标拟合函数符合的某种数学关系,以训练模型以满足这种数学关系的方式,达到以“间接监督”的方式优化模型的目的
167167

168168
假设我们不再使用 $u=sin(x)$ 这一先验公式,因而无法生成标签数据 $u$。因此我们使用 $\dfrac{\partial u} {\partial x}=cos(x)$ 这一方程,构造数据对 $(x_i, cos(x_i)), i=1,...,N$。
169-
这意味着我们仍然能保持模型的输入、输出不变,但优化目标变成了:让 $\dfrac{\partial \hat{u}} {\partial x}$ 尽可能地接近 $cos(x)$。
169+
这意味着我们仍然能保持模型的输入、输出不变,但优化目标变成了:让 $\dfrac{\partial \hat{u}} {\partial x}$ 尽可能地接近 $cos(x)$。
170170

171171
基于以上理论,我们对场景一的代码进行少量的改写即可得到本场景二的代码。
172172

ppsci/arch/embedding_koopman.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ def build_koopman_operator(self, embed_size: int):
117117
data = paddle.linspace(1, 0, embed_size)
118118
k_diag = paddle.create_parameter(
119119
shape=data.shape,
120-
dtype=data.dtype,
120+
dtype=paddle.get_default_dtype(),
121121
default_initializer=nn.initializer.Assign(data),
122122
)
123123

124124
data = 0.1 * paddle.rand([2 * embed_size - 3])
125125
k_ut = paddle.create_parameter(
126126
shape=data.shape,
127-
dtype=data.dtype,
127+
dtype=paddle.get_default_dtype(),
128128
default_initializer=nn.initializer.Assign(data),
129129
)
130130
return k_diag, k_ut

ppsci/arch/physx_transformer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ def _init_weights(self, module):
308308

309309
def get_position_embed(self, x):
310310
B, N, _ = x.shape
311-
position_ids = paddle.arange(0, N, dtype="float32").reshape([1, N, 1])
311+
position_ids = paddle.arange(0, N, dtype=paddle.get_default_dtype()).reshape(
312+
[1, N, 1]
313+
)
312314
position_ids = position_ids.repeat_interleave(B, axis=0)
313315

314316
position_embeds = paddle.zeros_like(x)

ppsci/constraint/boundary_constraint.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(
111111
label = {}
112112
for key, value in label_dict.items():
113113
if isinstance(value, (int, float)):
114-
label[key] = np.full_like(next(iter(input.values())), float(value))
114+
label[key] = np.full_like(next(iter(input.values())), value)
115115
elif isinstance(value, sympy.Basic):
116116
func = sympy.lambdify(
117117
sympy.symbols(geom.dim_keys),
@@ -125,9 +125,7 @@ def __init__(
125125
func = value
126126
label[key] = func(input)
127127
if isinstance(label[key], (int, float)):
128-
label[key] = np.full_like(
129-
next(iter(input.values())), float(label[key])
130-
)
128+
label[key] = np.full_like(next(iter(input.values())), label[key])
131129
else:
132130
raise NotImplementedError(f"type of {type(value)} is invalid yet.")
133131

@@ -139,7 +137,7 @@ def __init__(
139137
value = sp_parser.parse_expr(value)
140138

141139
if isinstance(value, (int, float)):
142-
weight[key] = np.full_like(next(iter(label.values())), float(value))
140+
weight[key] = np.full_like(next(iter(label.values())), value)
143141
elif isinstance(value, sympy.Basic):
144142
func = sympy.lambdify(
145143
[sympy.Symbol(k) for k in geom.dim_keys],
@@ -152,7 +150,7 @@ def __init__(
152150
weight[key] = func(input)
153151
if isinstance(weight[key], (int, float)):
154152
weight[key] = np.full_like(
155-
next(iter(input.values())), float(weight[key])
153+
next(iter(input.values())), weight[key]
156154
)
157155
else:
158156
raise NotImplementedError(f"type of {type(value)} is invalid yet.")

ppsci/constraint/initial_constraint.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __init__(
110110
if isinstance(value, str):
111111
value = sp_parser.parse_expr(value)
112112
if isinstance(value, (int, float)):
113-
label[key] = np.full_like(next(iter(input.values())), float(value))
113+
label[key] = np.full_like(next(iter(input.values())), value)
114114
elif isinstance(value, sympy.Basic):
115115
func = sympy.lambdify(
116116
sympy.symbols(geom.dim_keys),
@@ -124,9 +124,7 @@ def __init__(
124124
func = value
125125
label[key] = func(input)
126126
if isinstance(label[key], (int, float)):
127-
label[key] = np.full_like(
128-
next(iter(input.values())), float(label[key])
129-
)
127+
label[key] = np.full_like(next(iter(input.values())), label[key])
130128
else:
131129
raise NotImplementedError(f"type of {type(value)} is invalid yet.")
132130

@@ -137,7 +135,7 @@ def __init__(
137135
if isinstance(value, str):
138136
value = sp_parser.parse_expr(value)
139137
if isinstance(value, (int, float)):
140-
weight[key] = np.full_like(next(iter(label.values())), float(value))
138+
weight[key] = np.full_like(next(iter(label.values())), value)
141139
elif isinstance(value, sympy.Basic):
142140
func = sympy.lambdify(
143141
sympy.symbols(geom.dim_keys),
@@ -152,7 +150,7 @@ def __init__(
152150
weight[key] = func(input)
153151
if isinstance(weight[key], (int, float)):
154152
weight[key] = np.full_like(
155-
next(iter(input.values())), float(weight[key])
153+
next(iter(input.values())), weight[key]
156154
)
157155
else:
158156
raise NotImplementedError(f"type of {type(value)} is invalid yet.")

ppsci/constraint/integral_constraint.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Union
2121

2222
import numpy as np
23+
import paddle
2324
import sympy
2425
from sympy.parsing import sympy_parser as sp_parser
2526
from typing_extensions import Literal
@@ -114,7 +115,9 @@ def __init__(
114115
for key, value in label_dict.items():
115116
if isinstance(value, (int, float)):
116117
label[key] = np.full(
117-
(next(iter(input.values())).shape[0], 1), float(value), "float32"
118+
(next(iter(input.values())).shape[0], 1),
119+
value,
120+
paddle.get_default_dtype(),
118121
)
119122
elif isinstance(value, sympy.Basic):
120123
func = sympy.lambdify(
@@ -130,7 +133,9 @@ def __init__(
130133
label[key] = func(input)
131134
if isinstance(label[key], (int, float)):
132135
label[key] = np.full(
133-
(next(iter(input.values())).shape[0], 1), float(label[key])
136+
(next(iter(input.values())).shape[0], 1),
137+
label[key],
138+
paddle.get_default_dtype(),
134139
)
135140
else:
136141
raise NotImplementedError(f"type of {type(value)} is invalid yet.")
@@ -144,7 +149,7 @@ def __init__(
144149
value = sp_parser.parse_expr(value)
145150

146151
if isinstance(value, (int, float)):
147-
weight[key] = np.full_like(next(iter(label.values())), float(value))
152+
weight[key] = np.full_like(next(iter(label.values())), value)
148153
elif isinstance(value, sympy.Basic):
149154
func = sympy.lambdify(
150155
sympy.symbols(geom.dim_keys),
@@ -159,7 +164,7 @@ def __init__(
159164
weight[key] = func(input)
160165
if isinstance(weight[key], (int, float)):
161166
weight[key] = np.full_like(
162-
next(iter(input.values())), float(weight[key])
167+
next(iter(input.values())), weight[key]
163168
)
164169
else:
165170
raise NotImplementedError(f"type of {type(value)} is invalid yet.")

ppsci/constraint/interior_constraint.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(
113113
if isinstance(value, str):
114114
value = sp_parser.parse_expr(value)
115115
if isinstance(value, (int, float)):
116-
label[key] = np.full_like(next(iter(input.values())), float(value))
116+
label[key] = np.full_like(next(iter(input.values())), value)
117117
elif isinstance(value, sympy.Basic):
118118
func = sympy.lambdify(
119119
sympy.symbols(geom.dim_keys),
@@ -127,9 +127,7 @@ def __init__(
127127
func = value
128128
label[key] = func(input)
129129
if isinstance(label[key], (int, float)):
130-
label[key] = np.full_like(
131-
next(iter(input.values())), float(label[key])
132-
)
130+
label[key] = np.full_like(next(iter(input.values())), label[key])
133131
else:
134132
raise NotImplementedError(f"type of {type(value)} is invalid yet.")
135133

@@ -141,7 +139,7 @@ def __init__(
141139
value = sp_parser.parse_expr(value)
142140

143141
if isinstance(value, (int, float)):
144-
weight[key] = np.full_like(next(iter(label.values())), float(value))
142+
weight[key] = np.full_like(next(iter(label.values())), value)
145143
elif isinstance(value, sympy.Basic):
146144
func = sympy.lambdify(
147145
sympy.symbols(geom.dim_keys),
@@ -156,7 +154,7 @@ def __init__(
156154
weight[key] = func(input)
157155
if isinstance(weight[key], (int, float)):
158156
weight[key] = np.full_like(
159-
next(iter(input.values())), float(weight[key])
157+
next(iter(input.values())), weight[key]
160158
)
161159
else:
162160
raise NotImplementedError(f"type of {type(value)} is invalid yet.")

ppsci/constraint/periodic_constraint.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Union
2121

2222
import numpy as np
23+
import paddle
2324
import sympy
2425
from sympy.parsing import sympy_parser as sp_parser
2526
from typing_extensions import Literal
@@ -123,7 +124,9 @@ def __init__(
123124
for key, value in label_dict.items():
124125
# set all label's to zero for dummy data.
125126
label[key] = np.full(
126-
(next(iter(mixed_input.values())).shape[0], 1), 0, "float32"
127+
(next(iter(mixed_input.values())).shape[0], 1),
128+
0,
129+
paddle.get_default_dtype(),
127130
)
128131

129132
# # prepare weight, keep weight the same shape as input_periodic
@@ -134,7 +137,7 @@ def __init__(
134137
value = sp_parser.parse_expr(value)
135138

136139
if isinstance(value, (int, float)):
137-
weight[key] = np.full_like(next(iter(label.values())), float(value))
140+
weight[key] = np.full_like(next(iter(label.values())), value)
138141
elif isinstance(value, sympy.Basic):
139142
func = sympy.lambdify(
140143
[sympy.Symbol(k) for k in geom.dim_keys],
@@ -147,7 +150,7 @@ def __init__(
147150
weight[key] = func(mixed_input)
148151
if isinstance(weight[key], (int, float)):
149152
weight[key] = np.full_like(
150-
next(iter(mixed_input.values())), float(weight[key])
153+
next(iter(mixed_input.values())), weight[key]
151154
)
152155
else:
153156
raise NotImplementedError(f"type of {type(value)} is invalid yet.")

ppsci/data/dataset/csv_dataset.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ class CSVDataset(io.Dataset):
3636
input_keys (Tuple[str, ...]): List of input keys.
3737
label_keys (Tuple[str, ...]): List of label keys.
3838
alias_dict (Optional[Dict[str, str]]): Dict of alias(es) for input and label keys.
39+
i.e. {inner_key: outer_key}. Defaults to None.
3940
weight_dict (Optional[Dict[str, Union[Callable, float]]]): Define the weight of
4041
each constraint variable. Defaults to None.
4142
timestamps (Optional[Tuple[float, ...]]): The number of repetitions of the data
4243
in the time dimension. Defaults to None.
4344
transforms (Optional[vision.Compose]): Compose object contains sample wise
44-
transform(s).
45+
transform(s). Defaults to None.
4546
4647
Examples:
4748
>>> import ppsci
@@ -116,14 +117,14 @@ def __init__(
116117
for key, value in weight_dict.items():
117118
if isinstance(value, (int, float)):
118119
self.weight[key] = np.full_like(
119-
next(iter(self.label.values())), float(value)
120+
next(iter(self.label.values())), value
120121
)
121122
elif callable(value):
122123
func = value
123124
self.weight[key] = func(self.input)
124125
if isinstance(self.weight[key], (int, float)):
125126
self.weight[key] = np.full_like(
126-
next(iter(self.label.values())), float(self.weight[key])
127+
next(iter(self.label.values())), self.weight[key]
127128
)
128129
else:
129130
raise NotImplementedError(f"type of {type(value)} is invalid yet.")
@@ -154,12 +155,13 @@ class IterableCSVDataset(io.IterableDataset):
154155
input_keys (Tuple[str, ...]): List of input keys.
155156
label_keys (Tuple[str, ...]): List of label keys.
156157
alias_dict (Optional[Dict[str, str]]): Dict of alias(es) for input and label keys.
158+
Defaults to None.
157159
weight_dict (Optional[Dict[str, Union[Callable, float]]]): Define the weight of
158160
each constraint variable. Defaults to None.
159161
timestamps (Optional[Tuple[float, ...]]): The number of repetitions of the data
160162
in the time dimension. Defaults to None.
161163
transforms (Optional[vision.Compose]): Compose object contains sample wise
162-
transform(s).
164+
transform(s). Defaults to None.
163165
164166
Examples:
165167
>>> import ppsci
@@ -234,14 +236,14 @@ def __init__(
234236
for key, value in weight_dict.items():
235237
if isinstance(value, (int, float)):
236238
self.weight[key] = np.full_like(
237-
next(iter(self.label.values())), float(value)
239+
next(iter(self.label.values())), value
238240
)
239241
elif callable(value):
240242
func = value
241243
self.weight[key] = func(self.input)
242244
if isinstance(self.weight[key], (int, float)):
243245
self.weight[key] = np.full_like(
244-
next(iter(self.label.values())), float(self.weight[key])
246+
next(iter(self.label.values())), self.weight[key]
245247
)
246248
else:
247249
raise NotImplementedError(f"type of {type(value)} is invalid yet.")

0 commit comments

Comments
 (0)