Hi Fabian!



 meyro123:

My training samples are points in space and time, i.e. a two-dimensional tensor


I don’t understand what you are saying here.


gradient = torch.autograd.grad(u,
trainingData,
create_graph=True,
allow_unused=True)
dtU = gradient[0][0]?
dxU = gradient[0][1]?


The following example script may answer part of your question:
import torch
torch.__version__

def  f (x, y):
    return x * y

x = torch.Tensor ([2.0])
x.requires_grad = True
y = torch.Tensor ([3.0])
y.requires_grad = True
u = f (x, y)
gradient = torch.autograd.grad (u, (x, y), create_graph=True, allow_unused=True)
gradient[0]
gradient[1]

Here is its output:
>>> import torch
>>> torch.__version__
'1.6.0'
>>>
>>> def  f (x, y):
...     return x * y
...
>>> x = torch.Tensor ([2.0])
>>> x.requires_grad = True
>>> y = torch.Tensor ([3.0])
>>> y.requires_grad = True
>>> u = f (x, y)
>>> gradient = torch.autograd.grad (u, (x, y), create_graph=True, allow_unused=True)
>>> gradient[0]
tensor([3.], grad_fn=<MulBackward0>)
>>> gradient[1]
tensor([2.], grad_fn=<MulBackward0>)

Best.
K. Frank