Skip to content

Commit 89aeb4d

Browse files
1want2sleepUnityLikerHydrogenSulfate
authored
【PPSCI Doc No.23、25-29、31-34、97】 (PaddlePaddle#840)
* ppsci.equation.PDE.parameters/state_dict/set_state_dict api fix * ppsci.equation.PDE.parameters/state_dict/set_state_dict api fix * fix api docs in the timedomain * fix api docs of timedomain * fix api docs of timedomain * ppsci api docs fixed * ppsci api docs fixed * ppsci api docs fixed --------- Co-authored-by: krp <2934631798@qq.com> Co-authored-by: HydrogenSulfate <490868991@qq.com>
1 parent fff722e commit 89aeb4d

File tree

8 files changed

+93
-2
lines changed

8 files changed

+93
-2
lines changed

ppsci/arch/afno.py

+10
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ class AFNONet(base.Arch):
414414
Examples:
415415
>>> import ppsci
416416
>>> model = ppsci.arch.AFNONet(("input", ), ("output", ))
417+
>>> input_data = {"input": paddle.randn([1, 20, 720, 1440])}
418+
>>> output_data = model(input_data)
419+
>>> for k, v in output_data.items():
420+
... print(k, v.shape)
421+
output [1, 20, 720, 1440]
417422
"""
418423

419424
def __init__(
@@ -577,6 +582,11 @@ class PrecipNet(base.Arch):
577582
>>> import ppsci
578583
>>> wind_model = ppsci.arch.AFNONet(("input", ), ("output", ))
579584
>>> model = ppsci.arch.PrecipNet(("input", ), ("output", ), wind_model)
585+
>>> data = paddle.randn([1, 20, 720, 1440])
586+
>>> data_dict = {"input": data}
587+
>>> output = model.forward(data_dict)
588+
>>> print(output['output'].shape)
589+
[1, 1, 720, 1440]
580590
"""
581591

582592
def __init__(

ppsci/arch/embedding_koopman.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,18 @@ class CylinderEmbedding(base.Arch):
285285
drop (float, optional): Probability of dropout the units. Defaults to 0.0.
286286
287287
Examples:
288+
>>> import paddle
288289
>>> import ppsci
289-
>>> model = ppsci.arch.CylinderEmbedding(("x", "y"), ("u", "v"))
290+
>>> model = ppsci.arch.CylinderEmbedding(("states", "visc"), ("pred_states", "recover_states"))
291+
>>> states_shape = [32, 10, 3, 64, 128]
292+
>>> visc_shape = [32, 1]
293+
>>> input_dict = {"states" : paddle.rand(states_shape),
294+
... "visc" : paddle.rand(visc_shape)}
295+
>>> out_dict = model(input_dict)
296+
>>> print(out_dict["pred_states"].shape)
297+
[32, 9, 3, 64, 128]
298+
>>> print(out_dict["recover_states"].shape)
299+
[32, 10, 3, 64, 128]
290300
"""
291301

292302
def __init__(

ppsci/arch/gan.py

+15
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,21 @@ class Discriminator(base.Arch):
286286
>>> acts = ("leaky_relu", "leaky_relu", "leaky_relu", "leaky_relu", None)
287287
>>> output_keys_disc = ("out_1", "out_2", "out_3", "out_4", "out_5", "out_6", "out_7", "out_8", "out_9", "out_10")
288288
>>> model = ppsci.arch.Discriminator(("in_1","in_2"), output_keys_disc, in_channel, out_channels, fc_channel, kernel_sizes, strides, use_bns, acts)
289+
>>> input_data = [paddle.to_tensor(paddle.randn([1, in_channel, 128, 128])),paddle.to_tensor(paddle.randn([1, in_channel, 128, 128]))]
290+
>>> input_dict = {"in_1": input_data[0],"in_2": input_data[1]}
291+
>>> out_dict = model(input_dict)
292+
>>> for k, v in out_dict.items():
293+
... print(k, v.shape)
294+
out_1 [1, 32, 64, 64]
295+
out_2 [1, 64, 32, 32]
296+
out_3 [1, 128, 16, 16]
297+
out_4 [1, 256, 16, 16]
298+
out_5 [1, 1]
299+
out_6 [1, 32, 64, 64]
300+
out_7 [1, 64, 32, 32]
301+
out_8 [1, 128, 16, 16]
302+
out_9 [1, 256, 16, 16]
303+
out_10 [1, 1]
289304
"""
290305

291306
def __init__(

ppsci/arch/model_list.py

+9
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ class ModelList(base.Arch):
2828
model_list (Tuple[base.Arch, ...]): Model(s) nested in tuple.
2929
3030
Examples:
31+
>>> import paddle
3132
>>> import ppsci
3233
>>> model1 = ppsci.arch.MLP(("x", "y"), ("u", "v"), 10, 128)
3334
>>> model2 = ppsci.arch.MLP(("x", "y"), ("w", "p"), 5, 128)
3435
>>> model = ppsci.arch.ModelList((model1, model2))
36+
>>> input_dict = {"x": paddle.rand([64, 64, 1]),"y": paddle.rand([64, 64, 1])}
37+
>>> output_dict = model(input_dict)
38+
>>> for k, v in output_dict.items():
39+
... print(k, v.shape)
40+
u [64, 64, 1]
41+
v [64, 64, 1]
42+
w [64, 64, 1]
43+
p [64, 64, 1]
3544
"""
3645

3746
def __init__(

ppsci/arch/nowcastnet.py

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class NowcastNet(base.Arch):
3636
Examples:
3737
>>> import ppsci
3838
>>> model = ppsci.arch.NowcastNet(("input", ), ("output", ))
39+
>>> input_data = paddle.rand([1, 9, 512, 512, 2])
40+
>>> input_dict = {"input": input_data}
41+
>>> output_dict = model(input_dict)
42+
>>> print(output_dict["output"].shape)
43+
[1, 20, 512, 512, 1]
3944
"""
4045

4146
def __init__(

ppsci/arch/physx_transformer.py

+6
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,14 @@ class PhysformerGPT2(base.Arch):
256256
output data to the physical space. Defaults to None.
257257
258258
Examples:
259+
>>> import paddle
259260
>>> import ppsci
260261
>>> model = ppsci.arch.PhysformerGPT2(("embeds", ), ("pred_embeds", ), 6, 16, 128, 4)
262+
>>> data = paddle.to_tensor(paddle.randn([10, 16, 128]))
263+
>>> inputs = {"embeds": data}
264+
>>> outputs = model(inputs)
265+
>>> print(outputs["pred_embeds"].shape)
266+
[10, 16, 128]
261267
"""
262268

263269
def __init__(

ppsci/autodiff/ad.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ def __call__(
283283
>>> x.stop_gradient = False
284284
>>> y = (x * x).sin()
285285
>>> dy_dxx = ppsci.autodiff.hessian(y, x, component=0)
286+
>>> print(dy_dxx.shape)
287+
[4, 1]
286288
"""
287289
key = (ys, xs, component)
288290
if key not in self.Hs:
@@ -299,6 +301,24 @@ def _clear(self):
299301

300302

301303
def clear():
302-
"""Clear cached Jacobians and Hessians."""
304+
"""Clear cached Jacobians and Hessians.
305+
306+
Args:
307+
None.
308+
309+
Returns:
310+
None.
311+
312+
Examples:
313+
>>> import paddle
314+
>>> import ppsci
315+
>>> x = paddle.randn([4, 3])
316+
>>> x.stop_gradient = False
317+
>>> y = (x * x).sin()
318+
>>> dy_dxx = ppsci.autodiff.hessian(y, x, component=0)
319+
>>> ppsci.autodiff.clear()
320+
>>> print(ppsci.autodiff.hessian.Hs)
321+
{}
322+
"""
303323
jacobian._clear()
304324
hessian._clear()

ppsci/utils/misc.py

+16
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,22 @@ def all_gather(
303303
304304
Returns:
305305
Union[paddle.Tensor, List[paddle.Tensor]]: Gathered Tensors.
306+
307+
Examples:
308+
>>> import paddle
309+
>>> import ppsci
310+
>>> import paddle.distributed as dist
311+
>>> dist.init_parallel_env() # doctest: +SKIP
312+
>>> if dist.get_rank() == 0: # doctest: +SKIP
313+
... data = paddle.to_tensor([[1, 2, 3], [4, 5, 6]])
314+
... else:
315+
... data = paddle.to_tensor([[7, 8, 9], [10, 11, 12]])
316+
>>> result = ppsci.utils.misc.all_gather(data) # doctest: +SKIP
317+
>>> print(result.numpy()) # doctest: +SKIP
318+
[[ 1 2 3]
319+
[ 4 5 6]
320+
[ 7 8 9]
321+
[10 11 12]]
306322
"""
307323
result: List[paddle.Tensor] = []
308324

0 commit comments

Comments
 (0)