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/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__] 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: 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 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 ```````````