GPLaSDI icon indicating copy to clipboard operation
GPLaSDI copied to clipboard

Incompatibility with up-to-date pytorch and numpy

Open dreamer2368 opened this issue 8 months ago • 1 comments

This issue corresponds to the legacy code. The work-in-progress python package has already applied the fix for this issue. The legacy code currently solves SINDY using the outdated torch/numpy routines at two routines in BurgersEqn1D/utils.py:

  1. find_sindy_coef uses torch.pinverse
  2. solve_sindy uses np.linalg.lstsq

Other examples are not examined, but expected to use the same routines.

For torch>=2.3.0 and numpy>=1.26.4, the internal behaviors of torch.pinverse and numpy.linalg.lstsq have been changed, which make them unstable for our use of sindy loss training. Earlier versions of torch or numpy may have the same issue.

Currently the solution is:

  1. Use torch.linalg.lstsq insteady of torch.pinverse. This is also recommended from pytorch official documentation.
  2. It is not clear numpy.linalg.lstsq is unstable. However, it often returns different results than torch.linalg.lstsq, given the same system. numpy official documentation says that if there are multiple solutions, the solution with minimal norm is chosen, which could be a reason for this inconsistency. For the best of our practice, it is recommended to use the same torch.linalg.lstsq.

dreamer2368 avatar Jun 26 '24 17:06 dreamer2368