Skip to content

Change names of MD subroutines and files - #7900

Merged
mohanchen merged 5 commits into
deepmodeling:developfrom
19hello:change_name
Sep 4, 2026
Merged

Change names of MD subroutines and files#7900
mohanchen merged 5 commits into
deepmodeling:developfrom
19hello:change_name

Conversation

@19hello

@19hello 19hello commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

No linked issue. This is an internal refactor follow-up to #7812 and #7896.

Unit Tests and/or Case Tests for my changes

  • Commands run:

    bash -c 'source toolchain/install/setup && cmake -S . -B build_parallel_md1_current'
    
    bash -c 'source toolchain/install/setup && cmake --build build_parallel_md1_current --target driver esolver md MODULE_ESOLVER_esolver_dp_test
    MODULE_MD_run MODULE_MD_func MODULE_MD_fire MODULE_MD_lgv MODULE_MD_msst MODULE_MD_nhc MODULE_MD_verlet MODULE_CELL_NEIGHBOR_mdcell_reader
    MODULE_CELL_NEIGHBOR_mdcell_migrate_mpi -j4'
    
    OMP_NUM_THREADS=1 ctest --test-dir build_parallel_md1_current --output-on-failure -R 'MODULE_ESOLVER_esolver_dp_test|MODULE_MD_(run|func|fire|lgv|
    msst|nhc|verlet)$|MODULE_CELL_NEIGHBOR_(mdcell_reader|mdcell_migrate_mpi)'
    
    python3 tools/03_code_analysis/agent_governance_check.py --staged
    git diff --check
    
  • Result summary:

    • CMake configuration passed.
    • Driver, ESolver, MD, and affected test targets built successfully.
    • 10/10 focused ESolver, MD, and MPI tests passed.
    • git diff --check passed.
    • Governance check reported warnings only; no blocking findings.
  • Checks not run, with reason:

    • The full CTest suite was not run; this PR is an internal refactor and focused tests cover all renamed MDCell/BaseCell/STRU metadata paths.
    • GPU, DeePMD, and NEP runtime tests were not run because the local build is CPU-only and does not enable those optional backends.

What's changed?

  • Move parallel-MD cell preparation from Driver into Run_MD::prepare_mdcell.

  • Keep the original UnitCell initialization path in driver_run.cpp; both MD initialization paths now prepare one MDCell and use the same md_line.

  • Keep MD restart STRU metadata in MDCell, so Driver does not own MD output state.

  • Simplify MD-related names:

    • DistributedMDCellReader → MDCellReader
    • distributed_mdcell_reader.* → mdcell_reader.*
    • base_cell.* → basecell.*
    • md_cell.* → mdcell.*
    • BaseCell::Kind::{unit_cell, md_cell} → {unitcell, mdcell}
    • MdStruFileMetadata / MdStruFileSpecies → StruMeta / StruSpecies
    • md_stru_file_metadata.h → strumeta.h
  • Remove unused includes from driver_run.cpp.

  • Add focused coverage for preparing an MDCell from a UnitCell.

No user-visible behavior or INPUT parameter behavior changes are intended.

Governance Notes

  • INPUT/docs changes:

    • No INPUT behavior changed; no user documentation update is required.
  • Core module impact:

    • source_cell: renames BaseCell/MDCell implementation files and moves restart STRU metadata ownership into MDCell.
    • source_md: owns MDCell preparation and consumes metadata through MDCell.
    • source_esolver: updates internal BaseCell::Kind references only; solver behavior is unchanged.
  • Exceptions requested:

    • None.
    • Governance header-include warnings are rename-only: the affected headers continue to require the same complete types as before, with no
      dependency growth.

@mohanchen mohanchen changed the title Change name Change names of MD subroutines and files Sep 3, 2026
Comment thread source/source_md/test/run_md_test.cpp Outdated
Comment thread source/source_md/test/run_md_test.cpp Outdated
@mohanchen mohanchen added Refactor Refactor ABACUS codes MD & LAM MD and Larege Atomic Models labels Sep 3, 2026

@mohanchen mohanchen 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
mohanchen merged commit 912824c into deepmodeling:develop Sep 4, 2026
17 of 18 checks passed
mohanchen pushed a commit to mohanchen/abacus-mc that referenced this pull request Sep 4, 2026
PR deepmodeling#7888 tests were added before PR deepmodeling#7900 renamed
ModuleBase::world_communication_domain() to
ModuleBase::world_comm_domain(); update the three affected
test files so the parallel test targets build again.

Verified: cmake --build build --target
MODULE_BASE_parallel_domain_grid MODULE_BASE_para_gemm
MODULE_BASE_parallel_device all succeed.
mohanchen added a commit that referenced this pull request Sep 6, 2026
* feat(estate): add OccMatMixer skeleton for DFT+U occupation mixing

Introduce OccMatMixer in source_estate to own the flattened
occupation-matrix buffers (uom/uom_save) currently embedded in
Plus_U_Base. Step 1 only adds the class skeleton (init/seed_save/
begin_iter/collect/mix) and wires occ_mixer.cpp into CMake; the
migration of state and call sites follows in subsequent commits.

* refactor(pwdft): attach OccMatMixer to Plus_U_Base (transitional)

Compose Plus_U_Base with a std::unique_ptr<OccMatMixer>, constructed in
init_base only when mixing_dftu != 0 so that "mixer exists" doubles as
the mixing-on flag. The legacy uom_array/uom_save members and the
is_mixing_enabled/enable_mixing accessors are kept for now; they are
removed in a later commit once all call sites migrate.

Invert the Charge_Mixing dependency: OccMatMixer no longer calls
Charge_Mixing::mix_uom itself. It only owns the flat buffers, exposes
them via uom()/uom_save(), and provides write_back() to deserialize the
mixed result. The PW driver (which already links charge_mixing) feeds
the buffers to mix_uom. This keeps occ_mixer.cpp dependent solely on
occ_matrix.h, so the PW and LCAO dftu unit tests link with just
occ_matrix.cpp + occ_mixer.cpp instead of dragging in the planewave/xc
dependency chain (PW_Basis::real2recip, XC_Functional::ked_flag).

Wire occ_mixer.cpp into the dftu_base_test and dftu_lcao_test sources.

* refactor(pwdft): route cal_occ_pw mixing through OccMatMixer

cal_occ_pw now drives the PW mixing orchestration via the composed
OccMatMixer instead of the legacy uom_array/uom_save members:
begin_iter flattens the saved occ into uom_save, collect flattens the
fresh occ into uom, the buffers are fed to Charge_Mixing::mix_uom, and
write_back deserializes the mixed result. The enable condition switches
from is_mixing_enabled() to has_occ_mixer().

The flat save/new writes now run only when a mixer exists; they were
previously executed unconditionally but their results were only read
inside the mixing branch, so behavior is bit-identical. uom_array and
uom_save are now dead members and are removed in a later commit.

OccMatMixer::begin_iter no longer performs copy_to_save itself; that
snapshot stays in cal_occ_pw because it must precede occmat_.zero().

* refactor(estate): switch PW uom allocation to OccMatMixer flat_size

In chgmixing_ks_pw, drop the now-dead dftu.enable_mixing() call (the
mixer is constructed in init_base and cal_occ_pw reads has_occ_mixer()),
gate the uom_mdata allocation on has_occ_mixer() instead of
inp.mixing_dftu, and size it with occ_mixer().flat_size() which equals
the previous get_size_pot_uterm_pw(). The LCAO branch's dead
enable_mixing() call is left for the PARAM-dependency cleanup step.

* refactor(pwdft): drop dead uom_array/uom_save/is_mixing_enabled

Remove the flat occupation buffers uom_array/uom_save from Plus_U_Base
(now owned by OccMatMixer) together with their resize in init_base, and
the is_mixing_enabled() accessor that has no callers left. enable_mixing()
and the mixing_dftu member stay for now because the LCAO path still calls
enable_mixing(); they are removed alongside the PARAM.inp.mixing_dftu
dependency in the cleanup step.

* refactor(dftu): route LCAO plain mixing through OccMatMixer::mix_plain

Add OccMatMixer::mix_plain(occmat, beta), which delegates to
elecstate::mix_occ_with_save on the nested occupation blocks (the flat
buffers are PW/Broyden-only). Replace the two duplicated LCAO k/gamma
call sites with dftu.occ_mixer().mix_plain(dftu.occmat(), mixing_beta)
and gate them on has_occ_mixer() instead of PARAM.inp.mixing_dftu,
removing that cross-layer global read from dftu_nao_occ.cpp.

* refactor(pwdft): remove mixing_dftu member and dead enable_mixing calls

The mutable workflow switch is fully retired: drop the LCAO branch's dead
dftu.enable_mixing() block in chgmixing_ks_lcao (the flag it set was never
read), the enable_mixing() accessor, and the mixing_dftu member of
Plus_U_Base. The init_base mixing_dftu parameter is kept as the sole
decision input for constructing the OccMatMixer; presence of the mixer is
now the only "mixing on" signal.

* add ut for occ_mixer

* fix(dftu): serialize occ_save in write_save_to_flat; fix test double-free

OccupationMatrix::write_save_to_flat is documented to flatten occ_save_
into the uom_save mixing buffer, but it was reading occ_ instead, so the
first mixing step after seed_save/begin_iter used the wrong history
matrix.

In test_occ_mixer, Statistics::~Statistics() owns and delete[]s
iat2it/iat2ia, so backing them with std::vector storage caused a
double-free. Allocate them with new[] instead and drop the extra
backing vectors.

Verified: cmake --build build --target MODULE_ESTATE_occ_mixer &&
OMP_NUM_THREADS=1 ./build/source/source_estate/test/MODULE_ESTATE_occ_mixer
(4/4 tests pass).

* build(Makefile): add occ_mixer.o to OBJS_ELECSTAT

The Makefile build links dftu_base_occ.o/dftu_nao_occ.o against
OccMatMixer, but occ_mixer.cpp was missing from Makefile.Objects,
causing undefined-reference link errors for write_back/mix_plain.
CMake already wires it via source_estate/CMakeLists.txt.

* fix(base): update test call sites to world_comm_domain()

PR #7888 tests were added before PR #7900 renamed
ModuleBase::world_communication_domain() to
ModuleBase::world_comm_domain(); update the three affected
test files so the parallel test targets build again.

Verified: cmake --build build --target
MODULE_BASE_parallel_domain_grid MODULE_BASE_para_gemm
MODULE_BASE_parallel_device all succeed.

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MD & LAM MD and Larege Atomic Models Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants