DiffEqML / torchdyn

A PyTorch library entirely dedicated to neural differential equations, implicit models and related numerical methods
https://torchdyn.org
Apache License 2.0
1.4k stars 130 forks source link

AssertionError: each element of save_at [torch.Tensor] must be contained in t_span [torch.Tensor] once and only once, why am I getting this error? #159

Closed bigyaan closed 2 years ago

bigyaan commented 2 years ago

My code was running fine for older version of torchdyn but I get the above error in the newer version. What has changed in this newer version?

joglekara commented 2 years ago

Thanks for your question!

There was a new flag added to the fixed step solver (fixed_odeint) to indicate at which steps you would like to save the solution. The error is telling you that the contents of whatever is being passed in as save_at are not in t_span. So it can't save that timestep and is giving you an error before running, and finding out that it didn't save the timesteps you wanted.

I'd suggest checking whether you are passing in a save_at tensor? If not, should you? If yes, make sure its contents are also in t_span.

bigyaan commented 2 years ago

Hello @joglekara , thank you for your answer. I understand where you are saying but can't seem to find how to fix this problem in my code. https://colab.research.google.com/drive/1DXFkPzOPeqBBmYON3TOtxi9tHwrUmgBs?usp=sharing This is my code could you have a look at it.

joglekara commented 2 years ago

I just took a look at the notebook and saw this error which is different than the assertion error you were getting earlier, so you probably have made some changes since then.

TypeError: trajectory() got an unexpected keyword argument 'save_at'

Unfortunately, I can't access the data in your notebook so I can't fully debug it

I would try not passing in save_at to the trajectory call you have in your LSTM. trajectory should just output every timestep in t_span.

We can debug over slack if you want, it might be a little easier/faster.

bigyaan commented 2 years ago

@joglekara Hello, thanks lot. I am sorry that save at was not supposed to be there. I tried adding it later to fix the bug. The probIem is same as mentioned before. I would be delighted if we could do it over slack. I think I am added to this repos slack. Let's communicate there.

bigyaan commented 2 years ago

@joglekara hey there, I solved this problem. The atol and rtol of isclose was 1e-3 in default. However, my time span value was in 1e5, this made the function to give strange results. I reduced the representation of value to 3 digits and it worked fine. Thank you for your effort.