CCQC / Quax

Arbitrary-order derivatives of popular electronic structure methods, such as Hartree-Fock and coupled cluster theory.
BSD 3-Clause "New" or "Revised" License
62 stars 10 forks source link

3-rd and higher derivatives not yet generalized #2

Closed binghuang2018 closed 3 years ago

binghuang2018 commented 3 years ago

While running Quax, I encountered the following error:

python: /opt/gnu/libint/2.7.0-beta.6-ninja-lmax2-deriv4/include/libint2/./engine.impl.h:1964: const target_ptr_vec& libint2::Engine::compute2(const libint2::Shell&, const libint2::Shell&, const libint2::Shell&, const libint2::Shell&, const libint2::ShellPair*, const libint2::ShellPair*) [with libint2::Operator oper = libint2::Operator::coulomb; libint2::BraKet braket = libint2::BraKet::xx_xx; long unsigned int deriv_order = 3; libint2::Engine::target_ptr_vec = std::vector<const double*, libint2::detail::ext_stack_allocator<const double*, 1365> >]: Assertion `false && "3-rd and higher derivatives not yet generalized"' failed.
forrtl: error (76): Abort trap signal
Image              PC                Routine            Line        Source
libgdma.so         00007F2EAACA810F  for__signal_handl     Unknown  Unknown
libpthread-2.31.s  00007F2EAFE0B3C0  Unknown               Unknown  Unknown
libc-2.31.so       00007F2EAFAE318B  gsignal               Unknown  Unknown
libc-2.31.so       00007F2EAFAC2859  abort                 Unknown  Unknown
libc-2.31.so       00007F2EAFAC2729  Unknown               Unknown  Unknown
libc-2.31.so       00007F2EAFAD3F36  Unknown               Unknown  Unknown
libint_interface.  00007F2AE0BFB9EB  _ZN7libint26Engin     Unknown  Unknown
libint_interface.  00007F2AE098EAF5  Unknown               Unknown  Unknown
libint_interface.  00007F2AE09C6B02  Unknown               Unknown  Unknown
libint_interface.  00007F2AE09C394E  Unknown               Unknown  Unknown
python             000055B601D85427  _PyMethodDef_RawF     Unknown  Unknown
python3.7          000055B601D86AD8  Unknown               Unknown  Unknown
python             000055B601DB174A  _PyEval_EvalFrame     Unknown  Unknown
python             000055B601CF5EAD  _PyFunction_FastC     Unknown  Unknown
python3.7          000055B601D5D8AC  Unknown               Unknown  Unknown
python             000055B601D8575C  _PyObject_FastCal     Unknown  Unknown
python3.7          000055B601D86B59  Unknown               Unknown  Unknown
.....

I followed exactly your Quax github page for installation of libint2 (and related conda packages). The setting --enable-1body=4 --enable-eri=4 did export deriv4 related source files. So the problem must be related to the compilation of libint2. Any idea how this happen?

PS: Just fyi, here is the content of my Quax input file

import quax
import psi4
import numpy as np
molecule = psi4.geometry("""
0 1
O   -0.000007070942     0.125146536460     0.000000000000
H   -1.424097055410    -0.993053750648     0.000000000000
H    1.424209276385    -0.993112599269     0.000000000000
units bohr
""")
basis_name = 'sto-3g'
psi4.set_options({'basis': basis_name,
                  'scf_type': 'pk',
                  'mp2_type':'conv',
                  'e_convergence': 1e-10,
                  'd_convergence':1e-10,
                  'puream': 0,
                  'points':5,
                  'fd_project':False})
options = {'damping':True, 'spectral_shift':False, 'integral_algo': 'libint_core'}
quax_deriv = np.asarray(quax.core.derivative(molecule, basis_name, 'mp2', deriv_order=4, options=options))
binghuang2018 commented 3 years ago

Here is the solution by @adabbott (copied from my Email)

Thanks for trying out Quax. Sorry you are having difficulties, it is largely experimental, and I have since graduated and do not have much time to work on improving it. You did nothing wrong, but it looks like from: Assertion `false && "3-rd and higher derivatives not yet generalized" ​ your version of Libint does not have the new Engine API, and this is partly my fault since the PR that fixes it is not yet merged. Let me explain:

Even if you compile Libint with support for higher order derivatives, Libint's "Engine" API in the current version can only compute up to 2nd order. I have a PR (https://github.com/evaleev/libint/pull/200) opened that fixes this but it is currently dormant. I will ask Ed to see what we need to do to get that merged soon. This will only fix higher order derivatives for overlap, kinetic, and electron repulsion integrals. Nuclear-electron attraction integrals are another story... I am not sure if Libint will ever support beyond 2nd order. I have had to use Quax's native integrals code for the nuclear-electron attraction integral derivatives, and Quax works around (https://github.com/CCQC/Quax/blob/5d41cd1749fbe35e0fdf69bb45fb74263ead42db/quax/methods/ints.py#L69) this even if you are using Libint, although it is a bit awkward.

Please verify that the code you sent me works when you change "deriv_order=4" to "deriv_order=2". If that works, then the following fix might help: For two-electron integral derivatives, I think you can get it working with minimal effort by copying this altered engine.impl.h file in my Libint PR (https://github.com/evaleev/libint/pull/200/commits/22dac951f0a2558ad46f80598e34327852b603d8) and replacing the engine.impl.h file in your Libint installation with that one. This will add support for 3rd and 4th derivatives of two-electron integrals. Finally, change 'integral_algo': 'libint_core' to 'integral_algo': 'libint_disk', to deal with Libint being unable to compute nuclear-electron attraction integral derivatives (it will use Libint for TEI's and Quax for OEI's, pack them up into disk-based arrays, and then read them). Ideally, this clunky logic would be fixed, but its hard when you depend on an external library that doesn't have all the features we need.

Hope this helps,

Adam

binghuang2018 commented 3 years ago

Hi, @adabbott, I tried the altered engine.impl.h file, but end up with a different error:

python: /opt/gnu/libint/2.7.0-beta.6-ninja-lmax2-deriv4/include/libint2/./engine.impl.h:469: const target_ptr_vec& libint2::Engine::compute1(const libint2::Shell&, const libint2::Shell&): Assertion `deriv_order_ <= 2 && "feature not implemented"' failed.
forrtl: error (76): Abort trap signal
Image              PC                Routine            Line        Source             
libgdma.so         00007FC0140CF10F  for__signal_handl     Unknown  Unknown
libpthread-2.31.s  00007FC01908D3C0  Unknown               Unknown  Unknown
libc-2.31.so       00007FC018D6518B  gsignal               Unknown  Unknown
libc-2.31.so       00007FC018D44859  abort                 Unknown  Unknown
libc-2.31.so       00007FC018D44729  Unknown               Unknown  Unknown
libc-2.31.so       00007FC018D55F36  Unknown               Unknown  Unknown
libint_interface.  00007FBC8A50227A  _ZN7libint26Engin     Unknown  Unknown
libint_interface.  00007FBC8A4C1010  Unknown               Unknown  Unknown
libint_interface.  00007FBC8A4FE4FF  Unknown               Unknown  Unknown
libint_interface.  00007FBC8A4F913E  Unknown               Unknown  Unknown
python             00005615C028B427  _PyMethodDef_RawF     Unknown  Unknown
python3.7          00005615C028CAD8  Unknown               Unknown  Unknown
python             00005615C02B774A  _PyEval_EvalFrame     Unknown  Unknown
python             00005615C01FBEAD  _PyFunction_FastC     Unknown  Unknown
python3.7          00005615C0261F93  Unknown               Unknown  Unknown
python             00005615C01FE08C  PyObject_Call         Unknown  Unknown
python             00005615C02B4AA7  _PyEval_EvalFrame     Unknown  Unknown
python             00005615C0228E94  _PyFunction_FastC     Unknown  Unknown
...

Any idea?

adabbott commented 3 years ago

Issue here was Quax was calling Libint asking for 3rd and higher derivatives of potential integrals, but even with the patch to engine.impl.h, this is not fixed (that only fixes two-electron integral derivatives). For now, under latest commit Quax will use its own integrals for potential integrals whenever deriv order is greater than 2, even if the user requests Libint integrals/integral derivatives.

Updating Quax to latest version should hopefully fix the above error.