Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 862076b

Browse files
1. remove useless imports; 2. fix bugs in csv_validator.py and navier_stokes.py; 3. replace f-string with string if f-string has no placeholders
1 parent f5008dc commit 862076b

File tree

14 files changed

+32
-35
lines changed

14 files changed

+32
-35
lines changed

ppsci/arch/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs):
3232
self._output_transform = None
3333

3434
def forward(self, *args, **kwargs):
35-
raise NotImplementedError(f"NetBase.forward is not implemented")
35+
raise NotImplementedError("NetBase.forward is not implemented")
3636

3737
@property
3838
def num_params(self):

ppsci/arch/mlp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ def __init__(
5151
if isinstance(hidden_size, (tuple, list)):
5252
if num_layers is not None:
5353
raise ValueError(
54-
f"num_layers should be None when hidden_size is specified"
54+
"num_layers should be None when hidden_size is specified"
5555
)
5656
elif isinstance(hidden_size, int):
5757
if not isinstance(num_layers, int):
5858
raise ValueError(
59-
f"num_layers should be an int when hidden_size is an int"
59+
"num_layers should be an int when hidden_size is an int"
6060
)
6161
hidden_size = [hidden_size] * num_layers
6262
else:

ppsci/constraint/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
limitations under the License.
1414
"""
1515

16-
import numpy as np
17-
1816
from ppsci import data
1917

2018

ppsci/constraint/boundary_constraint.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
limitations under the License.
1414
"""
1515

16-
import os.path as osp
1716
import types
1817

1918
import numpy as np
@@ -23,7 +22,6 @@
2322
from ppsci import geometry
2423
from ppsci.constraint import base
2524
from ppsci.data import dataset
26-
from ppsci.utils import misc
2725

2826

2927
class BoundaryConstraint(base.Constraint):

ppsci/constraint/supervised_constraint.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
limitations under the License.
1414
"""
1515

16-
import os.path as osp
1716
import types
1817

1918
import numpy as np
@@ -61,7 +60,7 @@ def __init__(
6160
# load data
6261
data = self._load_csv_file(data_file, input_keys + label_keys, alias_dict)
6362
if "t" not in data and timestamps is None:
64-
raise ValueError(f"must given time data from t0 or data itself.")
63+
raise ValueError("Time should be given by arg t0 or data itself.")
6564
if timestamps is not None:
6665
if "t" in data:
6766
raw_time_array = data["t"]
@@ -95,7 +94,7 @@ def __init__(
9594

9695
self.label_expr = {key: (lambda d, k=key: d[k]) for key in self.output_keys}
9796
else:
98-
raise NotImplementedError(f"Only suppport .csv file now.")
97+
raise NotImplementedError("Only suppport .csv file now.")
9998

10099
weight = {key: np.ones_like(next(iter(label.values()))) for key in label}
101100
if weight_dict is not None:
@@ -162,7 +161,7 @@ def __init__(
162161
# load data
163162
data = misc.load_csv_file(data_file, input_keys + label_keys, alias_dict)
164163
if "t" not in data and t0 is None:
165-
raise ValueError(f"must given time data from t0 or data itself.")
164+
raise ValueError("Time should be given by arg t0 or data itself.")
166165
if t0 is not None:
167166
data = misc.convert_to_array(data, self.input_keys + self.output_keys)
168167
data = misc.combine_array_with_time(data, [t0])
@@ -178,7 +177,7 @@ def __init__(
178177
self.label_expr = {key: (lambda d, k=key: d[k]) for key in self.output_keys}
179178
self.num_timestamp = 1
180179
else:
181-
raise NotImplementedError(f"Only suppport .csv file now.")
180+
raise NotImplementedError("Only suppport .csv file now.")
182181

183182
weight = {key: np.ones_like(next(iter(label.values()))) for key in label}
184183
if weight_dict is not None:

ppsci/equation/pde/navier_stokes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def momentum_y_compute_func(out):
9494
if self.dim == 3:
9595

9696
def momentum_z_compute_func(out):
97-
x, y = out["x"], out["y"]
98-
u, v, p = out["u"], out["v"], out["p"]
97+
x, y, z = out["x"], out["y"], out["z"]
98+
u, v, w, p = out["u"], out["v"], out["w"], out["p"]
9999
momentum_z = (
100100
u * jacobian(w, x)
101101
+ v * jacobian(w, y)

ppsci/geometry/geometry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def sample_interior(self, n, random="pseudo", criteria=None, evenly=False):
7878
_nsuc += 1
7979

8080
if _ntry >= 1000 and _nsuc == 0:
81-
raise RuntimeError(f"sample interior failed")
81+
raise RuntimeError("sample interior failed")
8282
return misc.convert_to_dict(x, self.dim_keys)
8383

8484
def sample_boundary(self, n, random="pseudo", criteria=None, evenly=False):
@@ -117,7 +117,7 @@ def sample_boundary(self, n, random="pseudo", criteria=None, evenly=False):
117117
_nsuc += 1
118118

119119
if _ntry >= 1000 and _nsuc == 0:
120-
raise RuntimeError(f"sample boundary failed")
120+
raise RuntimeError("sample boundary failed")
121121

122122
if not (
123123
misc.typename(self) == "TimeXGeometry"

ppsci/geometry/mesh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def sample_boundary(
270270
while _size < n:
271271
if evenly:
272272
raise ValueError(
273-
f"Can't sample evenly on mesh now, please set evenly=False."
273+
"Can't sample evenly on mesh now, please set evenly=False."
274274
)
275275
# points, normal, area = self.uniform_boundary_points(n, False)
276276
else:
@@ -290,7 +290,7 @@ def sample_boundary(
290290
_nsuc += 1
291291

292292
if _ntry >= 1000 and _nsuc == 0:
293-
raise RuntimeError(f"sample boundary failed")
293+
raise RuntimeError("sample boundary failed")
294294

295295
normal_dict = misc.convert_to_dict(
296296
normal, [f"normal_{key}" for key in self.dim_keys if key != "t"]
@@ -348,7 +348,7 @@ def sample_interior(self, n, random="pseudo", criteria=None, evenly=False):
348348
_nsuc += 1
349349

350350
if _ntry >= 1000 and _nsuc == 0:
351-
raise RuntimeError(f"sample interior failed")
351+
raise RuntimeError("sample interior failed")
352352

353353
x_dict = misc.convert_to_dict(x, self.dim_keys)
354354

ppsci/geometry/pointcloud.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
limitations under the License.
1414
"""
1515

16-
import os.path as osp
17-
1816
import numpy as np
1917

2018
from ppsci.geometry import geometry
@@ -136,7 +134,7 @@ def scale(self, scale):
136134
def uniform_boundary_points(self, n: int):
137135
"""Compute the equispaced points on the boundary."""
138136
raise NotImplementedError(
139-
f"PointCloud do not have 'uniform_boundary_points' method"
137+
"PointCloud do not have 'uniform_boundary_points' method"
140138
)
141139

142140
def random_boundary_points(self, n, random="pseudo"):
@@ -163,32 +161,32 @@ def random_points(self, n, random="pseudo"):
163161

164162
def union(self, rhs):
165163
raise NotImplementedError(
166-
f"Union operation for PointCloud is not supported yet."
164+
"Union operation for PointCloud is not supported yet."
167165
)
168166

169167
def __or__(self, rhs):
170168
raise NotImplementedError(
171-
f"Union operation for PointCloud is not supported yet."
169+
"Union operation for PointCloud is not supported yet."
172170
)
173171

174172
def difference(self, rhs):
175173
raise NotImplementedError(
176-
f"Subtraction operation for PointCloud is not supported yet."
174+
"Subtraction operation for PointCloud is not supported yet."
177175
)
178176

179177
def __sub__(self, rhs):
180178
raise NotImplementedError(
181-
f"Subtraction operation for PointCloud is not supported yet."
179+
"Subtraction operation for PointCloud is not supported yet."
182180
)
183181

184182
def intersection(self, rhs):
185183
raise NotImplementedError(
186-
f"Intersection operation for PointCloud is not supported yet."
184+
"Intersection operation for PointCloud is not supported yet."
187185
)
188186

189187
def __and__(self, rhs):
190188
raise NotImplementedError(
191-
f"Intersection operation for PointCloud is not supported yet."
189+
"Intersection operation for PointCloud is not supported yet."
192190
)
193191

194192
def __str__(self) -> str:

ppsci/geometry/timedomain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def sample_initial_interior(
370370
_nsuc += 1
371371

372372
if _ntry >= 1000 and _nsuc == 0:
373-
raise RuntimeError(f"sample initial interior failed")
373+
raise RuntimeError("sample initial interior failed")
374374
return misc.convert_to_dict(x, self.dim_keys)
375375

376376
def __str__(self) -> str:

0 commit comments

Comments
 (0)