Repository navigation
test(pw): add a DeltaSpin onsite stress oracle test - #8137
Merged
mohanchen merged 1 commit intoOct 13, 2026
Merged
Conversation
deepmodeling#8122 shipped a finite-difference check of the DeltaSpin force kernel against physically built Pauli moments; the stress side got no equivalent, so the sign correction in deepmodeling#8125 and the ROCm sync in deepmodeling#8133 have nothing that would fail if they were reverted. test_stress_op.cpp differentiates lambda . M from the spinor and compares, for each Pauli channel and for the collinear projector. Registered as deltaspin_stress_cpu_test beside the force target.
mohanchen
approved these changes
Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reminder
AGENTS.mdanddocs/developers_guide/agent_governance.md.source/changes.Linked Issue
Follow-up to #8133 and to
#8125; no new issue is opened for this test gap, and this PR does not change any production code.What's changed?
#8122fixed the DeltaSpin Pauli-y signs in the PW onsite force kernels and shipped an independent oracle for them (kernels/test/test_force_op.cppdifferentiates physical Pauli moments by hand and compares against the kernel). The stress side never got the same treatment:kernels/test/stress_op_test.cppcontains no reference tolambdaat all, so the sign correction in#8125, and by extension the ROCm sync in #8133, has no test that would fail if it were reverted.This PR adds the missing twin:
source/source_pw/module_pwdft/kernels/test/test_stress_op.cpp(new)source/source_pw/module_pwdft/kernels/test/CMakeLists.txt: registerdeltaspin_stress_cpu_test, next to the existingdeltaspin_force_cpu_testso it inherits the same feature-define contextThe fixture drives
hamilt::cal_stress_nl_op<double, DEVICE_CPU>in its DeltaSpin form over both spinor projectors and one collinear projector, for each of the three Pauli channels, and compares against-1/2 d/d eps [ sum_ib w * lambda . M(b + eps*db) ], whereM = b^dagger sigma bis built in the test from the Pauli matrices without borrowing any indexing from the kernel. Starting the output at0.125also pins that the kernel accumulates rather than overwrites.User-visible behavior
None. Test-only change; no INPUT parameter, no documented behavior, so no documentation update required.
Verification
Compiled and executed locally with the repository's own source files. No ABACUS build was configured, so this did not go through CTest; the exact commands:
-Wall -Wextraon the new file produces no warning of its own (only two pre-existing-Wunused-variablenotes fromsource_base/module_device/memory_op.h)./tmp/dsbuild/gt_inc/gtest/gtest.his a ~100-line stand-in for gtest, written only because this machine has no GTest installed; it implementsTEST,EXPECT_NEAR,EXPECT_EQand the failure counter, and it is not part of the PR. CI runs the real gtest through the CMake target.The test was checked against four mutants of
stress_op.cpp, each a one-expression change in the DeltaSpin branch, and each fails exactly the channel it corrupts:coefficients1/2reverted to the pre-#8125signs (what ROCm had until #8133)npol=2 axis=1onlycoefficients1/2real parts negatednpol=2 axis=0onlycoefficients0/3(lambda_zdiagonal) negatednpol=2 axis=2onlylocal_stress -= ...flipped to+=Reproduce a mutant by copying
stress_op.cpp, applying the sign change, and rerunning the compile above with the copy in place of the original.Unit Tests and/or Case Tests for my changes
python3 tools/03_code_analysis/agent_governance_check.py --base <pre> --head <post> --event-path <this body> --format text->Agent governance check: no findings., andpython3 tools/03_code_analysis/code_quality_score.py source/source_pw/module_pwdft/kernels/test/test_stress_op.cpp->1 files scanned, 1 passing(threshold 60).lambda . Mfor all three channels, in both spinor and collinear form, and the test demonstrably fails on each of the four injected errors.AddTest(... ../cuda/stress_op.cu)cannot be compiled on this machine (nonvcc) and I would rather not commit a second target whose numbers I have not seen. The force test's GPU half is the template to follow for that, and it is the change that would also be needed before a ROCm runner exists.Governance Notes
source/production code. The only non-test edit is the CMake registration, which is required for the new file to be built (AGENTS.md: source additions must be wired through the relevantCMakeLists.txt).Two limits of this test, stated plainly
cal_stress_nl_op(DFT+U, collinear, DeltaSpin) usefac = d_wgwithout the explicit2.0 * tpibathe force kernel uses, so the kernel returns-1/2 dE/d(eps)for the strain component itsdbecpwas built from. The test compares against that same convention, which means it pins the signs and the channel structure -- the thing that was actually broken -- and would not notice a normalization error shared by all three branches. Nothing intests/17_DS_DFTUcurrently exercisestest_stresseither, so there is no external anchor to pin the normalization against yet.double. The DeltaSpin stress overload is declaredconst double* lambdainstress_op.h:141andstress_op.h:359but definedconst FPTYPE* lambdainstress_op.cpp:345, while the force equivalent usesFPTYPEin both.cal_stress_nl_op<float, DEVICE_CPU>is explicitly instantiated (stress_op.cpp:759), yet no caller can reach its DeltaSpin overload through the header:and the same call with
doublecompiles. The CUDA and ROCm copies also useconst double*, soFPTYPEin the CPU definition is the odd one out; aligning the five sites is a separate, mechanical change and I left it out of a test PR.