Introduce add_points method in AbstractProblem, removed unused comments in Collector class and add the test for add_points and codacy corrections
This commit is contained in:
committed by
Nicola Demo
parent
004cbc00c0
commit
f578b2ed12
@@ -10,6 +10,7 @@ from pina.equation.equation_factory import FixedValue
|
||||
from pina.operators import laplacian
|
||||
from pina.collector import Collector
|
||||
|
||||
|
||||
# def test_supervised_tensor_collector():
|
||||
# class SupervisedProblem(AbstractProblem):
|
||||
# output_variables = None
|
||||
@@ -37,6 +38,7 @@ def test_pinn_collector():
|
||||
my_laplace = Equation(laplace_equation)
|
||||
in_ = LabelTensor(torch.tensor([[0., 1.]], requires_grad=True), ['x', 'y'])
|
||||
out_ = LabelTensor(torch.tensor([[0.]], requires_grad=True), ['u'])
|
||||
|
||||
class Poisson(SpatialProblem):
|
||||
output_variables = ['u']
|
||||
spatial_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]})
|
||||
@@ -78,7 +80,8 @@ def test_pinn_collector():
|
||||
|
||||
def poisson_sol(self, pts):
|
||||
return -(torch.sin(pts.extract(['x']) * torch.pi) *
|
||||
torch.sin(pts.extract(['y']) * torch.pi)) / (2 * torch.pi**2)
|
||||
torch.sin(pts.extract(['y']) * torch.pi)) / (
|
||||
2 * torch.pi ** 2)
|
||||
|
||||
truth_solution = poisson_sol
|
||||
|
||||
@@ -91,30 +94,34 @@ def test_pinn_collector():
|
||||
collector.store_fixed_data()
|
||||
collector.store_sample_domains()
|
||||
|
||||
for k,v in problem.conditions.items():
|
||||
for k, v in problem.conditions.items():
|
||||
if isinstance(v, InputOutputPointsCondition):
|
||||
assert list(collector.data_collections[k].keys()) == ['input_points', 'output_points']
|
||||
assert list(collector.data_collections[k].keys()) == [
|
||||
'input_points', 'output_points']
|
||||
|
||||
for k,v in problem.conditions.items():
|
||||
for k, v in problem.conditions.items():
|
||||
if isinstance(v, DomainEquationCondition):
|
||||
assert list(collector.data_collections[k].keys()) == ['input_points', 'equation']
|
||||
assert list(collector.data_collections[k].keys()) == [
|
||||
'input_points', 'equation']
|
||||
|
||||
|
||||
def test_supervised_graph_collector():
|
||||
pos = torch.rand((100,3))
|
||||
x = [torch.rand((100,3)) for _ in range(10)]
|
||||
pos = torch.rand((100, 3))
|
||||
x = [torch.rand((100, 3)) for _ in range(10)]
|
||||
graph_list_1 = RadiusGraph(pos=pos, x=x, build_edge_attr=True, r=.4)
|
||||
out_1 = torch.rand((10,100,3))
|
||||
pos = torch.rand((50,3))
|
||||
x = [torch.rand((50,3)) for _ in range(10)]
|
||||
out_1 = torch.rand((10, 100, 3))
|
||||
pos = torch.rand((50, 3))
|
||||
x = [torch.rand((50, 3)) for _ in range(10)]
|
||||
graph_list_2 = RadiusGraph(pos=pos, x=x, build_edge_attr=True, r=.4)
|
||||
out_2 = torch.rand((10,50,3))
|
||||
out_2 = torch.rand((10, 50, 3))
|
||||
|
||||
class SupervisedProblem(AbstractProblem):
|
||||
output_variables = None
|
||||
conditions = {
|
||||
'data1' : Condition(input_points=graph_list_1,
|
||||
output_points=out_1),
|
||||
'data2' : Condition(input_points=graph_list_2,
|
||||
output_points=out_2),
|
||||
'data1': Condition(input_points=graph_list_1,
|
||||
output_points=out_1),
|
||||
'data2': Condition(input_points=graph_list_2,
|
||||
output_points=out_2),
|
||||
}
|
||||
|
||||
problem = SupervisedProblem()
|
||||
|
||||
Reference in New Issue
Block a user