pinnx 0.0.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pinnx/__init__.py +13 -0
- pinnx/_convert.py +49 -0
- pinnx/_display.py +72 -0
- pinnx/_model.py +597 -0
- pinnx/callbacks.py +542 -0
- pinnx/data/__init__.py +38 -0
- pinnx/data/data.py +58 -0
- pinnx/data/dataset.py +69 -0
- pinnx/data/fpde.py +673 -0
- pinnx/data/function.py +62 -0
- pinnx/data/function_spaces.py +321 -0
- pinnx/data/helper.py +15 -0
- pinnx/data/ide.py +128 -0
- pinnx/data/mf.py +137 -0
- pinnx/data/pde.py +295 -0
- pinnx/data/pde_operator.py +354 -0
- pinnx/data/quadruple.py +100 -0
- pinnx/data/triple.py +93 -0
- pinnx/geometry/__init__.py +31 -0
- pinnx/geometry/base.py +456 -0
- pinnx/geometry/geometry_1d.py +184 -0
- pinnx/geometry/geometry_2d.py +1005 -0
- pinnx/geometry/geometry_3d.py +167 -0
- pinnx/geometry/geometry_nd.py +302 -0
- pinnx/geometry/pointcloud.py +88 -0
- pinnx/geometry/timedomain.py +184 -0
- pinnx/grad.py +90 -0
- pinnx/icbc/__init__.py +29 -0
- pinnx/icbc/base.py +95 -0
- pinnx/icbc/boundary_conditions.py +306 -0
- pinnx/icbc/initial_conditions.py +36 -0
- pinnx/metrics.py +70 -0
- pinnx/nn/__init__.py +28 -0
- pinnx/nn/base.py +37 -0
- pinnx/nn/deeponet.py +332 -0
- pinnx/nn/deeponet_strategy.py +155 -0
- pinnx/nn/fnn.py +154 -0
- pinnx/nn/mionet.py +239 -0
- pinnx/utils/__init__.py +5 -0
- pinnx/utils/array_ops.py +46 -0
- pinnx/utils/external.py +321 -0
- pinnx/utils/internal.py +211 -0
- pinnx/utils/sampler.py +76 -0
- pinnx/utils/sampling.py +1504 -0
- pinnx/utils/transformers.py +315 -0
- pinnx-0.0.1.dist-info/LICENSE +202 -0
- pinnx-0.0.1.dist-info/METADATA +104 -0
- pinnx-0.0.1.dist-info/RECORD +50 -0
- pinnx-0.0.1.dist-info/WHEEL +6 -0
- pinnx-0.0.1.dist-info/top_level.txt +1 -0
pinnx/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
__version__ = "0.0.1"
|
|
2
|
+
|
|
3
|
+
from . import callbacks
|
|
4
|
+
from . import data
|
|
5
|
+
from . import geometry
|
|
6
|
+
from . import grad
|
|
7
|
+
from . import icbc
|
|
8
|
+
from . import metrics
|
|
9
|
+
from . import nn
|
|
10
|
+
from . import utils
|
|
11
|
+
from ._model import Model
|
|
12
|
+
from pinnx._convert import array_to_dict, dict_to_array
|
|
13
|
+
from .utils import saveplot
|
pinnx/_convert.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright 2024 BDP Ecosystem Limited. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
|
|
16
|
+
import brainunit as u
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"array_to_dict",
|
|
21
|
+
"dict_to_array",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def array_to_dict(x, *names):
|
|
26
|
+
"""
|
|
27
|
+
Convert args to a dictionary.
|
|
28
|
+
"""
|
|
29
|
+
if x.shape[-1] != len(names):
|
|
30
|
+
raise ValueError("The number of columns of x must be equal to the number of names.")
|
|
31
|
+
|
|
32
|
+
return {key: x[..., i] for i, key in enumerate(names)}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def dict_to_array(d):
|
|
36
|
+
"""
|
|
37
|
+
Convert a dictionary to an array.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
d (dict): The dictionary.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
ndarray: The array.
|
|
44
|
+
"""
|
|
45
|
+
keys = tuple(d.keys())
|
|
46
|
+
if isinstance(d[keys[0]], np.ndarray):
|
|
47
|
+
return np.stack([d[key] for key in keys], axis=-1)
|
|
48
|
+
else:
|
|
49
|
+
return u.math.stack([d[key] for key in keys], axis=-1)
|
pinnx/_display.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from pinnx.utils import list_to_str
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TrainingDisplay:
|
|
9
|
+
"""
|
|
10
|
+
Display training progress.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self):
|
|
14
|
+
self.len_train = None
|
|
15
|
+
self.len_test = None
|
|
16
|
+
self.len_metric = None
|
|
17
|
+
self.is_header_print = False
|
|
18
|
+
|
|
19
|
+
def print_one(self, s1, s2, s3, s4):
|
|
20
|
+
print(
|
|
21
|
+
"{:{l1}s}{:{l2}s}{:{l3}s}{:{l4}s}".format(
|
|
22
|
+
s1,
|
|
23
|
+
s2,
|
|
24
|
+
s3,
|
|
25
|
+
s4,
|
|
26
|
+
l1=10,
|
|
27
|
+
l2=self.len_train,
|
|
28
|
+
l3=self.len_test,
|
|
29
|
+
l4=self.len_metric,
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
sys.stdout.flush()
|
|
33
|
+
|
|
34
|
+
def header(self):
|
|
35
|
+
self.print_one("Step", "Train loss", "Test loss", "Test metric")
|
|
36
|
+
self.is_header_print = True
|
|
37
|
+
|
|
38
|
+
def __call__(self, train_state):
|
|
39
|
+
if not self.is_header_print:
|
|
40
|
+
self.len_train = len(train_state.loss_train) * 10 + 4
|
|
41
|
+
self.len_test = len(train_state.loss_test) * 10 + 4
|
|
42
|
+
self.len_metric = len(train_state.metrics_test) * 10 + 4
|
|
43
|
+
self.header()
|
|
44
|
+
self.print_one(
|
|
45
|
+
str(train_state.step),
|
|
46
|
+
list_to_str(train_state.loss_train),
|
|
47
|
+
list_to_str(train_state.loss_test),
|
|
48
|
+
list_to_str(train_state.metrics_test),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def summary(self, train_state):
|
|
52
|
+
print("Best model at step {:d}:".format(train_state.best_step))
|
|
53
|
+
print(" train loss: {:.2e}".format(train_state.best_loss_train))
|
|
54
|
+
print(" test loss: {:.2e}".format(train_state.best_loss_test))
|
|
55
|
+
print(" test metric: {:s}".format(list_to_str(train_state.best_metrics)))
|
|
56
|
+
if train_state.best_ystd is not None:
|
|
57
|
+
print(" Uncertainty:")
|
|
58
|
+
print(" l2: {:g}".format(np.linalg.norm(train_state.best_ystd)))
|
|
59
|
+
print(
|
|
60
|
+
" l_infinity: {:g}".format(
|
|
61
|
+
np.linalg.norm(train_state.best_ystd, ord=np.inf)
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
print(
|
|
65
|
+
" max uncertainty location:",
|
|
66
|
+
train_state.X_test[np.argmax(train_state.best_ystd)],
|
|
67
|
+
)
|
|
68
|
+
print("")
|
|
69
|
+
self.is_header_print = False
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
training_display = TrainingDisplay()
|