-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scipy.linalg.eig_banded appears to give unreliable results inside solve_schrodinger_equation #1843
Comments
Update: We realized that my code was incorrect for reconstructing the dense Hamiltonian. We forgot to include the complex conjugate on the upper diags. We could have also gotten arround that by using
|
Previously, in solve_schrodinger_equation, we formatted the Hamiltonian as a banded matrix and obtained eigenvalues from scipy.linalg.eig_banded. However, as documented in #1843 this led to inconsistent results from system to system. Using np.linalg.eigh appears to be more reliable.
Previously, in solve_schrodinger_equation, we formatted the Hamiltonian as a banded matrix and obtained eigenvalues from scipy.linalg.eig_banded. However, as documented in #1843 this led to inconsistent results from system to system. Using np.linalg.eigh appears to be more reliable.
Previously, in solve_schrodinger_equation, we formatted the Hamiltonian as a banded matrix and obtained eigenvalues from scipy.linalg.eig_banded. However, as documented in #1843 this led to inconsistent results from system to system. Using np.linalg.eigh appears to be more reliable.
This issue is being automatically marked as stale because it has not received any interaction in the last 90 days. Please leave a comment if this is still a relevant issue, otherwise it will automatically be closed in 30 days. |
Bug Description
This was discovered in the course of debugging #1682. I am opening this up as a separate issue to refocus our efforts, and because it is possible that this is not the only issue affecting the failing pdep test.
Inside
HinderedRotor.solve_schrodinger_equation
(rmgpy.statmech.torsion.pyx) we construct a complex-valued Hamiltonian matrix banded in lower triangular form (i.e. the full Hamiltonian is a 401x401 matrix, but here we only store the diagonals that are non-zero that appear on and below the main diagonal. Therefore,H
is only 6x401, but represents a full 401x401 Hamiltonian). This banded representation then gets passed toscipy.linalg.eig_banded
, which takes as input a complex-valued Hamiltonian represented in this way and returns the eigenvalues.Here is where the problem occurs. When running two different versions of RMG-Py (see below for more details), the exact same Hamiltonian input into
scipy.linalg.eig_banded
yields completely different eigenvalues, where some of them don't even match to 1 significant figure. As far as we can tell the Hamiltonian in question (which I have attached by outputting as a list to a YAML file) is not poorly conditioned. It is worth noting that this can be hard to reproduce, because it appears to be system dependent. I am seeing this issue based on current master, but others aren't necessarily.What is reproducible though is that the eigenvalues are different if you request
scipy.linalg.eig_banded
to return the eigenvectors as well, which as noted in the documentation for the underlying FORTRAN LAPACK functionchbevd.f
at http://www.netlib.org/lapack/explore-html/d5/db8/chbevd_8f_source.html will cause a different algorithm to be used. It is not surprising that the eigenvalues will be different if a different algorithm is used, but it is surprising if they are so different that they don't even agree to 1 significant digit. The eigenvalues were different when the eigenvectors were requested in both RMG-Py versions, and worse they were still different across the different RMG-Py versions.This is potentially a major bug, because we use these eigenvalues (energies) to calculate the partition function of the hindered rotor, which of course is the most important quantity in all of statmech which we derive everything else from. The resulting partition functions can differ in as much as the second significant digit, so it is important that we figure out what is going on here.
How To Reproduce
Finding different versions of RMG-Py where the output of
scipy.linalg.eig_banded
differs can be difficult to find. It appears to be system dependent, and we really don't have a good understanding of why at this point.Instead, I recommend changing the
eigvals_only
keyword argument from False to True and comparing the output.Expected Behavior
The returned eigenvalues should have more precision than they appear to have
Installation Information
OS (include version if known): Ubuntu 18.04
Installation method: source
RMG-Py version "py3 (nearly current master)" information:
RMG-Py version "py2 (v2.5.0)" information:
Additional Context
On an interesting note, I tried making the following modification to
HinderedRotor.solve_schrodinger_equation
to convert the banded representation to a dense numpy array, and then usenp.linalg.eig
to find the eigenvalues, which I think calls a different LAPACK function.Using the code below, I get different eigenvalues again, but both versions of RMG-Py now agree with each other. The eigenvalues found appear to have repeat entries (they come in pairs of two I think for the most part), which is interesting.I am not sure at all if this is correct (I could have messed up converting to a dense matrix, and it is also possible that the eigenvalues found from the numpy call are also unreliable), but if this is actually the correct result then both RMG-Py codes yield the same rate coefficient in the pdep test, it is just that they are now a factor of 10 smaller than what the test number is.I would be very interested to see what other codes (what does Julia say?) get for the eigenvalues for this problem. What even is the correct answer?
Final note: I had to change the file extension for the hamiltonian, but it is a YAML file
hamiltonian.txt
The text was updated successfully, but these errors were encountered: