Skip to content

Fix LR-TDDFT optical velocity for hybrid functionals - #8368

Open
maki49 wants to merge 8 commits into
deepmodeling:developfrom
maki49:lr-optical-commutator
Open

maki49 wants to merge 8 commits into
deepmodeling:developfrom
maki49:lr-optical-commutator

Conversation

@maki49

@maki49 maki49 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  • Reuse the existing RT-TDDFT AO velocity and position-integral code to include the Fock commutator in LR-TDDFT absorption. Supported LCAO LR with ground-state exact exchange defaults to abs_gauge velocity_commutator. It uses in-memory H(R)/S(R) in ks-lr and text CSR from out_hsr 1 in standalone lr. The INPUT docs recommend direct velocity for local and semilocal functionals.
  • Write LR excitation energies with 17 significant digits. Add the standard metadata header to the text spectrum absorption.dat.

Si SRCH

With identical LR-TDA settings and 0.10 eV Lorentzian HWHM, the 3–6 eV integral of Im εzz rises from 38.81 to 55.31. The digitized RT-TDDFT reference is 59.61. The LR peaks remain about 0.18 and 0.37 eV above the reference. Ji et al., Fig. 4(a)

Si SRCH absorption before and after the optical velocity fix, compared with Ji et al.

Verification

  • cmake --build /tmp/abacus-lr-optical-build -j 12 --target abacus_std_para MODULE_IO_input_test_para and ctest --test-dir /tmp/abacus-lr-optical-build -R '^(MODULE_IO_input_test_para_4|lr_energy_collector|08_RI_lr_absorption_workflow)$' passed, including HSE spectra from in-memory and CSR matrix inputs with one and two spin channels.
  • bash ../integrate/Autotest.sh -a /tmp/abacus-lr-optical-build/abacus_std_para_kxc -n 4 -o 1 -j 2 -r '^(lr_tddft_.*|bse_lr_multik|rt_tddft_hse_current_spin2_up)$' passed all nine selected cases with KXC-enabled LibXC.
  • Two-rank HSE H₂ output checks (mpirun -np 2 abacus_std_para) matched the 17-digit saved energies to the solver and report. The BeH₂ two-step relaxation wrote # Ionic_Step 2.

Governance notes

No linked issue. The Si spectrum above provides the reproduction. ESolver supplies the AO matrices and HSolver changes energy formatting only. The remaining PARAM read belongs to the existing direct velocity setup. The added includes declare interface types and the standard double-precision digit count. No exception requested.

Reuse the real-time AO velocity, position integrals and LR transition projection. Read H(R) and S(R) from text CSR for standalone LR and use the in-memory KS blocks for ks-lr.

Cover the opt-in gauge with a multik Si absorption regression and check the fixed-orbital SRCH result against an independent Fourier reconstruction.

(cherry picked from commit caed480)
Default to eight significant digits in LR energy output and accept values
up to 17. Keep 0 as the legacy-format opt-in. Apply the setting to solver
output, energy reports, optical energy columns, and saved excitation
energies. Refresh the HF Gamma energy references affected by the extra
printed digits.

Write optional LR state files outside assertions so Release builds honor
out_wfc_lr.

(cherry picked from commit bbc5d22)
Copilot AI balanced review requested due to automatic review settings November 23, 2026 04:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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

The new absorption regression can accept incomplete or NaN output; require a complete finite spectrum before treating the check as passed. Static source review at d040f1eb; no builds or runtime tests were run.

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

The previous three findings are addressed in the source at 024b3fc5a. Two non-blocking regression-test suggestions remain below. This was a static incremental review; I did not rerun the reported tests.

output_rows = read_spectrum(output)
for line, (expected, actual) in enumerate(zip(reference_rows, output_rows), start=2):
for column, (expected_value, actual_value) in enumerate(zip(expected, actual), start=1):
if abs(expected_value - actual_value) > tolerance:

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: the new spectrum has 89 of its 100 intensities below 1e-4, so this comparator would accept all 89 being replaced by zero. Could the intensity column use a relative tolerance with a smaller absolute floor, while keeping separate tolerances for the grid columns, and include a small-amplitude regression case?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 15f7092. Frequency and wavelength each retain an absolute tolerance of 1e-4 in their own units. Absorption now uses a 1e-4 relative tolerance with a 1e-8 absolute floor. The collector test accepts a small perturbation around 2.5e-6 and rejects setting it to zero. I also zeroed the 89 weak intensities in the HSE reference and verified that the comparison fails.

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.

Addressed in 15f7092f7: absorption now uses a relative tolerance with a 1e-8 floor, while both grid columns retain 1e-4 absolute tolerance. The added cases distinguish a small weak-intensity perturbation from zeroed output and check both grid columns. Verified in source only; I did not run the tests.

basis_type lcao
gamma_only 0
symmetry -1
nspin 1

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: could a small nspin=2 LR commutator case be retained alongside this HSE spin-one case? The replacement removes the previous two-spin LR projection coverage, and all new CSR runs are spin-one, leaving the hrs2_nao.csr path untested. The RT spin-two case covers the shared AO helper, but not those LR consumers.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 15f7092. The original spin-one HSE test is retained and a separate 08_RI_lr_absorption_csr_spin2 CTest runs the same HSE H2 system with nspin=2. It verifies the separate reads of hrs1_nao.csr and hrs2_nao.csr, compares the in-memory and standalone spectra, and checks the same closed-shell reference and the direct-velocity control. Both tests passed with four MPI ranks on the merged branch.

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.

Addressed in source in 15f7092f7: the separate nspin=2 workflow checks both CSR file reads and compares the in-memory, standalone and reference spectra, alongside the direct-velocity control. This is closed-shell coverage; unequal spin blocks remain outside this fixture.

# Conflicts:
#	source/source_hamilt/module_hcontainer/read_hcontainer.cpp
#	source/source_hamilt/module_xc/exx_info.cpp
@maki49 maki49 closed this Nov 23, 2026
@maki49 maki49 reopened this Nov 23, 2026
@maki49 maki49 closed this Nov 23, 2026
@maki49 maki49 reopened this Nov 23, 2026
@mohanchen mohanchen added EXX/lr-TDDFT/RPA/BSE/GW Related to beyond DFT methods Refactor Refactor ABACUS codes labels Nov 24, 2026
const double *const energies = &this->tda_ene[is * this->nstates];
const std::string channel = this->inp_->bse_spin_types[is] + "_tda";
LR_Util::print_excitation_energies(this->ofs_running_, energies, this->nstates, channel);
LR_Util::print_excitation_energies(this->ofs_running_, energies, this->nstates, channel, 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.

name the variable first, for example x=0, and put x in the function, so readers can know what '0' means from the name of x

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in 21d9485. BSE now passes the named legacy_energy_precision value and retains its existing output format.

this->add_item(item);
}
{
Input_Item item("lr_energy_precision");

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 would suggest you fix 17 numbers and then remove the input parameter

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in 21d9485. LR excitation energies now use 17 significant digits. I removed the INPUT parameter and its dedicated tests.

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 would suggest adding the head lines like this (with # as first label):

ABACUS version: v3.11.0-beta13
Written at 2026-11-20 14:53:46
Ionic_Step 5
768 # number of points

you can find examples by asking AI agent

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in 21d9485. The text spectrum now uses the shared version, timestamp and one-based ionic-step header, followed by a commented point count. A two-step run confirmed Ionic_Step 2.


# This two-stage producer/consumer check needs the same SCF artifacts in
# separate LR runs, which the single-invocation Autotest cases cannot express.
find_program(LR_ABSORPTION_PYTHON python3)

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.

could you try to reduce the complexity of the cmake codes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated in 21d9485. CMake registers one absorption workflow test. The Python driver runs both spin configurations.

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.

do you have absorption '.csr outputs'? I didn't find them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The spectrum is the text table absorption.dat. CSR refers to the H(R)/S(R) matrix inputs for standalone LR. I renamed the test and driver to clarify this in 21d9485.

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

The fixed excitation-energy precision would benefit from a direct round-trip regression; the existing collector cannot distinguish the intended precision.

Static incremental source review of 21d9485, including LR/BSE callers, provenance and validation workflows; no build or runtime test was run.

{
std::ofstream ofs(file);
const int decimals = lr_excitation_energy_digits - 1;
ofs << std::scientific << std::setprecision(decimals);

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: Add a round-trip regression for the fixed excitation-energy precision. The LR property collector rounds energies to six decimals, so it can miss a regression in this 17-digit output contract. A finite value that requires max_digits10 to round-trip would protect the behavior.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added MODULE_LR_util_print in ff7dbc2. It writes and reads back the double immediately above 1.0 and a small finite value, then compares them exactly. The test passes at 17 significant digits and fails in a scratch build at 16.

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.

Addressed in ff7dbc29c: MODULE_LR_util_print now checks exact round trips for the double above 1.0 and 1e-12, protecting the 17-digit output and small finite values.

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

@maki49

maki49 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

The CUDA failure reproduces on upstream develop. The last passing parent, b9047f391, is followed by the first failing upstream run, 7ac8fd7e7. #8357 updates the CUDA image from 12.2/Ubuntu 22.04 to 12.9/Ubuntu 24.04. The case inputs and comparison script are identical across those commits. The concurrent move from V100 to L20 prevents these two runs from isolating the image's effect.

The failing develop run and this PR's CUDA run report the same six Max_wfc values. #8372 addresses the phase-sensitive comparison upstream.

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

EXX/lr-TDDFT/RPA/BSE/GW Related to beyond DFT methods Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants