From a3c677c8436dc47f083c1f9d18a5b8580caa0a1f Mon Sep 17 00:00:00 2001 From: Jerry-Jzy <66828815+Jerry-Jzy@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:59:11 -0500 Subject: [PATCH 1/8] Bug fix: PDEOperatorCartesianProd (#1925) --- deepxde/data/pde_operator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepxde/data/pde_operator.py b/deepxde/data/pde_operator.py index 3b001cf9a..85174215b 100644 --- a/deepxde/data/pde_operator.py +++ b/deepxde/data/pde_operator.py @@ -307,7 +307,7 @@ def forward_call(trunk_input): losses_bc = zip(*losses_bc) losses_bc = [bkd.reduce_mean(bkd.stack(loss, 0)) for loss in losses_bc] - losses.append(losses_bc) + losses.extend(losses_bc) return losses def losses_train(self, targets, outputs, loss_fn, inputs, model, aux=None): From 6a067667a6a59da3445a8d6533f54317fbdcbf4f Mon Sep 17 00:00:00 2001 From: lululxvi Date: Fri, 3 Jan 2025 20:30:56 -0500 Subject: [PATCH 2/8] Update docs --- docs/index.rst | 1 + docs/modules/deepxde.optimizers.pytorch.rst | 20 +++++--------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index ab36ce6f1..306dcc79d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -107,6 +107,7 @@ If you are looking for information on a specific function, class or method, this modules/deepxde.nn.tensorflow modules/deepxde.nn.tensorflow_compat_v1 modules/deepxde.optimizers + modules/deepxde.optimizers.pytorch modules/deepxde.utils Indices and tables diff --git a/docs/modules/deepxde.optimizers.pytorch.rst b/docs/modules/deepxde.optimizers.pytorch.rst index a01e34f85..7451e2806 100644 --- a/docs/modules/deepxde.optimizers.pytorch.rst +++ b/docs/modules/deepxde.optimizers.pytorch.rst @@ -1,21 +1,11 @@ -deepxde.optimizers.pytorch package -================================== +deepxde.optimizers.pytorch +========================== -Submodules ----------- +deepxde.optimizers.pytorch.nncg module +-------------------------------------- -deepxde.optimizers.pytorch.optimizers module --------------------------------------------- - -.. automodule:: deepxde.optimizers.pytorch.optimizers +.. automodule:: deepxde.optimizers.pytorch.nncg :members: :undoc-members: :show-inheritance: -Module contents ---------------- - -.. automodule:: deepxde.optimizers.pytorch - :members: - :undoc-members: - :show-inheritance: From 28dee2265c38f783c5d9870aecc87a2f7fd0ddb6 Mon Sep 17 00:00:00 2001 From: lululxvi Date: Fri, 3 Jan 2025 21:33:10 -0500 Subject: [PATCH 3/8] get Sphinx documentation to build all optimizers --- deepxde/optimizers/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/deepxde/optimizers/__init__.py b/deepxde/optimizers/__init__.py index 556761a86..2f669ae76 100644 --- a/deepxde/optimizers/__init__.py +++ b/deepxde/optimizers/__init__.py @@ -5,6 +5,17 @@ from ..backend import backend_name +# To get Sphinx documentation to build, we import all +if os.environ.get("READTHEDOCS") == "True": + # The backend should be tensorflow/tensorflow.compat.v1 to ensure backend.tf is not + # None. + from . import jax + from . import paddle + from . import pytorch + from . import tensorflow + from . import tensorflow_compat_v1 + + def _load_backend(mod_name): mod = importlib.import_module(".%s" % mod_name, __name__) thismod = sys.modules[__name__] From 9be09b275cfcfa23f9e34cb419bf6d4ca188ae94 Mon Sep 17 00:00:00 2001 From: lululxvi Date: Fri, 3 Jan 2025 21:41:02 -0500 Subject: [PATCH 4/8] Bug fix for previous commit --- deepxde/optimizers/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/deepxde/optimizers/__init__.py b/deepxde/optimizers/__init__.py index 2f669ae76..b99904b2c 100644 --- a/deepxde/optimizers/__init__.py +++ b/deepxde/optimizers/__init__.py @@ -1,4 +1,5 @@ import importlib +import os import sys from .config import LBFGS_options, set_LBFGS_options, NNCG_options, set_NNCG_options From 1b5027601459b11d1ed05a17a7a0f776c59a2008 Mon Sep 17 00:00:00 2001 From: lululxvi Date: Fri, 3 Jan 2025 21:55:16 -0500 Subject: [PATCH 5/8] get Sphinx documentation to build NNCG optimizer --- deepxde/optimizers/pytorch/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/deepxde/optimizers/pytorch/__init__.py b/deepxde/optimizers/pytorch/__init__.py index affedd3bd..1c7968624 100644 --- a/deepxde/optimizers/pytorch/__init__.py +++ b/deepxde/optimizers/pytorch/__init__.py @@ -1,3 +1,4 @@ __all__ = ["get", "is_external_optimizer"] +from .nncg import NNCG # To get Sphinx documentation to build from .optimizers import get, is_external_optimizer From 46e628e7353f89f25c5a3f477b25b1191ab8e6e1 Mon Sep 17 00:00:00 2001 From: lululxvi Date: Fri, 3 Jan 2025 22:13:29 -0500 Subject: [PATCH 6/8] Revert PyTorch NNCG optimizer doc build; Try torch v2 for Sphinx --- deepxde/optimizers/__init__.py | 12 ------------ deepxde/optimizers/pytorch/__init__.py | 1 - docs/requirements.txt | 2 +- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/deepxde/optimizers/__init__.py b/deepxde/optimizers/__init__.py index b99904b2c..556761a86 100644 --- a/deepxde/optimizers/__init__.py +++ b/deepxde/optimizers/__init__.py @@ -1,22 +1,10 @@ import importlib -import os import sys from .config import LBFGS_options, set_LBFGS_options, NNCG_options, set_NNCG_options from ..backend import backend_name -# To get Sphinx documentation to build, we import all -if os.environ.get("READTHEDOCS") == "True": - # The backend should be tensorflow/tensorflow.compat.v1 to ensure backend.tf is not - # None. - from . import jax - from . import paddle - from . import pytorch - from . import tensorflow - from . import tensorflow_compat_v1 - - def _load_backend(mod_name): mod = importlib.import_module(".%s" % mod_name, __name__) thismod = sys.modules[__name__] diff --git a/deepxde/optimizers/pytorch/__init__.py b/deepxde/optimizers/pytorch/__init__.py index 1c7968624..affedd3bd 100644 --- a/deepxde/optimizers/pytorch/__init__.py +++ b/deepxde/optimizers/pytorch/__init__.py @@ -1,4 +1,3 @@ __all__ = ["get", "is_external_optimizer"] -from .nncg import NNCG # To get Sphinx documentation to build from .optimizers import get, is_external_optimizer diff --git a/docs/requirements.txt b/docs/requirements.txt index 5d0c53fba..9f042ef45 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -9,7 +9,7 @@ tensorflow>=2.7.0 # TensorFlow 2.x tensorflow-probability>=0.11.0 # PyTorch -torch<2.0.0 # build fails on RTD with torch 2.0.0 +torch # PaddlePaddle # https://paddle-wheel.bj.bcebos.com/develop/linux/linux-cpu-mkl-avx/paddlepaddle-0.0.0-cp38-cp38-linux_x86_64.whl paddlepaddle==2.6.0 From d99fa2f6881a442e112c836436d0e92bf0660ed1 Mon Sep 17 00:00:00 2001 From: lululxvi Date: Fri, 3 Jan 2025 22:21:59 -0500 Subject: [PATCH 7/8] get Sphinx documentation to build pytorch NNCG optimizer --- deepxde/optimizers/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/deepxde/optimizers/__init__.py b/deepxde/optimizers/__init__.py index 556761a86..b99904b2c 100644 --- a/deepxde/optimizers/__init__.py +++ b/deepxde/optimizers/__init__.py @@ -1,10 +1,22 @@ import importlib +import os import sys from .config import LBFGS_options, set_LBFGS_options, NNCG_options, set_NNCG_options from ..backend import backend_name +# To get Sphinx documentation to build, we import all +if os.environ.get("READTHEDOCS") == "True": + # The backend should be tensorflow/tensorflow.compat.v1 to ensure backend.tf is not + # None. + from . import jax + from . import paddle + from . import pytorch + from . import tensorflow + from . import tensorflow_compat_v1 + + def _load_backend(mod_name): mod = importlib.import_module(".%s" % mod_name, __name__) thismod = sys.modules[__name__] From 7bcda4b80b777c934ff35f0fe35c0bc54e219859 Mon Sep 17 00:00:00 2001 From: lululxvi Date: Fri, 3 Jan 2025 22:42:07 -0500 Subject: [PATCH 8/8] Require PyTorch>=2.0.0 --- README.md | 2 +- deepxde/backend/pytorch/tensor.py | 4 ++-- docs/user/installation.rst | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9bd5eb8f3..2cc1f01d1 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ DeepXDE requires one of the following backend-specific dependencies to be instal - TensorFlow 1.x: [TensorFlow](https://www.tensorflow.org)>=2.7.0 - TensorFlow 2.x: [TensorFlow](https://www.tensorflow.org)>=2.3.0, [TensorFlow Probability](https://www.tensorflow.org/probability)>=0.11.0 -- PyTorch: [PyTorch](https://pytorch.org)>=1.9.0 +- PyTorch: [PyTorch](https://pytorch.org)>=2.0.0 - JAX: [JAX](https://jax.readthedocs.io), [Flax](https://flax.readthedocs.io), [Optax](https://optax.readthedocs.io) - PaddlePaddle: [PaddlePaddle](https://www.paddlepaddle.org.cn/en)>=2.6.0 diff --git a/deepxde/backend/pytorch/tensor.py b/deepxde/backend/pytorch/tensor.py index 4d32d68f2..474293d9c 100644 --- a/deepxde/backend/pytorch/tensor.py +++ b/deepxde/backend/pytorch/tensor.py @@ -4,8 +4,8 @@ import torch -if Version(torch.__version__) < Version("1.9.0"): - raise RuntimeError("DeepXDE requires PyTorch>=1.9.0.") +if Version(torch.__version__) < Version("2.0.0"): + raise RuntimeError("DeepXDE requires PyTorch>=2.0.0.") # To write device-agnostic (CPU or GPU) code, a common pattern is to first determine # torch.device and then use it for all the tensors. diff --git a/docs/user/installation.rst b/docs/user/installation.rst index 2dcf7eede..d7caa3ac2 100644 --- a/docs/user/installation.rst +++ b/docs/user/installation.rst @@ -14,7 +14,7 @@ DeepXDE requires one of the following backend-specific dependencies to be instal - For TensorFlow 2.16+ with Keras 3, refer to `the instruction `_ for installing TensorFlow Probability. -- PyTorch: `PyTorch `_>=1.9.0 +- PyTorch: `PyTorch `_>=2.0.0 - JAX: `JAX `_, `Flax `_, `Optax `_ - PaddlePaddle: `PaddlePaddle `_>=2.6.0 @@ -124,7 +124,7 @@ Export ``DDE_BACKEND`` as ``pytorch`` to specify PyTorch backend. In addition, i .. code:: python if torch.cuda.is_available(): - torch.set_default_tensor_type(torch.cuda.FloatTensor) + torch.set_default_device("cuda") JAX backend ```````````