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 Nicola Demo
parent aea24d0bee
commit 0146155c9b
51 changed files with 140529 additions and 440 deletions

View File

@@ -33,15 +33,16 @@
"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 scipy\n",
" # get the data\n",
" !wget https://github.com/mathLab/PINA/raw/refs/heads/master/tutorials/tutorial5/Data_Darcy.mat\n",
" !pip install \"pina-mathlab\"\n",
" !pip install scipy\n",
" # get the data\n",
" !wget https://github.com/mathLab/PINA/raw/refs/heads/master/tutorials/tutorial5/Data_Darcy.mat\n",
"\n",
"import torch\n",
"import matplotlib.pyplot as plt\n",
@@ -54,7 +55,7 @@
"from pina.solver import SupervisedSolver\n",
"from pina.problem.zoo import SupervisedProblem\n",
"\n",
"warnings.filterwarnings('ignore')"
"warnings.filterwarnings(\"ignore\")"
]
},
{
@@ -129,10 +130,10 @@
],
"source": [
"plt.subplot(1, 2, 1)\n",
"plt.title('permeability')\n",
"plt.title(\"permeability\")\n",
"plt.imshow(k_train[0])\n",
"plt.subplot(1, 2, 2)\n",
"plt.title('field solution')\n",
"plt.title(\"field solution\")\n",
"plt.imshow(u_train[0])\n",
"plt.show()"
]
@@ -278,12 +279,10 @@
" )\n",
" * 100\n",
")\n",
"print(f'Final error training {err:.2f}%')\n",
"print(f\"Final error training {err:.2f}%\")\n",
"\n",
"err = (\n",
" float(\n",
" metric_err(u_test.unsqueeze(-1), model(k_test.unsqueeze(-1))).mean()\n",
" )\n",
" float(metric_err(u_test.unsqueeze(-1), model(k_test.unsqueeze(-1))).mean())\n",
" * 100\n",
")\n",
"print(f\"Final error testing {err:.2f}%\")"