Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check conditions-solver compatibility #388

Open
wants to merge 1 commit into
base: 0.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pina/solvers/pinns/basepinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from abc import ABCMeta, abstractmethod
import torch
from torch.nn.modules.loss import _Loss
from ...condition import InputOutputPointsCondition, \
InputPointsEquationCondition, DomainEquationCondition
from ...solvers.solver import SolverInterface
from ...utils import check_consistency
from ...loss.loss_interface import LossInterface
Expand All @@ -24,6 +26,8 @@ class PINNInterface(SolverInterface, metaclass=ABCMeta):
to the user to choose which problem the implemented solver inheriting from
this class is suitable for.
"""
accepted_conditions_types = (InputOutputPointsCondition,
InputPointsEquationCondition, DomainEquationCondition)

def __init__(
self,
Expand Down
17 changes: 3 additions & 14 deletions pina/solvers/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import torch
import sys



class SolverInterface(lightning.pytorch.LightningModule, metaclass=ABCMeta):
"""
Solver base class. This class inherits is a wrapper of
Expand Down Expand Up @@ -134,18 +132,9 @@ def on_train_start(self):
return super().on_train_start()

def _check_solver_consistency(self, problem):
pass
#TODO : Implement this method for the conditions
'''


for _, condition in problem.conditions.items():
if not set(condition.condition_type).issubset(
set(self.accepted_condition_types)):
raise ValueError(
f'{self.__name__} dose not support condition '
f'{condition.condition_type}')
'''
for condition in problem.conditions.values():
check_consistency(condition, self.accepted_conditions_types)

@staticmethod
def get_batch_size(batch):
# Assuming batch is your custom Batch object
Expand Down
4 changes: 3 additions & 1 deletion pina/solvers/supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import torch
from pytorch_lightning.utilities.types import STEP_OUTPUT
from torch.nn.modules.loss import _Loss

from ..condition import InputOutputPointsCondition
from ..optim import TorchOptimizer, TorchScheduler
from .solver import SolverInterface
from ..label_tensor import LabelTensor
Expand Down Expand Up @@ -37,7 +39,7 @@ class SupervisedSolver(SolverInterface):
we are seeking to approximate multiple (discretised) functions given
multiple (discretised) input functions.
"""
__name__ = 'SupervisedSolver'
accepted_conditions_types = InputOutputPointsCondition

def __init__(self,
problem,
Expand Down
Loading