From 4b80d2455b55fd276ef3888758ab697526fa2820 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Tue, 9 Jan 2024 14:45:35 +0100 Subject: [PATCH] Put jupyter notebook into documentation Signed-off-by: Johannes Mueller --- docs/conf.py | 2 + docs/requirements.txt | 9 +++- .../Introduction_Tutorial_PINNs.nblink | 3 ++ docs/tutorial/main_page.rst | 41 ++++++++----------- .../Introduction_Tutorial_PINNs.ipynb | 24 ++++++----- 5 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 docs/tutorial/Introduction_Tutorial_PINNs.nblink diff --git a/docs/conf.py b/docs/conf.py index cfc2a041..d11f16bc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -78,6 +78,8 @@ "sphinx.ext.ifconfig", "sphinx.ext.mathjax", "sphinx.ext.napoleon", + "nbsphinx", + "nbsphinx_link", ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/requirements.txt b/docs/requirements.txt index 9e4cb3cf..8d9bbe5d 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -13,4 +13,11 @@ trimesh>=3.9.19 shapely>=1.7.1 rtree>=0.9.7 scipy>=1.6.3 -networkx>=2.5.1 \ No newline at end of file +networkx>=2.5.1 +jupyter +nbsphinx +nbsphinx-link +sphinx_rtd_theme>=1.0 +ipywidgets +ipython<8.17.0 # https://github.com/ipython/ipython/issues/14235 +ipykernel diff --git a/docs/tutorial/Introduction_Tutorial_PINNs.nblink b/docs/tutorial/Introduction_Tutorial_PINNs.nblink new file mode 100644 index 00000000..3351cf20 --- /dev/null +++ b/docs/tutorial/Introduction_Tutorial_PINNs.nblink @@ -0,0 +1,3 @@ +{ + "path": "../../examples/tutorial/Introduction_Tutorial_PINNs.ipynb" +} diff --git a/docs/tutorial/main_page.rst b/docs/tutorial/main_page.rst index 8e314648..ce1d1c13 100644 --- a/docs/tutorial/main_page.rst +++ b/docs/tutorial/main_page.rst @@ -1,48 +1,43 @@ ========================= The TorchPhysics Tutorial ========================= -Here one can find all important information and knowledge to get started with the +Here one can find all important information and knowledge to get started with the software library TorchPhysics. -In order to make it as easy and user-friendly as possible for all users, +In order to make it as easy and user-friendly as possible for all users, both complete novices and professionals in Machine Learning and PDEs, to get started, the tutorial starts with some basics regarding differential equations and neural networks. For more experienced users, these points can be skipped. -Afterward, we give a rough overview of different Deep Learning approaches for solving +Afterward, we give a rough overview of different Deep Learning approaches for solving differential equations, with a focus on PINNs and DeepONet. The main and final topic is the use of TorchPhysics. Here we split the tutorial into two parts. -The first part, guides you along some implementations of different small examples, while showing +The first part, guides you along some implementations of different small examples, while showing all the important aspects and steps to solve a differential equation in TorchPhysics. This tutorial -series is aimed at an audience which is more interested on the direct utilization of the library +series is aimed at an audience which is more interested on the direct utilization of the library and for getting a fast and small overview of the possibilities. -To get a deeper understanding of the library, we show in the second part how the library is +To get a deeper understanding of the library, we show in the second part how the library is internally structured. This series is more aimed for users who plan to add or change functionalities. -Basics of Deep Learning and Differential Equations -===================================================== -Will be added in the future. +.. toctree:: + :maxdepth: 1 + :caption: Basics tutorial + Introduction_Tutorial_PINNs -Overview of Deep Learning Methods for Differential Equations -============================================================ -Will be added in the future. +.. toctree:: + :maxdepth: 1 + :caption: Applied tutorial -Usage of TorchPhysics -===================== -Like mentioned at the beginning, here we explain the aspects of TorchPhysics in more -detail. We split the tutorial into two categories: + applied_tutorial_start -1) A more applied tutorial to learn TorchPhysics by implementing some examples. - All basics features will be explained. The start can be found here_. -2) A more in depth tutorial that focuses more on the library architecture. This - tutorial begins on this page_. +.. toctree:: + :maxdepth: 1 + :caption: In depth tutorial - -.. _here : applied_tutorial_start.html -.. _page : tutorial_start.html \ No newline at end of file + tutorial_start diff --git a/examples/tutorial/Introduction_Tutorial_PINNs.ipynb b/examples/tutorial/Introduction_Tutorial_PINNs.ipynb index 2dcf3e30..a6095fb9 100644 --- a/examples/tutorial/Introduction_Tutorial_PINNs.ipynb +++ b/examples/tutorial/Introduction_Tutorial_PINNs.ipynb @@ -65,7 +65,7 @@ "id": "8da6279e-83c2-41ed-a56b-453b21f05d11", "metadata": {}, "source": [ - "# Recall PINNs\n", + "## Recall PINNs\n", "The goal is to find a neural network $u_\\theta: \\overline{\\Omega\\times I} \\to \\mathbb{R}$, which approximately satisfies all four conditions of the PDE problem above, where $\\theta$ are the trainable parameters of the neural network.\n", "Let us shortly recall the main idea behind PINNs.\n", "\n", @@ -105,7 +105,7 @@ "id": "8f0db4a0-cace-4d21-845f-f34680880d7d", "metadata": {}, "source": [ - "# Translating the PDE Problem into the Language of TorchPhysics\n", + "## Translating the PDE Problem into the Language of TorchPhysics\n", "Translating the PDE problem into the framework of TorchPhysics works in a convenient and intuitive way, as the notation is close to the mathematical formulation. The general procedure can be devided into five steps. Also when solving other problems with TorchPhysics, such as parameter identification or variational problems, the same steps can be applied, see also the further [tutorials](https://torchphysics.readthedocs.io/en/latest/tutorial/tutorial_start.html) or [examples](https://torchphysics.readthedocs.io/en/latest/examples.html)." ] }, @@ -529,7 +529,7 @@ "id": "31d80c43-5879-401c-8212-0e4a5fd6514c", "metadata": {}, "source": [ - "# Training based on Pytorch Lightning \n", + "## Training based on Pytorch Lightning \n", "In order to train a model, TorchPhysics makes use of the Pytorch Lightning library, which hence must be imported. Further, we import \"os\" so that GPUs can be used for the calculations." ] }, @@ -622,11 +622,13 @@ "outputs": [], "source": [ "# Start the training\n", - "trainer = pl.Trainer(gpus=device, # or None if CPU is used\n", - " max_steps=5000, # number of training steps\n", - " logger=False,\n", - " benchmark=True,\n", - " checkpoint_callback=False)\n", + "trainer = pl.Trainer(\n", + " gpus=device, # or None if CPU is used\n", + " max_steps=5000, # number of training steps\n", + " logger=False,\n", + " benchmark=True,\n", + " # checkpoint_callback=False # Uncomment this for more verbose\n", + ")\n", "\n", "trainer.fit(solver) # start training" ] @@ -648,7 +650,7 @@ "id": "bac7c186-2be3-4ce0-a252-527ae5083019", "metadata": {}, "source": [ - "# Visualization\n", + "## Visualization\n", "Torchphysics provides built-in functionalities for visualizing the outcome of the neural network.\n", "As a first step, for the 2D heat equation example one might be interested in creating a contour plot for the heat distribution inside of the room at some fixed time.\n", "\n", @@ -862,7 +864,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -876,7 +878,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.4" + "version": "3.10.13" } }, "nbformat": 4,