mathLab/PINA

`add_points` assigns wrong labels to new data

Closed this issue · 3 comments

Describe the bug
When calling add_points for a problem, if the labels of the new points are not in the same order as the labels of the old points, the new points will be assigned the incorrect labels.

To Reproduce

problem = ParametricPoisson() # Poisson adapted from examples, to be 1D with 1 parameter

problem.discretise_domain(200,'grid',variables=['x'],locations=['D'])
problem.discretise_domain(0,'random',variables=['x','a'],locations=['gamma1'])
problem.discretise_domain(0,'random',variables=['x','a'],locations=['gamma2'])
problem.discretise_domain(1,'random',variables=['a'],locations='D')

mu = problem.input_pts['D'].extract(['a'])[0].squeeze().item()
xl = LabelTensor(torch.tensor([[-1,mu]]),labels = ['x','a'])
xr = LabelTensor(torch.tensor([[1,mu]]),labels = ['x','a'])

# print the x coordinate of point to be added, should be -1
print(xl.extract('x'))

problem.add_points({'gamma1':xl, 'gamma2':xr})
# print the x coordinate of the new point added to the location, should be -1
print(problem.input_pts['gamma1'].extract('x'))
# print the parameter
print(f'{mu=:}')

Expected behavior
print(problem.input_pts['gamma1'].extract('x')) should print '-1'.

Output

labels(['x'])
LabelTensor([[[-1.]]])
labels(['x'])
LabelTensor([[[0.0838]]])
mu=0.08375704288482666

👋🏻 @Gabriele-Codega Thank you for spotting the bug! Indeed this is a very high-priority issue. Let's open a PR with the change and a small test for the future :)

The problem, as you suggested, is indeed in add_points in line 276. Basically, we are using new_points[location] but in line 269 we do a check and create a variable new_pts which has the correct labels order. So I think changing those two will solve the problem. Do you want to work on it?

ndem0 commented

Fixed in #310