Okay, so this works:
q = torch.tensor([2], requires_grad = True, dtype = torch.double)

XR = torch.zeros([2], dtype = torch.double)


XR[0] = 2

XR[1] = q[0]**2

z = torch.sum(XR)
z.backward()
q.grad

tensor([ 4.], dtype=torch.float64)

But this does not:
q = torch.tensor([2], requires_grad = True, dtype = torch.double)

XR = torch.zeros([2], dtype = torch.double)


XR[0] = 2

XR[1] = q[0]**XR[0]

z = torch.sum(XR)
z.backward()
q.grad

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

Obviously, this is a silly toy example, but I am ultimately trying to do numeric integration and it would be nice to find a way to do this. Is it possible, or do I have to use a work around?
Thanks,
DS