Skip to content

Commit

Permalink
Merge branch 'lululxvi:master' into fix-variable-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
bonneted authored Dec 17, 2024
2 parents ea6af8b + ec4bdd3 commit 751aef5
Show file tree
Hide file tree
Showing 32 changed files with 1,101 additions and 278 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build SDist and wheel
run: pipx run build

- name: Upload SDist and wheel
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: dist/*
if-no-files-found: error
Expand All @@ -33,12 +33,12 @@ jobs:

steps:
- name: Download SDist and wheel
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4.1.7
with:
name: artifact
path: dist

- name: Publish on PyPI
uses: pypa/gh-action-pypi-publish@v1.6.4
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ First off, thanks for taking the time to contribute!

## The Team

DeepXDE was developed by [Lu Lu](https://github.com/lululxvi) under the supervision of Prof. [George Karniadakis](https://www.brown.edu/research/projects/crunch/george-karniadakis) at [Brown University](https://www.brown.edu) from the summer of 2018 to 2020, supported by [PhILMs](https://www.pnnl.gov/computing/philms). DeepXDE was originally self-hosted in Subversion at Brown University, under the name SciCoNet (Scientific Computing Neural Networks). On Feb 7, 2019, SciCoNet was moved from Subversion to GitHub, renamed to DeepXDE.
DeepXDE was developed by [Lu Lu](https://github.com/lululxvi) under the supervision of Prof. [George Karniadakis](https://www.brown.edu/research/projects/crunch/george-karniadakis) at [Brown University](https://www.brown.edu) from the summer of 2018 to 2020. DeepXDE was originally self-hosted in Subversion at Brown University, under the name SciCoNet (Scientific Computing Neural Networks). On Feb 7, 2019, SciCoNet was moved from Subversion to GitHub, renamed to DeepXDE.

DeepXDE is currently maintained by [Lu Lu](https://github.com/lululxvi) at [Yale University](https://www.yale.edu) with major contributions coming from many talented individuals in various forms and means. A non-exhaustive but growing list needs to mention: [Paul Escapil-Inchauspé](https://github.com/pescap), [Jialin Li](https://github.com/lijialin03), [Saransh Chopra](https://github.com/Saransh-cpp), [Zongren Zou](https://github.com/ZongrenZou), [Sensen He](https://github.com/HydrogenSulfate), [Zhongyi Jiang](https://github.com/Jerry-Jzy), [Anran Jiao](https://github.com/anranjiao), [Shunyuan Mao](https://github.com/smao-astro).
DeepXDE is currently maintained by [Lu Lu](https://github.com/lululxvi) at [Yale University](https://www.yale.edu) with major contributions coming from many talented individuals in various forms and means. A non-exhaustive but growing list needs to mention: [Paul Escapil-Inchauspé](https://github.com/pescap), [Zongren Zou](https://github.com/ZongrenZou), [Jialin Li](https://github.com/lijialin03), [Saransh Chopra](https://github.com/Saransh-cpp), [Sensen He](https://github.com/HydrogenSulfate), [Vladimir Dudenkov](https://github.com/vl-dud), [Anran Jiao](https://github.com/anranjiao), [Zhongyi Jiang](https://github.com/Jerry-Jzy), [Shunyuan Mao](https://github.com/smao-astro).

## License

Expand Down
39 changes: 39 additions & 0 deletions deepxde/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,42 @@ def sparse_dense_matmul(x, y):
Returns:
Tensor: The multiplication result.
"""


###############################################################################
# Regularization


def l1_regularization(l1):
"""A regularizer that applies a L1 regularization penalty or L1 weight decay.
Warning:
The implementation may vary across different backends.
Args:
l1 (float): L1 regularization factor.
"""


def l2_regularization(l2):
"""A regularizer that applies a L2 regularization penalty or L2 weight decay.
Warning:
The implementation may vary across different backends.
Args:
l2 (float): L2 regularization factor.
"""


def l1_l2_regularization(l1, l2):
"""A regularizer that applies both L1 and L2 regularization penalties or
L1 and L2 weight decay.
Warning:
The implementation may vary across different backends.
Args:
l1 (float): L1 regularization factor.
l2 (float): L2 regularization factor.
"""
8 changes: 8 additions & 0 deletions deepxde/backend/paddle/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,11 @@ def matmul(x, y):

def sparse_dense_matmul(x, y):
return paddle.sparse.matmul(x, y)


def l1_regularization(l1):
return paddle.regularizer.L1Decay(coeff=l1)


def l2_regularization(l2):
return paddle.regularizer.L2Decay(coeff=l2)
12 changes: 12 additions & 0 deletions deepxde/backend/tensorflow/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,15 @@ def zeros_like(input_tensor):

def matmul(x, y):
return tf.linalg.matmul(x, y)


def l1_regularization(l1):
return tf.keras.regularizers.L1(l1=l1)


def l2_regularization(l2):
return tf.keras.regularizers.L2(l2=l2)


def l1_l2_regularization(l1, l2):
return tf.keras.regularizers.L1L2(l1=l1, l2=l2)
12 changes: 12 additions & 0 deletions deepxde/backend/tensorflow_compat_v1/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,15 @@ def matmul(x, y):

def sparse_dense_matmul(x, y):
return tf.sparse.sparse_dense_matmul(x, y)


def l1_regularization(l1):
return tf.keras.regularizers.L1(l1=l1)


def l2_regularization(l2):
return tf.keras.regularizers.L2(l2=l2)


def l1_l2_regularization(l1, l2):
return tf.keras.regularizers.L1L2(l1=l1, l2=l2)
4 changes: 2 additions & 2 deletions deepxde/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __init__(
self.monitor = monitor
self.monitor_op = np.less
self.epochs_since_last_save = 0
self.best = np.Inf
self.best = np.inf

def on_epoch_end(self):
self.epochs_since_last_save += 1
Expand Down Expand Up @@ -221,7 +221,7 @@ def on_train_begin(self):
if self.baseline is not None:
self.best = self.baseline
else:
self.best = np.Inf if self.monitor_op == np.less else -np.Inf
self.best = np.inf if self.monitor_op == np.less else -np.inf

def on_epoch_end(self):
if self.model.train_state.epoch < self.start_from_epoch:
Expand Down
2 changes: 1 addition & 1 deletion deepxde/data/quadruple.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def train_next_batch(self, batch_size=None):
self.train_x[0][indices_branch],
self.train_x[1][indices_branch],
self.train_x[2][indices_trunk],
), self.train_y[indices_branch, indices_trunk]
), self.train_y[indices_branch][:, indices_trunk]

def test(self):
return self.test_x, self.test_y
31 changes: 31 additions & 0 deletions deepxde/geometry/geometry_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,37 @@ def uniform_points(self, n, boundary=True):
)
return x

def uniform_boundary_points(self, n):
points_per_face = max(1, n // (2 * self.dim))
points = []
for d in range(self.dim):
for boundary in [self.xmin[d], self.xmax[d]]:
xi = []
for i in range(self.dim):
if i == d:
xi.append(np.array([boundary], dtype=config.real(np)))
else:
ni = int(np.ceil(points_per_face ** (1 / (self.dim - 1))))
xi.append(
np.linspace(
self.xmin[i],
self.xmax[i],
num=ni + 1,
endpoint=False,
dtype=config.real(np),
)[1:]
)
face_points = np.array(list(itertools.product(*xi)))
points.append(face_points)
points = np.vstack(points)
if n != len(points):
print(
"Warning: {} points required, but {} points sampled.".format(
n, len(points)
)
)
return points

def random_points(self, n, random="pseudo"):
x = sample(n, self.dim, random)
return (self.xmax - self.xmin) * x + self.xmin
Expand Down
2 changes: 2 additions & 0 deletions deepxde/gradients/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ def clear():
"""Clear cached Jacobians and Hessians."""
if config.autodiff == "reverse":
gradients_reverse.clear()
elif config.autodiff == "forward":
gradients_forward.clear()
5 changes: 5 additions & 0 deletions deepxde/gradients/gradients_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ def jacobian(ys, xs, i=None, j=None):
def hessian(ys, xs, component=0, i=0, j=0):
dys_xj = jacobian(ys, xs, i=None, j=j)
return jacobian(dys_xj, xs, i=component, j=i)


def clear():
"""Clear cached Jacobians"""
jacobian._Jacobians.clear()
Loading

0 comments on commit 751aef5

Please sign in to comment.