|
| 1 | +#include <complex> |
| 2 | +#include <functional> |
| 3 | +#include <pybind11/pybind11.h> |
| 4 | +#include <pybind11/stl.h> |
| 5 | +#include <pybind11/complex.h> |
| 6 | +#include <pybind11/numpy.h> |
| 7 | + |
| 8 | +#include "module_hsolver/diago_dav_subspace.h" |
| 9 | +#include "module_hsolver/kernels/math_kernel_op.h" |
| 10 | +#include "module_base/module_device/types.h" |
| 11 | + |
| 12 | +#include "./py_diago_dav_subspace.hpp" |
| 13 | + |
| 14 | +namespace py = pybind11; |
| 15 | +using namespace pybind11::literals; |
| 16 | + |
| 17 | +void bind_diago_dav_subspace(py::module& m) |
| 18 | +{ |
| 19 | + py::module hsolver = m.def_submodule("hsolver"); |
| 20 | + |
| 21 | + py::class_<hsolver::diag_comm_info>(hsolver, "diag_comm_info") |
| 22 | + .def(py::init<const int, const int>(), "rank"_a, "nproc"_a) |
| 23 | + .def_readonly("rank", &hsolver::diag_comm_info::rank) |
| 24 | + .def_readonly("nproc", &hsolver::diag_comm_info::nproc); |
| 25 | + |
| 26 | + py::class_<py_hsolver::PyDiagoDavSubspace>(hsolver, "diago_dav_subspace") |
| 27 | + .def(py::init<int, int>(), R"pbdoc( |
| 28 | + Constructor of diago_dav_subspace, a class for diagonalizing |
| 29 | + a linear operator using the Davidson-Subspace Method. |
| 30 | +
|
| 31 | + This class serves as a backend computation class. The interface |
| 32 | + for invoking this class is a function defined in _hsolver.py, |
| 33 | + which uses this class to perform the calculations. |
| 34 | +
|
| 35 | + Parameters |
| 36 | + ---------- |
| 37 | + nbasis : int |
| 38 | + The number of basis functions. |
| 39 | + nband : int |
| 40 | + The number of bands to be calculated. |
| 41 | + )pbdoc", "nbasis"_a, "nband"_a) |
| 42 | + .def("diag", &py_hsolver::PyDiagoDavSubspace::diag, R"pbdoc( |
| 43 | + Diagonalize the linear operator using the Davidson-Subspace Method. |
| 44 | +
|
| 45 | + Parameters |
| 46 | + ---------- |
| 47 | + mm_op : Callable[[NDArray[np.complex128]], NDArray[np.complex128]], |
| 48 | + The operator to be diagonalized, which is a function that takes a matrix as input |
| 49 | + and returns a matrix mv_op(X) = H * X as output. |
| 50 | + precond_vec : np.ndarray |
| 51 | + The preconditioner vector. |
| 52 | + dav_ndim : int |
| 53 | + The number of vectors, which is a multiple of the number of |
| 54 | + eigenvectors to be calculated. |
| 55 | + tol : double |
| 56 | + The tolerance for the convergence. |
| 57 | + max_iter : int |
| 58 | + The maximum number of iterations. |
| 59 | + need_subspace : bool |
| 60 | + Whether to use the subspace function. |
| 61 | + is_occupied : list[bool] |
| 62 | + A list of boolean values indicating whether the band is occupied, |
| 63 | + meaning that the corresponding eigenvalue is to be calculated. |
| 64 | + scf_type : bool |
| 65 | + Whether to use the SCF type, which is used to determine the |
| 66 | + convergence criterion. |
| 67 | + If true, it indicates a self-consistent field (SCF) calculation, |
| 68 | + where the initial precision of eigenvalue calculation can be coarse. |
| 69 | + If false, it indicates a non-self-consistent field (non-SCF) calculation, |
| 70 | + where high precision in eigenvalue calculation is required from the start. |
| 71 | + )pbdoc", |
| 72 | + "mm_op"_a, |
| 73 | + "precond_vec"_a, |
| 74 | + "dav_ndim"_a, |
| 75 | + "tol"_a, |
| 76 | + "max_iter"_a, |
| 77 | + "need_subspace"_a, |
| 78 | + "is_occupied"_a, |
| 79 | + "scf_type"_a, |
| 80 | + "comm_info"_a) |
| 81 | + .def("set_psi", &py_hsolver::PyDiagoDavSubspace::set_psi, R"pbdoc( |
| 82 | + Set the initial guess of the eigenvectors, i.e. the wave functions. |
| 83 | + )pbdoc", "psi_in"_a) |
| 84 | + .def("get_psi", &py_hsolver::PyDiagoDavSubspace::get_psi, R"pbdoc( |
| 85 | + Get the eigenvectors. |
| 86 | + )pbdoc") |
| 87 | + .def("init_eigenvalue", &py_hsolver::PyDiagoDavSubspace::init_eigenvalue, R"pbdoc( |
| 88 | + Initialize the eigenvalues as zero. |
| 89 | + )pbdoc") |
| 90 | + .def("get_eigenvalue", &py_hsolver::PyDiagoDavSubspace::get_eigenvalue, R"pbdoc( |
| 91 | + Get the eigenvalues. |
| 92 | + )pbdoc"); |
| 93 | +} |
0 commit comments