Skip to content

Toolchain: Build libxc with KXC support - #8218

Draft
Growl1234 wants to merge 1 commit into
deepmodeling:developfrom
Growl1234:toolchain
Draft

Growl1234 wants to merge 1 commit into
deepmodeling:developfrom
Growl1234:toolchain

Conversation

@Growl1234

Copy link
Copy Markdown
Collaborator

Follow up to #8069. Dropped the manual configuration from CI.

@Growl1234 Growl1234 added the Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS label Oct 25, 2026
@Growl1234

Growl1234 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

I'll take a look at the testing failure tomorrow. nan is weird.

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review of 615ad580a2a0 against 8e2017587f62. No builds or runtime tests were run; CI diagnostics were unavailable. The alternative-version suggestion is nonblocking and concerns an inherited limitation.

run: echo "LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/toolchain/install/libxc-kxc/lib:${LD_LIBRARY_PATH:-}" >> "${GITHUB_ENV}"

- name: Test LR excited-state tracking checker
run: python3 tests/integrate/validation_tools/test_es_check.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Retain tracking-checker regression coverage

Please keep the test_es_check.py invocation when removing the custom LibXC setup. This script is not registered with CTest, so the remaining steps no longer run its negative cases for NaN forces, lost branches, and missing tracking diagnostics. Restoring this step, or registering the script with CTest, preserves that coverage.

-DENABLE_PYTHON=OFF \
-DBUILD_TESTING=OFF .. \
-DBUILD_TESTING=OFF \
-DMAXORDER=3 .. \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Cover the alternative LibXC version in a follow-up

Non-blocking: --package-version libxc:alt selects 7.0.0, whose build ignores MAXORDER and defaults to DISABLE_KXC=ON, so that installation still lacks KXC for LR gradients. This is an inherited limitation; the default 7.1.2 path is covered by this change. A follow-up after merge can use version-appropriate derivative switches or document that KXC currently requires the main version.

@maki49

maki49 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

My local test finds LibXC 7.0.0 pass three isolated LibxcSanitizer tests, including GgaSigmaReverseMatchesTheWeightedEnergy, which fails with 7.1.2 producing NANs. Both the CI input (0.04, -0.20, 0.03) and the physically valid opposing-gradient input (0.04, -0.04, 0.04) produce finite energy and first derivatives in 7.0.0.

The suspected regression is in PBE correlation’s generated evaluation. Commit b5a0dec introduces sqrt(q), where q = sigma_uu + 2*sigma_ud + sigma_dd, together with 1/sqrt(q) in the first-derivative chain; its immediate parent uses q directly. I performed a runtime bisect and this has been confirmed:

LibXC commit Standalone probe: eight inputs ABACUS test GgaSigmaReverseMatchesTheWeightedEnergy
Parent 321b7a9 All outputs finite pass
b5a0dec, “Regenerated sources” Cases 3 and 5 produce NaNs fails

The eight inputs in the standalone test are listed as follows. Sigma components are ordered as (uu, ud, dd). “Finite” means that exc, both vrho components and all three vsigma components are finite.

Case sigma_uu sigma_ud sigma_dd Parent 321b7a9 Commit b5a0dec
0 0.04 0.01 0.03 Finite Finite
1 0.00005 0 0.03 Finite Finite
2 0.04 0.20 0.03 Finite Finite
3 0.04 −0.20 0.03 Finite exc, vrho, vsigma are NaN
4 0.00005 0.20 0.03 Finite Finite
5 0.04 −0.04 0.04 Finite exc and vrho finite; vsigma NaN
6 0.04 −0.034 0.03 Finite Finite
7 0.04 -sqrt(0.04*0.03) ≈ −0.034641016151377546 0.03 Finite Finite

For case 3, internal cross-sigma clipping leaves q = −6.9388939039072284e−18 through floating-point rounding, making the square root invalid. For case 5, q=0 exactly; the energy remains finite, but the derivative chain encounters an unresolved zero-times-infinity limit.
Importantly, case 5 is physically valid: equal and opposite spin-density gradients give zero total gradient.

The probe calls xc_gga_exc_vxc() for XC_GGA_C_PBE (ID 130), with:

xc_func_init(&func, XC_GGA_C_PBE, XC_POLARIZED);
xc_func_set_dens_threshold(&func, 1e-6);
xc_func_set_sigma_threshold(&func, 1e-2);

double rho[2] = {0.4, 0.2};

The similar issue has been reported in https://gitlab.com/libxc/libxc/-/work_items/639 and fixed in its devel branch. 7.1.0-7.1.2 all includes this regression. We can use 7.0.0 by default or wait for the upcoming 7.2.0 release.

@Growl1234

Growl1234 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks for the reminder! Then we can wait for the 7.2.0 update. Version 7.0.0 takes much more time building with KXC.

@Growl1234
Growl1234 marked this pull request as draft October 26, 2026 05:19
@AsTonyshment

Copy link
Copy Markdown
Collaborator

I encountered exactly the same NaN issue with Libxc v7.1.2 a while ago, and discovered that the $\frac{1}{\sqrt{q}}$ issue had already been fixed in MR #839 just as I was about to open an issue in the Libxc repository. They were pretty quick to fix this one, considering that a previous issue I reported took about two years to get resolved😅

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants