diff --git a/ppsci/arch/amgnet.py b/ppsci/arch/amgnet.py index 28ac01b02..80634af78 100644 --- a/ppsci/arch/amgnet.py +++ b/ppsci/arch/amgnet.py @@ -579,7 +579,9 @@ class AMGNet(nn.Layer): Examples: >>> import ppsci - >>> model = ppsci.arch.AMGNet(("input", ), ("pred", ), 5, 3, 64, 2) + >>> model = ppsci.arch.AMGNet( + ... ("input", ), ("pred", ), 5, 3, 64, 2, "sum", 6, "norm", + ... ) """ def __init__( diff --git a/ppsci/arch/chip_deeponets.py b/ppsci/arch/chip_deeponets.py index 5c5127140..30c87c565 100644 --- a/ppsci/arch/chip_deeponets.py +++ b/ppsci/arch/chip_deeponets.py @@ -60,7 +60,7 @@ class ChipDeepONets(base.Arch): Examples: >>> import ppsci - >>> model = ppsci.arch.ChipDeepONet( + >>> model = ppsci.arch.ChipDeepONets( ... ('u',), ... ('bc',), ... ('bc_data',), diff --git a/ppsci/arch/epnn.py b/ppsci/arch/epnn.py index 67f901dc2..0f6a9ffed 100644 --- a/ppsci/arch/epnn.py +++ b/ppsci/arch/epnn.py @@ -65,12 +65,12 @@ class Epnn(base.Arch): Examples: >>> import ppsci - >>> ann_node_sizes_state = [1] + >>> ann_node_sizes_state = [1, 20] >>> model = ppsci.arch.Epnn( ... ("x",), ... ("y",), ... node_sizes=ann_node_sizes_state, - ... activations=("leaky_relu"), + ... activations=("leaky_relu",), ... drop_p=0.0, ... ) """ @@ -84,7 +84,9 @@ def __init__( drop_p: float, ): super().__init__() - self.active_func = [act_mod.get_activation(i) for i in activations] + self.active_func = [ + act_mod.get_activation(act_name) for act_name in activations + ] self.node_sizes = node_sizes self.drop_p = drop_p self.layers = [] diff --git a/ppsci/arch/he_deeponets.py b/ppsci/arch/he_deeponets.py index 78046ab42..811da0d1b 100644 --- a/ppsci/arch/he_deeponets.py +++ b/ppsci/arch/he_deeponets.py @@ -52,7 +52,7 @@ class HEDeepONets(base.Arch): Examples: >>> import ppsci - >>> model = ppsci.arch.HEDeepONet( + >>> model = ppsci.arch.HEDeepONets( ... ('qm_h',), ... ('qm_c',), ... ("x",'t'), diff --git a/ppsci/constraint/boundary_constraint.py b/ppsci/constraint/boundary_constraint.py index 6443acaf6..d0866c54f 100644 --- a/ppsci/constraint/boundary_constraint.py +++ b/ppsci/constraint/boundary_constraint.py @@ -69,7 +69,7 @@ class BoundaryConstraint(base.Constraint): ... }, ... ppsci.loss.MSELoss("mean"), ... name="BC", - ... ) + ... ) # doctest: +SKIP """ def __init__( diff --git a/ppsci/constraint/initial_constraint.py b/ppsci/constraint/initial_constraint.py index dea3eb8fe..b8811aedd 100644 --- a/ppsci/constraint/initial_constraint.py +++ b/ppsci/constraint/initial_constraint.py @@ -74,7 +74,7 @@ class InitialConstraint(base.Constraint): ... }, ... ppsci.loss.MSELoss("mean"), ... name="IC", - ... ) + ... ) # doctest: +SKIP """ def __init__( diff --git a/ppsci/constraint/integral_constraint.py b/ppsci/constraint/integral_constraint.py index 67779d490..1334cb4fc 100644 --- a/ppsci/constraint/integral_constraint.py +++ b/ppsci/constraint/integral_constraint.py @@ -71,7 +71,7 @@ class IntegralConstraint(base.Constraint): ... }, ... ppsci.loss.MSELoss("mean"), ... name="IgC", - ... ) + ... ) # doctest: +SKIP """ def __init__( diff --git a/ppsci/constraint/interior_constraint.py b/ppsci/constraint/interior_constraint.py index 6593df213..3cbc558a1 100644 --- a/ppsci/constraint/interior_constraint.py +++ b/ppsci/constraint/interior_constraint.py @@ -71,7 +71,7 @@ class InteriorConstraint(base.Constraint): ... }, ... ppsci.loss.MSELoss("mean"), ... name="EQ", - ... ) + ... ) # doctest: +SKIP """ def __init__( diff --git a/ppsci/data/dataset/era5_dataset.py b/ppsci/data/dataset/era5_dataset.py index e9fa86d24..1fad03c24 100644 --- a/ppsci/data/dataset/era5_dataset.py +++ b/ppsci/data/dataset/era5_dataset.py @@ -175,10 +175,10 @@ class ERA5SampledDataset(io.Dataset): ... "label_keys": ("output",), ... ) # doctest: +SKIP >>> # get the length of the dataset - >>> dataset_size = len(dataset) + >>> dataset_size = len(dataset) # doctest: +SKIP >>> # get the first sample of the data - >>> first_sample = dataset[0] - >>> print("First sample:", first_sample) + >>> first_sample = dataset[0] # doctest: +SKIP + >>> print("First sample:", first_sample) # doctest: +SKIP """ def __init__( diff --git a/ppsci/data/dataset/mrms_dataset.py b/ppsci/data/dataset/mrms_dataset.py index 0f63c120b..4b89dfc5a 100644 --- a/ppsci/data/dataset/mrms_dataset.py +++ b/ppsci/data/dataset/mrms_dataset.py @@ -187,10 +187,10 @@ class MRMSSampledDataset(io.Dataset): ... "num_total_timestamps": 29, ... ) # doctest: +SKIP >>> # get the length of the dataset - >>> dataset_size = len(dataset) + >>> dataset_size = len(dataset) # doctest: +SKIP >>> # get the first sample of the data - >>> first_sample = dataset[0] - >>> print("First sample:", first_sample) + >>> first_sample = dataset[0] # doctest: +SKIP + >>> print("First sample:", first_sample) # doctest: +SKIP """ def __init__( diff --git a/ppsci/data/dataset/vtu_dataset.py b/ppsci/data/dataset/vtu_dataset.py index f3198c883..fb0c9201b 100644 --- a/ppsci/data/dataset/vtu_dataset.py +++ b/ppsci/data/dataset/vtu_dataset.py @@ -39,7 +39,7 @@ class VtuDataset(io.Dataset): transform(s). Examples: - >>> from ppsci.dataset import VtuDataset + >>> from ppsci.data.dataset import VtuDataset >>> dataset = VtuDataset(file_path='example.vtu') # doctest: +SKIP @@ -47,7 +47,7 @@ class VtuDataset(io.Dataset): >>> dataset_size = len(dataset) # doctest: +SKIP >>> # get the first sample of the data >>> first_sample = dataset[0] # doctest: +SKIP - >>> print("First sample:", first_sample) + >>> print("First sample:", first_sample) # doctest: +SKIP """ # Whether support batch indexing for speeding up fetching process. diff --git a/ppsci/data/process/transform/preprocess.py b/ppsci/data/process/transform/preprocess.py index 767284d11..48f0fa122 100644 --- a/ppsci/data/process/transform/preprocess.py +++ b/ppsci/data/process/transform/preprocess.py @@ -32,18 +32,20 @@ class Translate: Examples: >>> import ppsci >>> import numpy as np - >>> translate = ppsci.data.transform.Translate({"x": 1.0, "y": -1.0}) - >>> input_data = np.array([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]) - >>> input_dict = {"x": input_data[:,:,0], "y": input_data[:,:,1]} + + >>> input_dict = {"x": np.array([5.0, 10.0]), "y": np.array([20.0, 40.0])} >>> label_dict = {"x": np.array([1.0, 2.0]), "y": np.array([3.0, 4.0])} >>> weight_dict = {"x": np.array([10.0, 20.0]), "y": np.array([30.0, 40.0])} + + >>> translate = ppsci.data.transform.Translate({"x": 1.0, "y": -1.0}) >>> translated_input_dict, translated_label_dict, translated_weight_dict = translate(input_dict, label_dict, weight_dict) + >>> print(translated_input_dict) - {"x": array([[2., 3.], [4., 5.]]), "y": array([[0., 1.], [2., 3.]])} + {'x': array([ 6., 11.]), 'y': array([19., 39.])} >>> print(translated_label_dict) - {"x": array([2., 3.]), "y": array([3., 4.])} + {'x': array([1., 2.]), 'y': array([3., 4.])} >>> print(translated_weight_dict) - {"x": array([10., 20.]), "y": array([30., 40.])} + {'x': array([10., 20.]), 'y': array([30., 40.])} """ def __init__(self, offset: Dict[str, float]): @@ -293,23 +295,24 @@ class FunctionalTransform: >>> # The function will perform some transformations on the data in data_dict, convert all labels in label_dict to uppercase, >>> # and modify the weights in weight_dict by dividing each weight by 10. >>> # Finally, it returns the transformed data, labels, and weights as a tuple. + >>> import ppsci >>> def transform_func(data_dict, label_dict, weight_dict): ... for key in data_dict: ... data_dict[key] = data_dict[key] * 2 ... for key in label_dict: - ... label_dict[key] = label_dict[key].upper() + ... label_dict[key] = label_dict[key] + 1.0 ... for key in weight_dict: ... weight_dict[key] = weight_dict[key] / 10 ... return data_dict, label_dict, weight_dict >>> transform = ppsci.data.transform.FunctionalTransform(transform_func) >>> # Define some sample data, labels, and weights >>> data = {'feature1': np.array([1, 2, 3]), 'feature2': np.array([4, 5, 6])} - >>> label = {'class': 'class1', 'instance': 'instance1'} + >>> label = {'class': 0.0, 'instance': 0.1} >>> weight = {'weight1': 0.5, 'weight2': 0.5} >>> # Apply the transform function to the data, labels, and weights using the FunctionalTransform instance >>> transformed_data = transform(data, label, weight) >>> print(transformed_data) - ({'feature1': [2, 4, 6], 'feature2': [8, 10, 12]}, {'class': 'CLASS1', 'instance': 'INSTANCE1'}, {'weight1': 0.5, 'weight2': 0.5}) + ({'feature1': array([2, 4, 6]), 'feature2': array([ 8, 10, 12])}, {'class': 1.0, 'instance': 1.1}, {'weight1': 0.05, 'weight2': 0.05}) """ def __init__( diff --git a/ppsci/equation/fpde/fractional_poisson.py b/ppsci/equation/fpde/fractional_poisson.py index 0f69d7414..159177965 100644 --- a/ppsci/equation/fpde/fractional_poisson.py +++ b/ppsci/equation/fpde/fractional_poisson.py @@ -38,7 +38,9 @@ class FractionalPoisson(PDE): Examples: >>> import ppsci - >>> fpde = ppsci.equation.FractionalPoisson(ALPHA, geom["disk"], [8, 100]) + >>> geom_disk = ppsci.geometry.Disk([0, 0], 1) + >>> ALPHA = 0.5 + >>> fpde = ppsci.equation.FractionalPoisson(ALPHA, geom_disk, [8, 100]) """ dtype = paddle.get_default_dtype() diff --git a/ppsci/experimental/math_module.py b/ppsci/experimental/math_module.py index b7dc71610..a446ba63c 100644 --- a/ppsci/experimental/math_module.py +++ b/ppsci/experimental/math_module.py @@ -427,34 +427,34 @@ def trapezoid_integrate( >>> res = ppsci.experimental.trapezoid_integrate(y) >>> print(res) Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [2., 8.]) + [2., 8.]) >>> res = ppsci.experimental.trapezoid_integrate(y, mode="cumsum") >>> print(res) Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [[0.50000000, 2. ], - [3.50000000, 8. ]]) + [[0.50000000, 2. ], + [3.50000000, 8. ]]) >>> res = ppsci.experimental.trapezoid_integrate( - y, x=paddle.to_tensor([[0, 1, 2], [3, 4, 5]], dtype="float32") - ) + ... y, x=paddle.to_tensor([[0, 1, 2], [3, 4, 5]], dtype="float32") + ... ) >>> print(res) Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [2., 8.]) + [2., 8.]) >>> res = ppsci.experimental.trapezoid_integrate( - y, x=paddle.to_tensor([0, 1], dtype="float32"), axis=0 - ) + ... y, x=paddle.to_tensor([0, 1], dtype="float32"), axis=0 + ... ) >>> print(res) Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [1.50000000, 2.50000000, 3.50000000]) + [1.50000000, 2.50000000, 3.50000000]) >>> res = ppsci.experimental.trapezoid_integrate( - y, x=paddle.to_tensor([0, 1, 2], dtype="float32"), axis=1 - ) + ... y, x=paddle.to_tensor([0, 1, 2], dtype="float32"), axis=1 + ... ) >>> print(res) Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [2., 8.]) + [2., 8.]) >>> res = ppsci.experimental.trapezoid_integrate(y, dx=2) >>> print(res) Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [4. , 16.]) + [4. , 16.]) """ if mode == "sum": return paddle.trapezoid(y, x, dx, axis) diff --git a/ppsci/geometry/mesh.py b/ppsci/geometry/mesh.py index 7563496cc..74a488000 100644 --- a/ppsci/geometry/mesh.py +++ b/ppsci/geometry/mesh.py @@ -75,11 +75,11 @@ def from_pymesh(cls, mesh: "pymesh.Mesh") -> "Mesh": Examples: >>> import ppsci - >>> import pymesh - >>> import numpy as np - >>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) - >>> mesh = ppsci.geometry.Mesh.from_pymesh(box) - >>> print(mesh.vertices) + >>> import pymesh # doctest: +SKIP + >>> import numpy as np # doctest: +SKIP + >>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) # doctest: +SKIP + >>> mesh = ppsci.geometry.Mesh.from_pymesh(box) # doctest: +SKIP + >>> print(mesh.vertices) # doctest: +SKIP [[0. 0. 0.] [1. 0. 0.] [1. 1. 0.] @@ -201,11 +201,11 @@ def translate(self, translation: np.ndarray, relative: bool = True) -> "Mesh": Examples: >>> import ppsci - >>> import pymesh + >>> import pymesh # doctest: +SKIP >>> import numpy as np - >>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) - >>> mesh = ppsci.geometry.Mesh(box) - >>> print(mesh.vertices) + >>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) # doctest: +SKIP + >>> mesh = ppsci.geometry.Mesh(box) # doctest: +SKIP + >>> print(mesh.vertices) # doctest: +SKIP [[0. 0. 0.] [1. 0. 0.] [1. 1. 0.] @@ -214,7 +214,7 @@ def translate(self, translation: np.ndarray, relative: bool = True) -> "Mesh": [1. 0. 1.] [1. 1. 1.] [0. 1. 1.]] - >>> print(mesh.translate((-0.5, 0, 0.5), False).vertices) # the center is moved to the translation vector. + >>> print(mesh.translate((-0.5, 0, 0.5), False).vertices) # the center is moved to the translation vector. # doctest: +SKIP [[-1. -0.5 0. ] [ 0. -0.5 0. ] [ 0. 0.5 0. ] @@ -223,7 +223,7 @@ def translate(self, translation: np.ndarray, relative: bool = True) -> "Mesh": [ 0. -0.5 1. ] [ 0. 0.5 1. ] [-1. 0.5 1. ]] - >>> print(mesh.translate((-0.5, 0, 0.5), True).vertices) # the translation vector is directly added to the geometry coordinates + >>> print(mesh.translate((-0.5, 0, 0.5), True).vertices) # the translation vector is directly added to the geometry coordinates # doctest: +SKIP [[-0.5 0. 0.5] [ 0.5 0. 0.5] [ 0.5 1. 0.5] @@ -274,11 +274,11 @@ def scale( Examples: >>> import ppsci - >>> import pymesh + >>> import pymesh # doctest: +SKIP >>> import numpy as np - >>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) - >>> mesh = ppsci.geometry.Mesh(box) - >>> print(mesh.vertices) + >>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) # doctest: +SKIP + >>> mesh = ppsci.geometry.Mesh(box) # doctest: +SKIP + >>> print(mesh.vertices) # doctest: +SKIP [[0. 0. 0.] [1. 0. 0.] [1. 1. 0.] @@ -287,8 +287,8 @@ def scale( [1. 0. 1.] [1. 1. 1.] [0. 1. 1.]] - >>> mesh = mesh.scale(2, (0.25, 0.5, 0.75)) - >>> print(mesh.vertices) + >>> mesh = mesh.scale(2, (0.25, 0.5, 0.75)) # doctest: +SKIP + >>> print(mesh.vertices) # doctest: +SKIP [[-0.25 -0.5 -0.75] [ 1.75 -0.5 -0.75] [ 1.75 1.5 -0.75] diff --git a/ppsci/solver/solver.py b/ppsci/solver/solver.py index aec7717a9..ed48ed061 100644 --- a/ppsci/solver/solver.py +++ b/ppsci/solver/solver.py @@ -103,7 +103,7 @@ class Solver: ... }, ... ppsci.loss.MSELoss("mean"), ... name="EQ", - ... ) + ... ) # doctest: +SKIP >>> solver = ppsci.solver.Solver( ... model, ... {"EQ": pde_constraint}, @@ -598,8 +598,8 @@ def predict( >>> input_dict = {'x': paddle.rand([32, 1]), ... 'y': paddle.rand([32, 1])} >>> pred = solver.predict(input_dict) # doctest: +SKIP - >>> for k, v in pred.items(): - ... print(k, v.shape) + >>> for k, v in pred.items(): # doctest: +SKIP + ... print(k, v.shape) # doctest: +SKIP u [32, 1] v [32, 1] """ diff --git a/ppsci/utils/misc.py b/ppsci/utils/misc.py index e36ef7134..b4ae27a87 100644 --- a/ppsci/utils/misc.py +++ b/ppsci/utils/misc.py @@ -212,9 +212,12 @@ class Timer(ContextDecorator): >>> timer = misc.Timer("cost_of_func", auto_print=False) >>> timer.start() + >>> def func(): + ... w = sum(range(0, 10)) >>> func() >>> timer.end() >>> print(f"time cost of 'cost_of_func' is {timer.interval:.2f}") + time cost of 'cost_of_func' is 0.00 """ interval: float # Time cost for code within Timer context diff --git a/ppsci/utils/writer.py b/ppsci/utils/writer.py index 16b7d5744..4046484ab 100644 --- a/ppsci/utils/writer.py +++ b/ppsci/utils/writer.py @@ -67,7 +67,7 @@ def save_csv_file( ... use_header=True, ... delimiter=",", ... encoding="utf-8", - ... ) + ... ) # doctest: +SKIP >>> # == test.csv == >>> # A,B @@ -150,7 +150,7 @@ def save_tecplot_file( ... num_y=3, ... alias_dict={"X": "x", "Y": "y"}, ... num_timestamps=2, - ... ) + ... ) # doctest: +SKIP >>> # == test_t-0.dat == >>> # title = "./test_t-0.dat" >>> # variables = "X", "Y" diff --git a/ppsci/visualize/radar.py b/ppsci/visualize/radar.py index 3d92ccfbe..abde75b77 100644 --- a/ppsci/visualize/radar.py +++ b/ppsci/visualize/radar.py @@ -38,6 +38,7 @@ class VisualizerRadar(base.Visualizer): Examples: >>> import ppsci + >>> import paddle >>> frames_tensor = paddle.randn([1, 29, 512, 512, 2]) >>> visualizer = ppsci.visualize.VisualizerRadar( ... {"input": frames_tensor},