Skip to content

fix(rt): correct hybrid gauge RI input and periodic-image phases - #8170

Merged
mohanchen merged 16 commits into
deepmodeling:developfrom
memii-x:codex/upstream-hse-input-phase-20261014
Nov 12, 2026
Merged

mohanchen merged 16 commits into
deepmodeling:developfrom
memii-x:codex/upstream-hse-input-phase-20261014

Conversation

@memii-x

@memii-x memii-x commented Oct 18, 2026 •

Copy link
Copy Markdown

What's changed?

In LCAO RT-TDDFT using hybrid gauge (td_stype=2), RI exact-exchange integrals are evaluated in the ordinary NAO basis, so the input density matrix must be expressed in the same representation.

This PR converts each source density before RI contraction and history mixing:

$$ D^0(\mathbf R) =e^{-i\mathbf A_{\mathrm{source}}\cdot\mathbf R} D^{\mathrm{hybrid\ gauge}}(\mathbf R). $$

Here $D^0$ is the ordinary-NAO density matrix, and $\mathbf A_{\mathrm{source}}$ is the vector potential at the density's source time. $\mathbf R$ is the actual Cartesian translation including the lattice scale lat0, and the vector potential uses the code's Hartree atomic units.

For a later electronic time step, the first iteration uses the left-endpoint density and vector potential; subsequent iterations and post-convergence EXX updates use the right endpoint. Resetting the mixer within a time step does not change the density's source time.

Each density is converted before entering the ordinary-NAO mixing history. The conversion leaves the cached original density unchanged.

Periodic-image phase correction

On a finite k-point mesh, RI must preserve the phase relating different periodic density images.

Write the actual translation as

$$ \mathbf R=\bar{\mathbf R}+\mathbf B, $$

where $\bar{\mathbf R}$ is the stored representative, $\mathbf B$ is a translation of the physical Born–von Karman supercell, and $\mathbf k_0$ is the origin of the regular k-point mesh. The input and image phases are combined in one multiplication:

$$ D^0(\mathbf R) =e^{-i[\mathbf k_0\cdot\mathbf B+ \mathbf A_{\mathrm{source}}\cdot\mathbf R]} D^{\mathrm{hybrid\ gauge}}(\bar{\mathbf R}). $$

The code expands the required actual images before they enter the mixing history. It sets the internal RI index period from the retained C/V integral supports to prevent these images from aliasing during contraction. Actual output translations are restored before EXX is assembled into HR, preserving contributions already written by other operators.

For nspin=2, HamiltLCAO synchronizes its two-spin storage after operator assembly grows HR. Both spin channels are remapped by atom pair and translation, preserving the active channel's newly assembled values and the inactive channel's existing values before spin switching.

The physical k mesh, LibRI dependency and final output-phase formula are unchanged. Image expansion can increase memory use and computational cost.

Scope and compatibility

  • HSE and the direct RI paths used by PBE0/HF (spencer, revised_spencer, limits) use the same input-phase conversion, image expansion and history-mixing treatment.
  • Ewald paths (massidda, carrier) retain their existing image treatment and are outside this extension.
  • The image-expansion path requires complex RI tensors, a full regular k mesh without space-group reconstruction, and kpar=1. Stress calculations on this path are not yet supported.
  • When RT hybrid-functional forces are requested, the unimplemented EXX force contribution is skipped, with a warning that the returned forces lack EXX and RT hybrid-functional forces have not yet been implemented. Ordinary ground-state force and structural-relaxation calculations retain their existing paths.
  • Density conversion, image expansion and mixing remain in module_ri; ESolver only passes the required field state. Ordinary SCF and other gauges retain their existing mixing and image treatment.

Unit Tests and/or Case Tests for my changes

Build and unit tests

The full CPU/MPI/LCAO/LibRI/Libxc executable builds successfully. All four focused CTest targets pass, comprising 38 GTests. The 14-test HContainer suite also passes with AddressSanitizer instrumentation of the container, atom-pair, matrix and test sources.

Coverage includes phase sign and units, source-time selection, plain/Pulay/Broyden mixing and resets, preservation of the original density, comparison against independent Fourier sums on Gamma-centered and shifted meshes, and configuration checks for enabling direct-kernel paths while leaving Ewald paths unchanged.

PBE0 integration test

The Si Gamma-centered 2x1x1 case now uses references that include both input and periodic-image phase corrections.

The preceding image-disabled version passes the original references. With the unified image correction enabled, the updated references pass with both 1 and 4 MPI ranks at unchanged tolerances. The image correction changes the final total energy of this case by approximately +0.01450 eV.

MoS2 physical case

A separate validation build with the input-phase correction completed 14 fs of fixed-ion MoS2 HSE/hybrid-gauge propagation under an applied electric field. All electronic steps converged, and the results were qualitatively consistent with expectations.

In a matched 14–15 fs continuation using isolated validation builds, the image-on/off difference was approximately 2.83 ppm in longitudinal-current relative L2 norm and at most $3.08\times10^{-11}\ \mathrm{C/m^2}$ in continuous polarization.

Spin-storage regression

The new rt_tddft_hse_spin2 integration case exercises HR image growth and spin switching through the production HSE/hybrid-gauge path. It passes with 1 and 4 MPI ranks at the standard tolerances. A two-rank control with the preceding build aborts with heap corruption; the corrected build completes the same input.

Real and complex unit tests cover growth starting from either spin, remapping blocks whose offsets change, repeated growth and switching back to the previously assembled spin. Short nspin=4 tests with zero and tilted initial magnetization (noncollinear, without SOC) complete before and after this fix with identical printed currents and final energies.

Supplementary tests

Short HSE, HF/Spencer and PBE0/revised-Spencer/limits runs completed. Fresh-process HSE/PBE0 restart tests reproduced the existing initialization defect reported separately in #8280.

Follow-up

  • Add a regression through the production adapter that detects swapped left/right endpoint accessors.

Linked Issue

Related restart initialization defect: #8280, tracked separately.

Governance Notes

No INPUT syntax or default values are changed. The exx_real_number description documents the complex-RI requirement for hybrid-gauge exact exchange.

New helper logic remains in RI; ESolver does not implement the low-level calculations. The PR's total number of global-configuration references does not increase. Whitespace and governance checks have no blocking findings, and no governance exception is requested.

@memii-x memii-x changed the title fix(rt): convert sHG density to ordinary NAO frame for RI exchange fix(rt): correct hybrid gauge input density for RI exchange Oct 18, 2026
@mohanchen mohanchen added rt-TDDFT Real-time Time-Dependent DFT Refactor Refactor ABACUS codes labels Oct 18, 2026

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

Reviewed statically at 5477d6c4b16b22604fe33ff7902356fcf02c6cf4: the local phase sign, units and conversion-before-history/source-time logic are consistent with the inspected conventions. No confirmed new implementation defect; the two comments are non-blocking. Pinned governance, whitespace and a static merge check against 27bbd6cfa6ec40ef4c5699b0c46f2e7412b840b7 passed; build/runtime validation was not run and CI diagnostics were unavailable. This review does not establish restart-replay, atom-wrap or complete finite-field cell-stress support.

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

I'll review your PR when you tell me you're ready :) no need to reply to this one

@memii-x memii-x changed the title fix(rt): correct hybrid gauge input density for RI exchange fix(rt): correct hybrid gauge RI input and periodic-image phases Nov 3, 2026

@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 incremental review found a two-spin storage defect and a non-blocking documentation follow-up below. No builds or runtime checks were run; the reported numerical/reference results were not independently verified.

Comment thread tests/08_RI/rt_tddft_hse_spin2/README Resolved
Comment thread tests/08_RI/rt_tddft_pbe0_gamma/README Resolved
@AsTonyshment

AsTonyshment commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Oh, and don't forget to update branch and resolve inline comments (if the issue pointed out in the comment has been resolved, or if you believe that over engineering and does not want to solve it) so that I will know that the PR is ready.

@memii-x

memii-x commented Nov 4, 2026

Copy link
Copy Markdown
Author

@AsTonyshment Updated the branch with develop and resolved your three inline comments.

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

LGTM, @mohanchen please have a look

@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 incremental review of 7c4b5c76; no builds or tests were run.

Non-blocking: Please add or link the exact build, CTest, ASan and MPI commands, plus the tested commit or executable identity, for the spin-storage results.

memii-x commented Nov 6, 2026

Copy link
Copy Markdown
Author

Updated the branch. The generic LCAO solver no longer accesses TD_info for this EXX update; the field is obtained within the EXX interface. I also cleaned up the formatting.

@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 incremental review of 3031383c; no new correctness defect found in the inspected changes. No build or runtime tests were run.

@mohanchen
mohanchen merged commit 52bc797 into deepmodeling:develop Nov 12, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes rt-TDDFT Real-time Time-Dependent DFT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants