Skip to content

refactor(estate): decouple constraint energy and TDDFT matrix inputs - #8376

Open
Critsium-xy wants to merge 4 commits into
deepmodeling:developfrom
Critsium-xy:codex/estate-energy-matrix-decoupling
Open

Critsium-xy wants to merge 4 commits into
deepmodeling:developfrom
Critsium-xy:codex/estate-energy-matrix-decoupling

Conversation

@Critsium-xy

@Critsium-xy Critsium-xy commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What's changed?

Estate no longer obtains spin-constraint energy through PW/LCAO virtual callbacks or asks a Hamiltonian/controller to prepare TDDFT energy-density matrices.

  • Compute DeltaSpin energy in its existing owner and deliver the scalar from PW, LCAO and SDFT orchestration before common energy convergence/mixing. Preserve Double-XC's base-state contribution and the direct RDMFT energy path. Store the result in the existing f_en.escon field; no duplicate state or new workflow flags.
  • Construct the EDM identity Tensor in its implementation with existing CPU/GPU memory kernels. Remove the unused generic helper from propagator.h.
  • Let EDM consume H/S matrix views, DMK and a Parallel_Blkcyclic layout for one k point. Keep updateHk, matrix retrieval and the k-point loop in the existing TDDFT endpoint workflow. Reuse the landed Base matrix/ScaLAPACK interfaces, without depending on unmerged feat(base): add self-contained Matrix2d storage and math #8317.
  • Remove the LCAO gather wrapper from EDM; use vector-owned scratch data and the same BLACS (0,0) dense descriptor. Preserve the serial/ScaLAPACK/Tensor formulas, ordinary transpose operations, global dimensions, host/device transfers and accepted/restart endpoint conditions.

Direct production include counts at base 503be43f4b36bc74fa607d4abe23431486f7c29b versus this branch:

Dependency Before After
Estate → LCAO 5 1
Estate → Hamilt 33 32
Estate → PW 10 10

The remaining Estate → LCAO include is rho_tau_lcao.h; density construction and broader Gint/Potential ownership are outside this PR. Psi, IO and the agreed version.h placement are unchanged.

Linked Issue

No separate issue: this is the next scoped step of the module-decoupling work following merged #8333.

Unit Tests and/or Case Tests for my changes

  • Extend MODULE_ESTATE_elecstate_energy to check nonzero constraint energy in Harris/KS totals, replacement on the next state, and disabling the contribution.
  • Add MODULE_ESTATE_edm_tddft and its four-rank unit-test variant: a four-orbital complex matrix checks the supplied-layout contract, transpose convention, unchanged inputs and both ScaLAPACK and CPU Tensor/LAPACK paths. These are unit tests, not new integration drivers.
  • Existing Autotest cases cover PW/NAO scf_deltaspin2/scf_deltaspin4 and TDDFT MD/restart endpoints. 07_NO_EDM_TDDFT uses td_edm=1 and is not claimed as coverage of this EDM branch.

Commands run locally:

  • git diff --cached --check after each step, and git diff --check upstream/develop...HEAD: passed.
  • python tools/03_code_analysis/agent_governance_check.py --staged after each step and python tools/03_code_analysis/agent_governance_check.py --base upstream/develop --head HEAD --format text: no blocking findings; warning rationales below.
  • python tools/03_code_analysis/code_quality_score.py <changed .cpp/.h files>: report generated, 13/19 files at or above 60; all six files below 60 were also below 60 at the base revision (12/18 passing). New EDM unit test scores 92, EDM implementations 95/99.
  • Static direct-include scan of both fixed revisions and repository-wide caller/removed-symbol searches: counts above; removed getter/helper have no callers.

No local builds, unit tests, integration runs or GPU tests were run. The user explicitly requested static implementation and submission followed by CI, because the remote test machine is unavailable. WSL was not installed. The initial head passed the full build matrix (including CUDA, non-MPI, non-LCAO and Makefile), Pyabacus, ASE and pre-commit. Its CUDA runtime check stopped at the shared upstream scf_out_wf failure, while the CPU test run was still in progress. The branch now includes the upstream fix; the new head requires fresh CI results.

Independent static review accepted the original implementation. Independent static integration review also accepted merge commit ac3b1f5d486510f308c4c0124f2b128d589e79e0 with no confirmed integration defects. Nonblocking limitation: GPU handles now initialize/destroy per k-point call; setup overhead has not been measured.

Governance Notes

  • INPUT/docs changes: none; this refactors internal interfaces and ownership without intended user-visible numerical or INPUT changes. No documentation update required; the matrix-data and energy-delivery contracts are documented at their interfaces.
  • Core module impact: Estate, its ESolver producers, the RDMFT energy caller, and an unused RT header helper. No source files were moved or split. Existing product build lists remain valid; new unit-test sources are registered in the module's unittests/CMakeLists.txt.
  • Header warnings: the EDM interface now explicitly includes the three Base headers declaring the matrix view, output matrix and layout it accepts. No high-level forward declarations replace dependencies.
  • Global dependency budget: net zero. RDMFT's existing PARAM.inp.sc_mag_switch read is named once and reused for producing and consuming constraint energy; no new global control is introduced.
  • Exceptions requested: none.

Upstream integration

Merge commit ac3b1f5d486510f308c4c0124f2b128d589e79e0 incorporates upstream/develop at 503be43f4b36bc74fa607d4abe23431486f7c29b, including #8372 and #8326. The merge had no conflicts. git diff --binary confirms the Estate patch against the updated base is byte-for-byte identical to the original patch against its former base. git diff --check upstream/develop...HEAD and the diff-scoped governance check passed without blockers; existing warning rationales above remain applicable. No local builds or runtime tests were run for this merge; normal PR CI verifies the new head.

@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.

No new correctness defect was identified in the constraint-energy handoff or TDDFT EDM refactor at ac3b1f5. Two test coverage suggestions are inline.

Static review only; no builds or runtime tests were run.

TEST(EdmTddft, ComplexMatricesInSuppliedLayout)
{
Parallel_Blkcyclic layout;
const int info = layout.init(4, 4, 1, MPI_COMM_WORLD, false);

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.

Non-blocking: Please add a case using a split or reordered communicator whose BLACS (0,0) is not world rank 0. The direct and four-rank runs both initialize MPI_COMM_WORLD here, so they cannot distinguish the supplied-layout root/context logic from world-based selection. Keep the result and input-preservation checks for both kernels.

h[index] = std::complex<double>(real, imag);
if (i == j)
{
s[index] = 2.0;

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.

Non-blocking: Please add a complex positive-definite overlap matrix that does not commute with H, and a non-diagonal DMK, with an independently constructed EDM reference for both kernels. With S=2I, exchanging HS^-1 and S^-1H leaves the test unchanged, so operand-order regressions are not covered.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants