From 07b440f6d74013c5a629c3ed0a12174e4887631f Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Sun, 7 Apr 2024 20:24:17 +0800 Subject: [PATCH] [Doc] Add more contributors and refine several docstrings (#836) * auto generate contributors instead of adding manually * refine return type of docstrings --- docs/index.md | 29 ++--------------------------- docs/javascripts/contributors.js | 26 ++++++++++++++++++++++++++ mkdocs.yml | 1 + ppsci/equation/pde/base.py | 14 +++++--------- ppsci/geometry/geometry.py | 5 +---- ppsci/geometry/timedomain.py | 24 ++++++++++++++---------- 6 files changed, 49 insertions(+), 50 deletions(-) create mode 100644 docs/javascripts/contributors.js diff --git a/docs/index.md b/docs/index.md index 97e96bac0..ce3960db2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -200,7 +200,7 @@ ./README.md:thanks --8<-- -- PaddleScience 的部分代码由以下优秀社区开发者贡献(按 [Contributors](https://github.com/PaddlePaddle/PaddleScience/graphs/contributors) 排序): +- PaddleScience 的部分代码由以下优秀开发者贡献(按 [Contributors](https://github.com/PaddlePaddle/PaddleScience/graphs/contributors) 排序): - - - - - - - - - - - - - - - - - - - - - - - - - - +
## 🤝合作单位 diff --git a/docs/javascripts/contributors.js b/docs/javascripts/contributors.js new file mode 100644 index 000000000..8799c78e3 --- /dev/null +++ b/docs/javascripts/contributors.js @@ -0,0 +1,26 @@ +const owner = 'PaddlePaddle'; +const repo = 'PaddleScience'; + +fetch(`https://api.github.com/repos/${owner}/${repo}/contributors?per_page=65&page=1`, { + headers: { + "Accept": "application/vnd.github.v3+json" + } +}) +.then(response => { + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); +}) +.then(data => { + const contributorsDiv = document.getElementById('contributors'); + data.forEach(contributor => { + const a = document.createElement('a'); + a.href = `https://github.com/${contributor.login}`; + a.innerHTML = ``; + contributorsDiv.appendChild(a); + }); +}) +.catch((error) => { + console.error('Fetching contributors failed:', error); +}); diff --git a/mkdocs.yml b/mkdocs.yml index cf3809acd..e483d21fa 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -211,6 +211,7 @@ markdown_extensions: extra_javascript: - javascripts/bd_statistics.js - javascripts/mathjax.js + - javascripts/contributors.js - https://polyfill.io/v3/polyfill.min.js?features=es6 - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js diff --git a/ppsci/equation/pde/base.py b/ppsci/equation/pde/base.py index 9a0c0c53e..8dc0b3547 100644 --- a/ppsci/equation/pde/base.py +++ b/ppsci/equation/pde/base.py @@ -85,9 +85,6 @@ def add_equation(self, name: str, equation: Callable): def parameters(self) -> List[paddle.Tensor]: """Return learnable parameters contained in PDE. - Args: - None - Returns: List[Tensor]: A list of learnable parameters. @@ -106,9 +103,6 @@ def parameters(self) -> List[paddle.Tensor]: def state_dict(self) -> Dict[str, paddle.Tensor]: """Return named learnable parameters in dict. - Args: - None - Returns: Dict[str, Tensor]: A dict of states(str) and learnable parameters(Tensor). @@ -125,14 +119,16 @@ def state_dict(self) -> Dict[str, paddle.Tensor]: return self.learnable_parameters.state_dict() - def set_state_dict(self, state_dict: Dict[str, paddle.Tensor]): + def set_state_dict( + self, state_dict: Dict[str, paddle.Tensor] + ) -> Tuple[List[str], List[str]]: """Set state dict from dict. Args: state_dict (Dict[str, paddle.Tensor]): The state dict to be set. Returns: - None + Tuple[List[str], List[str]]: List of missing_keys and unexpected_keys. Examples: >>> import paddle @@ -148,7 +144,7 @@ def set_state_dict(self, state_dict: Dict[str, paddle.Tensor]): Tensor(shape=[], dtype=float64, place=Place(gpu:0), stop_gradient=False, 0.))]) """ - self.learnable_parameters.set_state_dict(state_dict) + return self.learnable_parameters.set_state_dict(state_dict) def __str__(self): return ", ".join( diff --git a/ppsci/geometry/geometry.py b/ppsci/geometry/geometry.py index 55a8e3b32..0ecaf565e 100644 --- a/ppsci/geometry/geometry.py +++ b/ppsci/geometry/geometry.py @@ -659,11 +659,8 @@ def __and__(self, other: "Geometry") -> "Geometry": def __str__(self) -> str: """Return the name of class. - Args: - None. - Returns: - str: The name of class. + str: Meta information of geometry. Examples: >>> import ppsci diff --git a/ppsci/geometry/timedomain.py b/ppsci/geometry/timedomain.py index 6bdb8d0fb..45732cf13 100644 --- a/ppsci/geometry/timedomain.py +++ b/ppsci/geometry/timedomain.py @@ -75,14 +75,14 @@ def __init__( elif timestamps is not None: self.num_timestamps = len(timestamps) - def on_initial(self, t: np.ndarray): + def on_initial(self, t: np.ndarray) -> np.ndarray: """Check if a specific time is on the initial time point. Args: t (np.ndarray): The time to be checked. Returns: - bool: True or False for whether the specific time is on the initial time point. + np.ndarray: Bool numpy array of whether the specific time is on the initial time point. Examples: >>> import paddle @@ -132,7 +132,7 @@ def boundary_normal(self, x): normal = self.geometry.boundary_normal(x[:, 1:]) return np.hstack((x[:, :1], normal)) - def uniform_points(self, n: int, boundary: bool = True): + def uniform_points(self, n: int, boundary: bool = True) -> np.ndarray: """Uniform points on the spatial-temporal domain. Geometry volume ~ bbox. Time volume ~ diam. @@ -202,7 +202,7 @@ def uniform_points(self, n: int, boundary: bool = True): def random_points( self, n: int, random: str = "pseudo", criteria: Optional[Callable] = None - ): + ) -> np.ndarray: """Generate random points on the spatial-temporal domain. Args: @@ -347,7 +347,9 @@ def random_points( t = np.random.permutation(t) return np.hstack((t, x)) - def uniform_boundary_points(self, n: int, criteria: Optional[Callable] = None): + def uniform_boundary_points( + self, n: int, criteria: Optional[Callable] = None + ) -> np.ndarray: """Uniform boundary points on the spatial-temporal domain. Geometry surface area ~ bbox. Time surface area ~ diam. @@ -427,7 +429,7 @@ def uniform_boundary_points(self, n: int, criteria: Optional[Callable] = None): def random_boundary_points( self, n: int, random: str = "pseudo", criteria: Optional[Callable] = None - ): + ) -> np.ndarray: """Random boundary points on the spatial-temporal domain. Args: @@ -621,7 +623,7 @@ def random_boundary_points( else: return t_x - def uniform_initial_points(self, n: int): + def uniform_initial_points(self, n: int) -> np.ndarray: """Generate evenly distributed point coordinates on the spatial-temporal domain at the initial moment. Args: @@ -645,7 +647,7 @@ def uniform_initial_points(self, n: int): x = x[:n] return np.hstack((np.full([n, 1], t, dtype=paddle.get_default_dtype()), x)) - def random_initial_points(self, n: int, random: str = "pseudo"): + def random_initial_points(self, n: int, random: str = "pseudo") -> np.ndarray: """Generate randomly distributed point coordinates on the spatial-temporal domain at the initial moment. Args: @@ -668,7 +670,9 @@ def random_initial_points(self, n: int, random: str = "pseudo"): t = self.timedomain.t0 return np.hstack((np.full([n, 1], t, dtype=paddle.get_default_dtype()), x)) - def periodic_point(self, x: Dict[str, np.ndarray], component: int): + def periodic_point( + self, x: Dict[str, np.ndarray], component: int + ) -> Dict[str, np.ndarray]: """process given point coordinates to satisfy the periodic boundary conditions of the geometry. Args: @@ -704,7 +708,7 @@ def sample_initial_interior( criteria: Optional[Callable] = None, evenly: bool = False, compute_sdf_derivatives: bool = False, - ): + ) -> Dict[str, np.ndarray]: """Sample random points in the time-geometry and return those meet criteria. Args: