Skip to content

Fix RT-TDDFT MD fractional wrapping to [0, 1) and restore MD_dump atom ordering - #8207

Merged
mohanchen merged 11 commits into
deepmodeling:developfrom
ESROAMER:fix/md-wrap-dump-8206
Oct 28, 2026
Merged

mohanchen merged 11 commits into
deepmodeling:developfrom
ESROAMER:fix/md-wrap-dump-8206

Conversation

@ESROAMER

@ESROAMER ESROAMER commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Linked Issue

Fixes #8206.

What's changed?

  • Keep wrapped MD fractional coordinates within [0, 1).
  • Restore global atom ordering and frame separators in MD_dump, using bounded collective batches for large frames.
  • Add focused MD regressions and reuse test No. 10 for the minimal H2 boundary regression, retaining coverage of two Gaussian pulses in different directions.

Unit Tests and/or Case Tests for my changes

CPU build passed at 04a1ba3a26f3; MD tests were rebuilt and passed at e3714fdad546 after moving MPI tests to the standard unittests/ directory, with unchanged test lists. The merged RT case was verified at d4028da3410d using the same executable.

ctest --test-dir build-fix --output-on-failure \
  -R '^MODULE_MD_(func|verlet|dump_mpi(_np4)?)$'

From tests/05_rtTDDFT, using the fixed executable:

bash ../integrate/Autotest.sh -a "$ABACUS_EXE" \
  -n 4 -o 1 -j 1 -r '^10_NO_MD_boundary_shift$'

The merged case passes with both 1 and 4 MPI ranks, requiring one electronic iteration at the second step. Unmodified beta11 still fails the existing energy comparison by approximately 79 eV. 20_NO_MIXED_EFIELD_TDDFT also passes with 4 MPI ranks.
MD tests cover one-row and small-byte batches, aggregate overflow with individually fitting rank payloads, empty ranks, and appended frames. The 4-rank CTest also passes with nonempty MPIEXEC_PREFLAGS and MPIEXEC_POSTFLAGS; 16_NO_vel_TDDFT passes with 4 MPI ranks.

No documentation update required: no INPUT parameters or output fields change.
The include is required by the new CommunicationDomain API.

Gather frame text through CommunicationDomain and write rows by the stable type-major index. Emit frame separators once, including when some MPI ranks own no atoms.

Add serial-launch and four-rank tests for reversed ownership, an empty rank, empty frames, and append mode. No documentation update needed: this restores trajectory ordering without changing INPUT parameters, units, or columns.
Use two synthetic atoms and Gamma plus a non-Gamma point. Exercise the real MD update and backing-cell sync for sub-roundoff negative motion, and check H/S/coefficient phase covariance for all axes, both crossing directions, both atoms, and clearing a previous shift.

Verify the test fails when the coordinate fix is reverted or the Bloch phase sign is reversed. Restore both mutations and pass six related CTest targets, including the new single- and four-rank RT tests. No documentation update required: tests only.
Add INPUT, STRU and KPT for two H atoms on a periodic face with one non-Gamma k point and a supplied sub-roundoff transverse velocity. Register the case in CASES_CPU.txt and check post-initial SCF iterations and convergence through an opt-in md_scf.ref collector.

Original beta11 fails Autotest.sh with both one and four MPI ranks: step 2 reaches scf_nmax=8 without convergence. The fixed binary and beta11 with only the coordinate patch pass with one step-2 iteration. Existing 16_NO_vel_TDDFT and the four focused MD CTest targets also pass. Document the trigger and commands in the case README.
Raise scf_nmax to 100, remove the opt-in SCF collector and its reference file, and keep the case README to its single purpose sentence.

With one and four MPI ranks, the fixed case passes in one second-step iteration. Original beta11 takes ten iterations but reaches an energy about 79 eV away from the reference, so the existing Autotest.sh energy comparison fails without a custom validator or timeout.
@ESROAMER ESROAMER added Bugs Bugs that only solvable with sufficient knowledge of DFT rt-TDDFT Real-time Time-Dependent DFT labels Oct 23, 2026
@AsTonyshment
AsTonyshment requested a review from 19hello October 23, 2026 09:54
@AsTonyshment

Copy link
Copy Markdown
Collaborator

I heard @ESROAMER talk about this issue, and we believe it indeed arises from the newly implemented MD module. I'm not an expert in this area, so perhaps @19hello could take a look. Thanks!

@mohanchen mohanchen added the MD & LAM MD and Larege Atomic Models label Oct 23, 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 review of d2f1f5fb00c8 completed with independent verification. Two conditional P2 issues and one nonblocking naming note are below. No builds or runtime tests were run; the H2 energy/trigger and reported beta11 comparison remain unverified, and CI diagnostics were unavailable.

Comment thread source/source_base/parallel_cell.cpp Resolved
Comment thread source/source_md/test/CMakeLists.txt Resolved
Comment thread source/source_md/test/CMakeLists.txt Resolved
Comment thread tests/05_rtTDDFT/CASES_CPU.txt Resolved

@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 follow-up of d4028da3410d with independent verification found the three prior issues addressed. No new product defect is confirmed; the remaining notes are nonblocking.

Non-blocking: please update the integration command to ^10_NO_MD_boundary_shift$ and state which revision the reported results cover. The old ^29_NO_MD_boundary_shift$ filter now selects no cases, and Autotest can report a zero-case pass, so the documented command does not exercise this revision. (8207-A3)

No builds or runtime tests were run. The H2 reference, actual boundary trigger, beta11 comparison, MPI/serial/GPU execution and CI remain unverified.

@Critsium-xy Critsium-xy 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 title overstates the fix. This PR keeps wrapped fractional coordinates in [0, 1), which removes the spurious boundary crossing. It does not restore reset_matrix_boundary itself:

  • reset_matrix_boundary applies phases only when boundary_shift is nonzero (source_lcao/module_rt/boundary_fix.cpp:23).
  • boundary_shift is written only in unitcell::periodic_boundary_adjustment (source_cell/update_cell.cpp:490-503). The new MD path no longer calls it, and MDCell::sync_backing_unitcell() does not fill it.

So a genuine boundary crossing in LCAO RT-TDDFT MD (finite displacement, non-Gamma k) still gets no phase correction. The new case 10 does not cross a boundary after the fix, so it does not cover this. The gap predates this PR, so a fix is not required here. Please retitle the PR, e.g. "Fix MD fractional wrapping to [0, 1) and restore MD_dump atom ordering", and track the boundary_shift gap in a follow-up issue.

@ESROAMER ESROAMER changed the title Fix: restore normal reset_matrix_boundary behavior in RT-TDDFT and MD_dump ordering Fix RT-TDDFT MD fractional wrapping to [0, 1) and restore MD_dump atom ordering Oct 27, 2026
@ESROAMER

Copy link
Copy Markdown
Collaborator Author

Thanks for catching this! I've updated the title. I'll open a separate issue for the boundary_shift gap and fix it in a follow-up PR, with tests to check that it matches the old behavior.

@Critsium-xy

Critsium-xy commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

And by the way, according to our new standard, adding this new mpi folder is not allowed.
img_v3_0216s_a2786704-232a-4db1-a6b1-240b2d98bcfg
You can modify this by looking at what other folders are doing (add a unittest folder and put the tests under it)

@19hello

19hello commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the careful investigation and for preparing this fix. The wrapping and MD_dump regressions are well isolated. For the planned follow-up on genuine boundary crossings, it may also be worth handling the ionic-position update state explicitly.

Currently, ionic_position_updated is set in MD_base::setup(), while subsequent MDCell position updates are copied to the backing UnitCell by MDCell::sync_backing_unitcell(). Since ESolver_FP::before_scf() uses this flag to decide whether to update and extrapolate the charge density, it would be safer to refresh the flag whenever a new MD position is synchronized, rather than relying on its initial value remaining true.

One possible implementation is to add a per-atom boundary_shift field to LocalAtom. MD_base::update_pos() could compute this value from the unwrapped fractional coordinate before applying periodic wrapping, and MDCell::sync_backing_unitcell() could then copy each atom's boundary_shift to UnitCell::atoms[it].boundary_shift. After the position/state synchronization is complete, the same function could set:

backing_unitcell_->ionic_position_updated = true;

The wrapping logic should preserve the old two-step behavior: handle values below zero first, then handle values greater than or equal to one. This is important for the tiny-negative-displacement case, where adding one may round to exactly 1.0; the second check should canonicalize it back to 0.0 without recording a spurious boundary shift.

It would be useful to add focused tests for:

- a tiny negative displacement, producing coordinate 0.0 and zero boundary shift;
- genuine positive and negative boundary crossings, producing the expected wrapped coordinate and shift;
- synchronization of both boundary_shift and ionic_position_updated from MDCell to the backing UnitCell.

@ESROAMER

Copy link
Copy Markdown
Collaborator Author

Thanks for the suggestions! We'll incorporate them into the follow-up PR for #8221, including the position-update flag and the proposed tests.

@mohanchen
mohanchen merged commit d516afa into deepmodeling:develop Oct 28, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT MD & LAM MD and Larege Atomic Models rt-TDDFT Real-time Time-Dependent DFT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MD regressions: periodic wrapping roundoff breaks LCAO RT-TDDFT continuation and MD_dump loses atom order

6 participants