Automatize Tutorials html, py files creation (#496)

* workflow to export tutorials

---------
This commit is contained in:
Dario Coscia
2025-03-15 11:01:19 +01:00
committed by FilippoOlivo
parent 8dfc9d19db
commit 3ff9f0c9a2
51 changed files with 140529 additions and 440 deletions

View File

@@ -25,12 +25,13 @@
"source": [
"## routine needed to run the notebook on Google Colab\n",
"try:\n",
" import google.colab\n",
" IN_COLAB = True\n",
" import google.colab\n",
"\n",
" IN_COLAB = True\n",
"except:\n",
" IN_COLAB = False\n",
" IN_COLAB = False\n",
"if IN_COLAB:\n",
" !pip install \"pina-mathlab\"\n",
" !pip install \"pina-mathlab\"\n",
"\n",
"import torch\n",
"import matplotlib.pyplot as plt\n",
@@ -46,7 +47,7 @@
"from pina.model import FeedForward\n",
"from pina.model.block import FourierFeatureEmbedding\n",
"\n",
"warnings.filterwarnings('ignore')"
"warnings.filterwarnings(\"ignore\")"
]
},
{
@@ -312,9 +313,13 @@
"l2_loss = LpLoss(p=2, relative=False)\n",
"\n",
"# sample new test points\n",
"pts = pts = problem.spatial_domain.sample(100, 'grid')\n",
"print(f'Relative l2 error PINN {l2_loss(pinn(pts), problem.solution(pts)).item():.2%}')\n",
"print(f'Relative l2 error SAPINN {l2_loss(sapinn(pts), problem.solution(pts)).item():.2%}')"
"pts = pts = problem.spatial_domain.sample(100, \"grid\")\n",
"print(\n",
" f\"Relative l2 error PINN {l2_loss(pinn(pts), problem.solution(pts)).item():.2%}\"\n",
")\n",
"print(\n",
" f\"Relative l2 error SAPINN {l2_loss(sapinn(pts), problem.solution(pts)).item():.2%}\"\n",
")"
]
},
{
@@ -462,12 +467,14 @@
}
],
"source": [
"#plot solution obtained\n",
"plot_solution(multiscale_pinn, 'Multiscale PINN solution')\n",
"# plot solution obtained\n",
"plot_solution(multiscale_pinn, \"Multiscale PINN solution\")\n",
"\n",
"# sample new test points\n",
"pts = pts = problem.spatial_domain.sample(100, 'grid')\n",
"print(f'Relative l2 error PINN with MultiscaleFourierNet: {l2_loss(multiscale_pinn(pts), problem.solution(pts)).item():.2%}')"
"pts = pts = problem.spatial_domain.sample(100, \"grid\")\n",
"print(\n",
" f\"Relative l2 error PINN with MultiscaleFourierNet: {l2_loss(multiscale_pinn(pts), problem.solution(pts)).item():.2%}\"\n",
")"
]
},
{