Codacy correction
This commit is contained in:
committed by
Nicola Demo
parent
ea3d1924e7
commit
dd43c8304c
@@ -39,21 +39,16 @@ class Condition:
|
||||
"""
|
||||
|
||||
__slots__ = list(
|
||||
set(
|
||||
InputOutputPointsCondition.__slots__ +
|
||||
set(InputOutputPointsCondition.__slots__ +
|
||||
InputPointsEquationCondition.__slots__ +
|
||||
DomainEquationCondition.__slots__ +
|
||||
DataConditionInterface.__slots__
|
||||
)
|
||||
)
|
||||
DataConditionInterface.__slots__))
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
|
||||
if len(args) != 0:
|
||||
raise ValueError(
|
||||
"Condition takes only the following keyword "
|
||||
f"arguments: {Condition.__slots__}."
|
||||
)
|
||||
raise ValueError("Condition takes only the following keyword "
|
||||
f"arguments: {Condition.__slots__}.")
|
||||
|
||||
sorted_keys = sorted(kwargs.keys())
|
||||
if sorted_keys == sorted(InputOutputPointsCondition.__slots__):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
from abc import ABCMeta
|
||||
|
||||
|
||||
class ConditionInterface(metaclass=ABCMeta):
|
||||
|
||||
condition_types = ['physics', 'supervised', 'unsupervised']
|
||||
@@ -12,7 +12,7 @@ class ConditionInterface(metaclass=ABCMeta):
|
||||
@property
|
||||
def problem(self):
|
||||
return self._problem
|
||||
|
||||
|
||||
@problem.setter
|
||||
def problem(self, value):
|
||||
self._problem = value
|
||||
@@ -20,15 +20,14 @@ class ConditionInterface(metaclass=ABCMeta):
|
||||
@property
|
||||
def condition_type(self):
|
||||
return self._condition_type
|
||||
|
||||
|
||||
@condition_type.setter
|
||||
def condition_type(self, values):
|
||||
if not isinstance(values, (list, tuple)):
|
||||
values = [values]
|
||||
for value in values:
|
||||
if value not in ConditionInterface.condition_types:
|
||||
raise ValueError(
|
||||
'Unavailable type of condition, expected one of'
|
||||
f' {ConditionInterface.condition_types}.'
|
||||
)
|
||||
self._condition_type = values
|
||||
raise ValueError(
|
||||
'Unavailable type of condition, expected one of'
|
||||
f' {ConditionInterface.condition_types}.')
|
||||
self._condition_type = values
|
||||
|
||||
@@ -5,6 +5,7 @@ from ..label_tensor import LabelTensor
|
||||
from ..graph import Graph
|
||||
from ..utils import check_consistency
|
||||
|
||||
|
||||
class DataConditionInterface(ConditionInterface):
|
||||
"""
|
||||
Condition for data. This condition must be used every
|
||||
@@ -29,4 +30,4 @@ class DataConditionInterface(ConditionInterface):
|
||||
check_consistency(value, (LabelTensor, Graph, torch.Tensor))
|
||||
DataConditionInterface.__dict__[key].__set__(self, value)
|
||||
elif key in ('_problem', '_condition_type'):
|
||||
super().__setattr__(key, value)
|
||||
super().__setattr__(key, value)
|
||||
|
||||
@@ -5,6 +5,7 @@ from ..utils import check_consistency
|
||||
from ..domain import DomainInterface
|
||||
from ..equation.equation_interface import EquationInterface
|
||||
|
||||
|
||||
class DomainEquationCondition(ConditionInterface):
|
||||
"""
|
||||
Condition for domain/equation data. This condition must be used every
|
||||
@@ -30,4 +31,4 @@ class DomainEquationCondition(ConditionInterface):
|
||||
check_consistency(value, (EquationInterface))
|
||||
DomainEquationCondition.__dict__[key].__set__(self, value)
|
||||
elif key in ('_problem', '_condition_type'):
|
||||
super().__setattr__(key, value)
|
||||
super().__setattr__(key, value)
|
||||
|
||||
@@ -6,6 +6,7 @@ from ..graph import Graph
|
||||
from ..utils import check_consistency
|
||||
from ..equation.equation_interface import EquationInterface
|
||||
|
||||
|
||||
class InputPointsEquationCondition(ConditionInterface):
|
||||
"""
|
||||
Condition for input_points/equation data. This condition must be used every
|
||||
@@ -25,10 +26,12 @@ class InputPointsEquationCondition(ConditionInterface):
|
||||
|
||||
def __setattr__(self, key, value):
|
||||
if key == 'input_points':
|
||||
check_consistency(value, (LabelTensor)) # for now only labeltensors, we need labels for the operators!
|
||||
check_consistency(
|
||||
value, (LabelTensor)
|
||||
) # for now only labeltensors, we need labels for the operators!
|
||||
InputPointsEquationCondition.__dict__[key].__set__(self, value)
|
||||
elif key == 'equation':
|
||||
check_consistency(value, (EquationInterface))
|
||||
InputPointsEquationCondition.__dict__[key].__set__(self, value)
|
||||
elif key in ('_problem', '_condition_type'):
|
||||
super().__setattr__(key, value)
|
||||
super().__setattr__(key, value)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import torch
|
||||
|
||||
from .condition_interface import ConditionInterface
|
||||
@@ -6,6 +5,7 @@ from ..label_tensor import LabelTensor
|
||||
from ..graph import Graph
|
||||
from ..utils import check_consistency
|
||||
|
||||
|
||||
class InputOutputPointsCondition(ConditionInterface):
|
||||
"""
|
||||
Condition for domain/equation data. This condition must be used every
|
||||
|
||||
Reference in New Issue
Block a user