Skip to content

Add new search algorithm#7331

Open
19hello wants to merge 9 commits intodeepmodeling:developfrom
19hello:search_algorithm
Open

Add new search algorithm#7331
19hello wants to merge 9 commits intodeepmodeling:developfrom
19hello:search_algorithm

Conversation

@19hello
Copy link
Copy Markdown
Collaborator

@19hello 19hello commented May 10, 2026

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #...

Unit Tests and/or Case Tests for my changes

  • A unit test is added for each new feature or bug fix.

What's changed?

  • Example: My changes might affect the performance of the application under certain conditions, and I have tested the impact on various scenarios...

Any changes of core modules? (ignore if not applicable)

  • Example: I have added a new virtual function in the esolver base class in order to ...

Copilot AI review requested due to automatic review settings May 10, 2026 12:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new cell neighbor-search implementation (bin-based neighbor list) under source_cell/module_neighbor_search and integrates it into the Lennard-Jones ESolver path, with accompanying build wiring and unit tests. It also adjusts an existing PW float test threshold to account for precision differences.

Changes:

  • Added module_neighbor_search (NeighborSearch + BinManager + NeighborList/PageAllocator) and hooked it into the build (CMake + Makefile.Objects).
  • Updated UnitCell to implement a new IAtomProvider interface; added UnitCellPlus adapter.
  • Switched ESolver_LJ neighbor iteration from the legacy grid neighbor search to the new NeighborSearch implementation and added unit tests for the new module.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
tests/01_PW/208_PW_CG_float/threshold Loosened integration threshold for float PW CG test.
source/source_esolver/esolver_lj.h Included UnitCellPlus and added conversion helper declaration.
source/source_esolver/esolver_lj.cpp Integrated new NeighborSearch into LJ runner (replacing legacy neighbor driver code path).
source/source_cell/unitcell.h Made UnitCell implement IAtomProvider by adding accessor overrides.
source/source_cell/module_neighbor_search/unitcell_interface.h Added IAtomProvider interface for neighbor search inputs.
source/source_cell/module_neighbor_search/unitcell_plus.h Added UnitCellPlus adapter implementing IAtomProvider.
source/source_cell/module_neighbor_search/neighbor_atom.h Added neighbor atom/value types used by the new neighbor search.
source/source_cell/module_neighbor_search/neighbor_list.h Added NeighborList + PageAllocator for adjacency storage.
source/source_cell/module_neighbor_search/bin_manager.h Added binning manager interface.
source/source_cell/module_neighbor_search/bin_manager.cpp Implemented bin construction, binning, and neighbor list building.
source/source_cell/module_neighbor_search/neighbor_search.h Added NeighborSearch API and internal state.
source/source_cell/module_neighbor_search/neighbor_search.cpp Implemented neighbor search initialization, expansion, and domain logic.
source/source_cell/module_neighbor_search/CMakeLists.txt Added object library target and conditional test subdir.
source/source_cell/module_neighbor_search/test/CMakeLists.txt Added test targets for new module.
source/source_cell/module_neighbor_search/test/neighbor_search_test.cpp Added gtest coverage for NeighborSearch.
source/source_cell/module_neighbor_search/test/bin_manager_test.cpp Added gtest coverage for BinManager.
source/source_cell/module_neighbor_search/test/neighbor_list_test.cpp Added gtest coverage for PageAllocator/NeighborList.
source/source_cell/module_neighbor_search/test/test_neighbor_search.cpp Added additional tests file (currently not built).
source/source_cell/CMakeLists.txt Added module_neighbor_search subdirectory to cell build.
source/Makefile.Objects Added neighbor_search objects to Makefile build graph.
CMakeLists.txt Linked neighbor_search into main executable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +44 to +49
void NeighborSearch::init(const IAtomProvider& ucell, double sr, int mpi_rank)
{
search_radius = sr / ucell.get_lat0();
Check_Expand_Condition(ucell);
setMemberVariables(ucell);
InputAtoms atoms = ucell_to_input_atoms(ucell);
Comment on lines +51 to +54
int mpi_size = 1;
int nx, ny, nz;
decompose(mpi_size, nx, ny, nz);

Comment on lines +56 to +57
y = (mpi_rank % (nx * ny)) / ny;
x = mpi_rank % (nx * ny) % ny;
Comment on lines +67 to +71
if(wide_x==0)
{
if(all_atoms[i].position_x==atoms.x_low)
{
in_x = x;
}
}

neighbor_list.initialize(inside_atoms.size(), 100000000);
classname = "ESolver_LJ";
}

UnitCellPlus change_from_ucell_to_ucell_plus(UnitCell& ucell);
../bin_manager.cpp
)

AddTest(
Comment on lines +151 to +155
void NeighborSearch::Check_Expand_Condition(const IAtomProvider& ucell)
{
double a23_1 = ucell.get_latvec().e22 * ucell.get_latvec().e33 - ucell.get_latvec().e23 * ucell.get_latvec().e32;
double a23_2 = ucell.get_latvec().e21 * ucell.get_latvec().e33 - ucell.get_latvec().e23 * ucell.get_latvec().e31;
double a23_3 = ucell.get_latvec().e21 * ucell.get_latvec().e32 - ucell.get_latvec().e22 * ucell.get_latvec().e31;
Comment on lines +273 to +281
// with mpi_size fixed to 1 in init, nx=ny=nz=1; for rank 0 expect x=y=0,z=0
EXPECT_EQ(ns0.x, 0);
EXPECT_EQ(ns0.y, 0);
EXPECT_EQ(ns0.z, 0);

NeighborSearch ns1;
ns1.init(ucell, 0.5, 1);
// rank 1: z = mpi_rank /(nx*ny) = 1, x and y remain 0 when ny==1
EXPECT_EQ(ns1.z, 1);
Comment on lines +34 to +41
ModuleBase::Vector3<double> get_tauu(int i, int j) const override {
int count=0;
for(int k=0;k<i;k++)
{
count += na[k];
}
count+=j;
return tau[count];
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