export tutorials changed in dd88513 (#559)
Co-authored-by: dario-coscia <dario-coscia@users.noreply.github.com>
This commit is contained in:
committed by
Dario Coscia
parent
228f807d92
commit
d10c525e74
16
tutorials/tutorial14/tutorial.ipynb
vendored
16
tutorials/tutorial14/tutorial.ipynb
vendored
@@ -122,6 +122,7 @@
|
||||
" u_tt = laplacian(output_=output_, input_=input_, components=[\"u\"], d=[\"t\"])\n",
|
||||
" return u_tt + torch.exp(output_)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# define true solution\n",
|
||||
"def true_solution(x):\n",
|
||||
" alpha1 = torch.tensor([0.37929])\n",
|
||||
@@ -130,6 +131,7 @@
|
||||
" u2 = 2 * torch.log(torch.cosh(alpha2) / torch.cosh(alpha2 * (1 - 2 * x)))\n",
|
||||
" return u1, u2\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# build problem class\n",
|
||||
"class BratuProblem(TimeDependentProblem):\n",
|
||||
" output_variables = [\"u\"]\n",
|
||||
@@ -141,6 +143,7 @@
|
||||
" \"interior\": Condition(domain=\"interior\", equation=Equation(bratu_eq))\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# define problem and discretise domain\n",
|
||||
"problem = BratuProblem()\n",
|
||||
"problem.discretise_domain(n=101, mode=\"grid\", domains=\"interior\")"
|
||||
@@ -180,6 +183,7 @@
|
||||
" if param.requires_grad:\n",
|
||||
" torch.nn.init.normal_(param, mean=0.0, std=2.0)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# define a list of models with different initializations\n",
|
||||
"models = [Model(1, 1, inner_size=50, n_layers=2) for _ in range(10)]"
|
||||
]
|
||||
@@ -280,16 +284,18 @@
|
||||
" optimizers=optimizers,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# callback\n",
|
||||
"class StoreValue(Callback):\n",
|
||||
" def on_train_epoch_start(self, trainer, pl_module):\n",
|
||||
" input = LabelTensor(torch.tensor([[0.5]]), 't')\n",
|
||||
" input = LabelTensor(torch.tensor([[0.5]]), \"t\")\n",
|
||||
" output = pl_module(input).tensor.flatten()\n",
|
||||
" if trainer.current_epoch == 0:\n",
|
||||
" self.store = [output]\n",
|
||||
" else:\n",
|
||||
" self.store.append(output)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# define trainer\n",
|
||||
"trainer = Trainer(\n",
|
||||
" solver,\n",
|
||||
@@ -330,9 +336,9 @@
|
||||
"with torch.no_grad():\n",
|
||||
" metrics = torch.stack(trainer.callbacks[0].store, dim=0)\n",
|
||||
" plt.plot(range(metrics.shape[0]), metrics)\n",
|
||||
" plt.title('Ensemble Convergence')\n",
|
||||
" plt.ylabel(r'$u(0.5)$')\n",
|
||||
" plt.xlabel('epochs')\n",
|
||||
" plt.title(\"Ensemble Convergence\")\n",
|
||||
" plt.ylabel(r\"$u(0.5)$\")\n",
|
||||
" plt.xlabel(\"epochs\")\n",
|
||||
" plt.plot()"
|
||||
]
|
||||
},
|
||||
@@ -373,7 +379,7 @@
|
||||
" plt.plot(pts, u2, label=\"Reference solution u2\")\n",
|
||||
" for idx, sol in enumerate(u_ensemble):\n",
|
||||
" if idx == 0:\n",
|
||||
" plt.plot(pts, sol, \"--\", label=\"PINNs\", c='k')\n",
|
||||
" plt.plot(pts, sol, \"--\", label=\"PINNs\", c=\"k\")\n",
|
||||
" else:\n",
|
||||
" plt.plot(pts, sol, \"--\", c=\"k\")\n",
|
||||
" plt.legend()\n",
|
||||
|
||||
Reference in New Issue
Block a user