Repository navigation
dftd3: add D3(0) zero damping as an optional last token - #1935
Conversation
…tional> <rc> <rc_cn> [zero|bj]`) Two-body D3(0) with its own force kernels (small-box and large-box); the BJ kernels are unchanged. With zero damping the small-box coordination number is summed in double. R0 pair radii and the parameters of 48 functionals are in a new generated header (source: Grimme DFT-D3 parameters as in dftd3-lib, commit 3c99ee981266548a37588abe3a6f5cb56092d51a, lib/core.f90), with the generator in tools/Miscellaneous/for_coding/dftd3_zero_tables. Elements H-Rn (Z <= 86); a functional not available for the chosen damping stops the run. Not available for the nep_charge models. Adds the manual entry, an example, and tests_pytest/test_dftd3_zero.py (simple-dftd3 reference values, all 48 functionals, finite differences, small-box vs large-box, BJ unchanged).
# Conflicts: # doc/gpumd/input_parameters/dftd3.rst
|
Could you explain why a separate double-precision implementation is needed for the coordination number and interpolation weights only in the zero-damping small-box path, while the BJ and large-box paths remain in single precision? Please compare the energy, force, and virial errors against the reference using the existing single-precision implementation and the new double-precision implementation, and report the performance cost. Please also explain the basis for the accuracy thresholds. If the existing implementation provides sufficient accuracy, please reuse it. If double precision is necessary, we can discuss how to support it without duplicating the CN implementation. Local validation results in the PR discussion are sufficient; no additional test files are needed. |
…t (validation results are reported in the PR discussion)
|
Thank you for the review. Short answers first, then the numbers. Why double precision only in the zero-damping small-box path. I added it because, with single precision, the virial of one test structure (graphite, PBE) exceeded the accuracy threshold I had set in my own fork (2e-6 relative to the largest virial component). It is the only quantity where the two versions differ noticeably. I left BJ unchanged on purpose (so that existing results do not change), and I left the large-box path in single precision because making it double precision did not improve the large-box results in my earlier tests (one structure got worse). Single vs double CN for D3(0), small-box path, errors against simple-dftd3 (D3 term alone, all-zero NEP; ratio = single/double):
The largest virial component of graphite is about 4.5 eV, so 1e-5 eV is about 2e-6 relative. For comparison, BJ in Basis of the thresholds. They are not derived from an error model of D3(0). I took them from my fork, where they were set from the errors of the BJ implementation against simple-dftd3: 2e-6 relative for energy and virial (float errors scale with the size of the quantity, about 5–8e-7 of the D3 energy for unmodified BJ) and 1e-5 eV/Å for forces. In absolute terms the zero-damping force errors are 1e-8 to 5e-7 eV/Å, well below that. If you prefer a different criterion, I can apply it. Performance. I could not measure it today because the GPU is occupied by other jobs. The previous measurement (RTX A6000, idle, nsys kernel time per step): the double-precision CN kernel costs 0.109 ms per step at 648 atoms (0.050 → 0.159 ms), about 2.7 % of the D3 time (about 4 ms); large-box systems are not affected because their CN is single precision. I will re-measure on an idle GPU and update this comment. Options. (1) Reuse the existing single-precision CN kernel for zero damping: this removes the duplicated kernel (about 60 lines); the graphite virial error is then 1.0e-5 eV instead of 7.5e-6 eV, everything else is unchanged. (2) Keep double precision, but share the code with BJ by making the CN kernel a template whose single-precision instantiation is the current BJ kernel. I can do either; please tell me which you prefer. Tests. I have removed the test file and its fixtures from the PR (new commit); the validation numbers are in this comment and in the PR description. |
|
Performance numbers for the double-precision CN kernel of the zero-damping small-box path, as promised above. RTX A6000, CUDA 12.3, idle GPU (checked before every batch), NEP89,
So the double-precision CN costs about 2 % of a small-box step; the accuracy difference is the graphite virial discussed above. I am happy to go either way (reuse the single-precision kernel, or keep double precision with a shared template). |
|
The largest difference virial is still reasonable, so I don't think it will cause problem. For simplicity, I prefer keep the single-precision kernel. |
Remove the double-precision coordination-number kernel of the zero-damping small-box path, as requested in the review: both dampings now use find_dftd3_coordination_number_small_box. The BJ kernels are unchanged.
# Conflicts: # src/force/dftd3/dftd3.cu
|
Thank you. I removed the double-precision CN kernel (commit 19c30f6): zero damping now uses the existing single-precision CN kernel of the small-box path, as BJ does. The BJ kernels are untouched. I checked that the energy, forces and virial are identical (within the run-to-run noise of the atomic adds) to the single-precision numbers I reported above on graphite, water and the benzene dimer, and that BJ output is still identical to Two points from the description are still open, if you have a moment: (1) whether the table values taken from dftd3-lib ("GPL version 1 or later", numbers only) are acceptable given the planned LGPL move of |
|
Could you confirm that the new D3(0) implementation was independently written for GPUMD, apart from reuse of existing GPUMD code, rather than copied or adapted from another program? This question concerns the implementation code, not the numerical parameters, which are expected to agree across implementations. Please cite the original method and parameter publications. We do not want to introduce external software dependencies or require GPUMD users to cite other DFT-D3 programs. |
|
Yes. The zero-damping code was written for GPUMD, on top of the existing What does come from elsewhere:
For transparency: I used an AI coding assistant (Claude Code) to develop this code, and I reviewed the result. So that users are not asked to cite other programs, the documentation now refers to the method paper only ([Grimme2010]) for the parameters (commit cb5c2e5); the provenance of the numbers stays in the header of the generated file and in the PR description. |
|
Thank you for the clarification. Please make further revision with the following changes:
|
…ing-dependent pair term in an inline helper
…e functional in DFTD3::initialize with PRINT_INPUT_ERROR
…ove the table generation files
|
The revision is pushed (head Validation (RTX A6000, CUDA 12.3.103, g++ 11.4.0; reference =
At 648 atoms, 1 000 steps take 6.721 s ( The numerical checks above come from a local test file that is not part of the PR. |
|
Could you contact me via email: brucenju@gmail.com |
|
…ble in an anonymous namespace, reduce comments
|
Thank you for the review. All three points are done in the latest commit (
No behavior is changed. I rebuilt (sm_86, CUDA 12.3) and re-ran the D3 tests: the results are the same as before this commit. Regarding your request to contact you by email: I will send you an email separately. |
Summary
Adds D3(0) zero damping to the existing
dftd3keyword:dftd3 <functional> <potential_cutoff> <coordination_number_cutoff> [zero|bj]Without the last token the behaviour is unchanged (
bj).Two-body terms only (no ATM three-body term), as for BJ.
As agreed in #1915 this PR contains only the D3(0) part.
Motivation: reference data computed with zero damping (for example Quantum ESPRESSO with
vdw_corr = 'dft-d3',dftd3_version = 3) need the same dispersion function to be subtracted before training and added at run time.Changes
src/force/dftd3/dftd3.cu,dftd3.cuh: the small-box and the large-box force kernels are templates on the damping (template <bool zero_damping>); the damping-dependent pair term is an inline helper (d3_pair), with the BJ expressions unchanged andd3_zero_pair()for zero damping. The neighbour traversal, C6 interpolation, force/virial accumulation and the coordination-number kernels are shared. The specialization is selected at kernel launch.src/force/dftd3/dftd3zero_table.cuh(new): R0 pair radii and the parameters s6, sr6, s8, sr8 of 48 functionals.src/force/nep/nep.cu: optional fifth token (bjorzero);DFTD3::initialize()validates the damping and the functional and reports errors withPRINT_INPUT_ERROR.nep_chargeis unchanged (BJ only).doc/gpumd/input_parameters/dftd3.rst.Validation
RTX A6000 (sm_86), CUDA 12.3.103, g++ 11.4.0. The reference build is
master(63fab11), the revised build is this branch; both were built with the same flags (once with-DDEBUGfor the regression, once as release for the other checks). Both build without new warnings.tests_regression--suite full,-DDEBUGbuilds of both: 254 passed, 1 failed, relations 25/25. The failing case isqnep_pppm_future_bec(a qNEP PPPM case without D3; onethermo.outfield differs by 6e-11 relative; the same case also fails occasionally whenmasteris compared with itself).master(energy, forces, virial; all-zero NEP on five structures and NEP89 on two). The BJ kernels use the same registers and stack as before.dftd3 pbe 12 6, sum of the D3 kernels per step, idle GPU, median of 3 alternated runs):masterBJ (ms)At 648 atoms the whole step takes 6.721 s per 1 000 steps with
masterBJ, 6.722 s with this PR's BJ and 6.985 s with zero damping.Limitations
nep_chargemodels.