I am trying to add two tensors and save the result into a third tensor that I update every loop. Adding tensors seems hit or miss, as the velocity calculation works no problem and updates but for some reason my position does not change at all and refuses to update. For context, this snippet is a part of a function inside a class, but the variables y_0 and y_1. dy_0 and dy_1 are local variables defined at the top of this function. The output of self.eval_func.evaluate(*self.eval_func.tRP_tensor)).data does give me the proper tensor so this is not the issue.
Here is the relevant snippet:
for i, itt in enumerate(range(self.sim_time)):
# if t is needed, it is calculated here
cur_real_time = self.start_val + itt * self.dt
# Calclate velocity from force
temp1 = torch.mul(self.dt, self.eval_func.evaluate(*self.eval_func.tRP_tensor)).data
# print(temp.data, dy_0.data)
dy_1.data = dy_0.data + temp1.data # noqa
# calculate new position from velocity
temp2 = torch.mul(self.dt, dy_1.data).data
y_1.data = y_0.data + temp2.data
print(y_0.data, temp2.data, y_1.data)
# update variables this iterations initial and final values
# for the next iteration
y_0.data = y_1.data
dy_0.data = dy_1.data
self.update_args(cur_real_time, y_1, dy_1)
if cur_real_time - last_output_time >= self.output_step:
# this block is option status output with ETA if check_val
# is passed as True to the functuion
if check_val:
ratio = i / self.sim_time
cur_time = datetime.now() - start
ETA = cur_time.seconds / ratio
print('\rCurrently {:.2f}%. Running for {} seconds : E.T.A {:.2f} Seconds. T - done = {:.2f}'.format(100 * ratio, cur_time, ETA, ETA - cur_time.seconds), end='') # noqa
# put the final result for this iteration in the output
out_list.append(y_1.tolist()[0])
last_output_time = cur_real_time
print('\rCompleted in {}!'.format(datetime.now()-start))
print(out_list)
return np.array(out_list)
In this code, y_1 (and y_0) refuses to update with the value of y_1 = y_0 + dt * dy_1. I have this issue sometimes with dy_0 in another function and believe it to the be same issue in a Runge Kutta 4 function but have no idea why it is happening.
The temp1 and temp2 variables exist for debugging purposes so I could see what was actually being assigned when I preformed operations. It has the same behavior if I substitute the definition of temp1 and temp2 into the code and remove the variables.
Thank you very much.