Skip to content

Commit

Permalink
Change PODLayer name (#251)
Browse files Browse the repository at this point in the history
* rename PODBlock
* add tutorial rst

---------

Co-authored-by: Dario Coscia <[email protected]>
Co-authored-by: Dario Coscia <[email protected]>
  • Loading branch information
3 people authored Feb 29, 2024
1 parent c2529d3 commit c92a283
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/source/_rst/_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Supervised Learning
:titlesonly:

Unstructured convolutional autoencoder via continuous convolution<tutorials/tutorial4/tutorial.rst>

POD-NN for reduced order modeling<tutorials/tutorial8/tutorial.rst>
10 changes: 5 additions & 5 deletions docs/source/_rst/tutorials/tutorial8/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ minimum PINA version to run this tutorial is the ``0.1``.
from pina.geometry import CartesianDomain
from pina.problem import ParametricProblem
from pina.model.layers import PODLayer
from pina.model.layers import PODBlock
from pina import Condition, LabelTensor, Trainer
from pina.model import FeedForward
from pina.solvers import SupervisedSolver
Expand Down Expand Up @@ -130,7 +130,7 @@ architecture that takes in input the parameter and return the *modal
coefficients*, so the reduced dimension representation (the coordinates
in the POD space). Such latent variable is the projected to the original
space using the POD modes, which are computed and stored in the
``PODLayer`` object.
``PODBlock`` object.

.. code:: ipython3
Expand All @@ -145,7 +145,7 @@ space using the POD modes, which are computed and stored in the
"""
super().__init__()
self.pod = PODLayer(pod_rank)
self.pod = PODBlock(pod_rank)
self.nn = FeedForward(
input_dimensions=1,
output_dimensions=pod_rank,
Expand All @@ -168,8 +168,8 @@ space using the POD modes, which are computed and stored in the
def fit_pod(self, x):
"""
Just call the :meth:`pina.model.layers.PODLayer.fit` method of the
:attr:`pina.model.layers.PODLayer` attribute.
Just call the :meth:`pina.model.layers.PODBlock.fit` method of the
:attr:`pina.model.layers.PODBlock` attribute.
"""
self.pod.fit(x)
Expand Down
4 changes: 2 additions & 2 deletions pina/model/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"FourierBlock1D",
"FourierBlock2D",
"FourierBlock3D",
"PODLayer",
"PODBlock",
]

from .convolution_2d import ContinuousConvBlock
Expand All @@ -19,4 +19,4 @@
SpectralConvBlock3D,
)
from .fourier import FourierBlock1D, FourierBlock2D, FourierBlock3D
from .pod import PODLayer
from .pod import PODBlock
2 changes: 1 addition & 1 deletion pina/model/layers/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .utils_convolution import optimizing


class PODLayer(torch.nn.Module):
class PODBlock(torch.nn.Module):
"""
POD layer: it projects the input field on the proper orthogonal
decomposition basis. It needs to be fitted to the data before being used
Expand Down
22 changes: 11 additions & 11 deletions tests/test_layers/test_pod.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import torch
import pytest

from pina.model.layers.pod import PODLayer
from pina.model.layers.pod import PODBlock

x = torch.linspace(-1, 1, 100)
toy_snapshots = torch.vstack([torch.exp(-x**2)*c for c in torch.linspace(0, 1, 10)])

def test_constructor():
pod = PODLayer(2)
pod = PODLayer(2, True)
pod = PODLayer(2, False)
pod = PODBlock(2)
pod = PODBlock(2, True)
pod = PODBlock(2, False)
with pytest.raises(TypeError):
pod = PODLayer()
pod = PODBlock()


@pytest.mark.parametrize("rank", [1, 2, 10])
def test_fit(rank, scale):
pod = PODLayer(rank, scale)
pod = PODBlock(rank, scale)
assert pod._basis == None
assert pod.basis == None
assert pod._scaler == None
Expand All @@ -26,7 +26,7 @@ def test_fit(rank, scale):
@pytest.mark.parametrize("scale", [True, False])
@pytest.mark.parametrize("rank", [1, 2, 10])
def test_fit(rank, scale):
pod = PODLayer(rank, scale)
pod = PODBlock(rank, scale)
pod.fit(toy_snapshots)
n_snap = toy_snapshots.shape[0]
dof = toy_snapshots.shape[1]
Expand All @@ -43,7 +43,7 @@ def test_fit(rank, scale):
assert pod.scaler == None

def test_forward():
pod = PODLayer(1)
pod = PODBlock(1)
pod.fit(toy_snapshots)
c = pod(toy_snapshots)
assert c.shape[0] == toy_snapshots.shape[0]
Expand All @@ -55,7 +55,7 @@ def test_forward():
assert c.shape[1] == pod.rank
assert c.shape[0] == 1

pod = PODLayer(2, False)
pod = PODBlock(2, False)
pod.fit(toy_snapshots)
c = pod(toy_snapshots)
torch.testing.assert_close(c, (pod.basis @ toy_snapshots.T).T)
Expand All @@ -66,7 +66,7 @@ def test_forward():
@pytest.mark.parametrize("scale", [True, False])
@pytest.mark.parametrize("rank", [1, 2, 10])
def test_expand(rank, scale):
pod = PODLayer(rank, scale)
pod = PODBlock(rank, scale)
pod.fit(toy_snapshots)
c = pod(toy_snapshots)
torch.testing.assert_close(pod.expand(c), toy_snapshots)
Expand All @@ -75,7 +75,7 @@ def test_expand(rank, scale):
@pytest.mark.parametrize("scale", [True, False])
@pytest.mark.parametrize("rank", [1, 2, 10])
def test_reduce_expand(rank, scale):
pod = PODLayer(rank, scale)
pod = PODBlock(rank, scale)
pod.fit(toy_snapshots)
torch.testing.assert_close(
pod.expand(pod.reduce(toy_snapshots)),
Expand Down
10 changes: 5 additions & 5 deletions tutorials/tutorial8/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"from pina.geometry import CartesianDomain\n",
"\n",
"from pina.problem import ParametricProblem\n",
"from pina.model.layers import PODLayer\n",
"from pina.model.layers import PODBlock\n",
"from pina import Condition, LabelTensor, Trainer\n",
"from pina.model import FeedForward\n",
"from pina.solvers import SupervisedSolver\n",
Expand Down Expand Up @@ -172,7 +172,7 @@
"id": "6b264569-57b3-458d-bb69-8e94fe89017d",
"metadata": {},
"source": [
"Then, we define the model we want to use: basically we have a MLP architecture that takes in input the parameter and return the *modal coefficients*, so the reduced dimension representation (the coordinates in the POD space). Such latent variable is the projected to the original space using the POD modes, which are computed and stored in the `PODLayer` object."
"Then, we define the model we want to use: basically we have a MLP architecture that takes in input the parameter and return the *modal coefficients*, so the reduced dimension representation (the coordinates in the POD space). Such latent variable is the projected to the original space using the POD modes, which are computed and stored in the `PODBlock` object."
]
},
{
Expand All @@ -193,7 +193,7 @@
" \"\"\"\n",
" super().__init__()\n",
" \n",
" self.pod = PODLayer(pod_rank)\n",
" self.pod = PODBlock(pod_rank)\n",
" self.nn = FeedForward(\n",
" input_dimensions=1,\n",
" output_dimensions=pod_rank,\n",
Expand All @@ -216,8 +216,8 @@
"\n",
" def fit_pod(self, x):\n",
" \"\"\"\n",
" Just call the :meth:`pina.model.layers.PODLayer.fit` method of the\n",
" :attr:`pina.model.layers.PODLayer` attribute.\n",
" Just call the :meth:`pina.model.layers.PODBlock.fit` method of the\n",
" :attr:`pina.model.layers.PODBlock` attribute.\n",
" \"\"\"\n",
" self.pod.fit(x)"
]
Expand Down
10 changes: 5 additions & 5 deletions tutorials/tutorial8/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pina.geometry import CartesianDomain

from pina.problem import ParametricProblem
from pina.model.layers import PODLayer
from pina.model.layers import PODBlock
from pina import Condition, LabelTensor, Trainer
from pina.model import FeedForward
from pina.solvers import SupervisedSolver
Expand Down Expand Up @@ -85,7 +85,7 @@ class SnapshotProblem(ParametricProblem):
}


# Then, we define the model we want to use: basically we have a MLP architecture that takes in input the parameter and return the *modal coefficients*, so the reduced dimension representation (the coordinates in the POD space). Such latent variable is the projected to the original space using the POD modes, which are computed and stored in the `PODLayer` object.
# Then, we define the model we want to use: basically we have a MLP architecture that takes in input the parameter and return the *modal coefficients*, so the reduced dimension representation (the coordinates in the POD space). Such latent variable is the projected to the original space using the POD modes, which are computed and stored in the `PODBlock` object.

# In[33]:

Expand All @@ -101,7 +101,7 @@ def __init__(self, pod_rank, layers, func):
"""
super().__init__()

self.pod = PODLayer(pod_rank)
self.pod = PODBlock(pod_rank)
self.nn = FeedForward(
input_dimensions=1,
output_dimensions=pod_rank,
Expand All @@ -124,8 +124,8 @@ def forward(self, x):

def fit_pod(self, x):
"""
Just call the :meth:`pina.model.layers.PODLayer.fit` method of the
:attr:`pina.model.layers.PODLayer` attribute.
Just call the :meth:`pina.model.layers.PODBlock.fit` method of the
:attr:`pina.model.layers.PODBlock` attribute.
"""
self.pod.fit(x)

Expand Down

0 comments on commit c92a283

Please sign in to comment.