-
Notifications
You must be signed in to change notification settings - Fork 139
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
Feature: Add diago_dav_subspace module to pyabacus #4883
Conversation
This commit adds the `diago_dav_subspace` module to the `pyabacus` package, which is responsible for diagonalizing the Hamiltonian matrix using Davison subspace method. The current Pythonization version targets matrix diagonalization. The original algorithm does not require passing a matrix; instead, it uses a function pointer to pass a linear operator for diagonalization. So the current implementation still needs to wrap std::function<void(T*, T*, const int, const int, const int, const int)> to a Python callable type, which requires further iteration.
…o improve readability and enhance type checking in Python
A good practice -- the first contribution to pyabacus from the external users!🎉 I list the TODOs as follows:
|
The destructor of Diago_DavSubspace was causing a memory issue, preventing the program from running correctly. Lines 72-74 were previously commented out to avoid the issue, but this led to a memory leak. This commit addresses the root cause of the memory issue and ensures proper memory deallocation without causing a crash. - Uncommented lines 72-74 in the destructor. This ensures that all allocated memory is properly deallocated, preventing memory leaks but still unable to run the `pyabacus::hsolver::dav_subspace()`
…s/diago_matrix.py)
…ices Previously, our module could only accept explicit matrices for diagonalization. I have now modified the code to accept operators as parameters for diagonalization, eliminating the need to store the entire matrix explicitly. This allows us to compute eigenvalues for larger Hamiltonians using the sparse matrix storage provided by `SciPy`. The operator is a function pointer that accepts a vector and returns a vector. To diagonalize an operator A, we define a function or lambda function `mv_op` such that `mv_op(x) = Ax`, which can then be used in the diagonalization process. Additionally, I have added a new test case for the Hamiltonian matrix corresponding to H2O. The matrix size is `67024x67024`, which previously could not be stored explicitly due to memory constraints. The updated operator method now supports the computation of eigenvalues for such large matrices. Test cases have been updated to reflect these changes.
…nd potential performance improvement - Replaced manual loop with `std::copy` to copy elements from `psi_in` to `psi` and from `hpsi_ptr` to `hpsi_out`. - This change simplifies the code, enhances readability and may improve performance due to optimized standard library `std::copy` implementations.
…nd rename two variables' name - Modified `hpsi_func` to handle matrix-matrix multiplication instead of vector operations. - This vectorization significantly improved computation speed. - Renamed variables in the Python frontend interface: - `nbasis` to `dim` - `nband` to `num_eigs` - These changes align with the module's design as a pure mathematical interface.
- Updated test cases to ensure absolute error is less than 1e-8. - Added a new test case for random sparse matrices to validate the implementation.
It seems that the PR has sufficient content to be merged. Further updates are welcome. |
This commit adds the
diago_dav_subspace
module to thepyabacus
package, which is responsible for diagonalizing the Hamiltonian matrix using Davison subspace method.Reminder
Linked Issue
#4882