Skip to content

Draft: Enable complex multi-k PEXSI path for LCAO#7381

Open
JohnHe233 wants to merge 3 commits into
deepmodeling:developfrom
JohnHe233:pexsi-stage4-code-opt
Open

Draft: Enable complex multi-k PEXSI path for LCAO#7381
JohnHe233 wants to merge 3 commits into
deepmodeling:developfrom
JohnHe233:pexsi-stage4-code-opt

Conversation

@JohnHe233
Copy link
Copy Markdown

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

  • Added unit coverage for the refactored PEXSI solver interface:
    • DiagoPexsiRefactorTest.UsesInjectedSolverAndOwnedDensityBuffers
    • Uses a fake IPexsiSolver to test solver injection and owned DM/EDM buffers
      without invoking the real PEXSI/MPI sparse solve path.
  • Added tools/pexsi/check_lcao_10case_regression.py for LCAO PEXSI regression
    checks.
  • Retested the official LCAO 10-case set with ks_solver pexsi.
    • 5/10 cases completed SCF: 001, 002, 003, 005, 008.
    • 002 passes the strict 5.0e-7 eV total-energy tolerance.
    • 004, 006, 007, 009 and 010 timed out under the local 4 MPI ranks / 1800 s test
      limit.

What's changed?

  • Added a complex multi-k PEXSI path for LCAO.
    • Converts complex H/S matrices from ABACUS block-cyclic distribution to PEXSI CCS
      format.
    • Calls the complex expert-level PEXSI Fermi-operator workflow.
    • Retrieves complex DM/EDM matrices and maps them back to ABACUS data structures.
  • Added a global chemical-potential search for multi-k PEXSI.
    • Uses one chemical potential per spin channel.
    • Accumulates electron number, derivative and energies over weighted k-points.
    • Adds Newton / bracket / bisection fallback handling.
  • Fixed k-point and spin weighting for nspin=1 to avoid double-counting spin
    degeneracy.
  • Implemented complex PEXSI DM/EDM handling in ElecStateLCAO::dm2rho.
  • Refactored the PEXSI solver dependency.
    • Added pexsi::IPexsiSolver.
    • Changed DiagoPexsi to depend on the interface instead of directly depending on
      PEXSI_Solver.
  • Reworked DM/EDM buffer ownership in DiagoPexsi.
    • Uses std::vector<std::vector<T>> for storage.
    • Preserves the existing std::vector<T*> DM/EDM interface for current callers.
  • Added a deterministic guard for the Gamma-only real PEXSI path if it is incorrectly
    entered by a multi-k case.
  • Optimized BCD-to-CCS H/S redistribution by packing H and S values into one
    MPI_Alltoallv.
  • Fixed the countMatrixDistribution zero-value check from fabs(A[i] < 1e-31) to
    fabs(A[i]) < 1e-31.
  • Added TransMAT2CCS timer coverage to separate ABACUS-side matrix conversion cost
    from PEXSI solve cost.

Possible behavior changes

  • Multi-k LCAO inputs with ks_solver pexsi no longer fail immediately at the
    previous unsupported complex-path boundary.
  • Gamma-only real PEXSI now fails earlier with a clearer error if a multi-k index
    enters the real path.
  • Default PEXSI settings for fixed / low-temperature occupation are more conservative
    in this branch, which improves energy consistency for some cases but can
    significantly increase runtime.
  • Large or metallic cases may still be too expensive with the current serial-over-k
    implementation and repeated PEXSI setup/factorization.

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

  • HSolver:
    • Updated DiagoPexsi to support solver-interface injection, owned density
      buffers, complex multi-k PEXSI calls and global chemical-potential accumulation.
    • Updated HSolverLCAO integration to pass k-point weights and handle PEXSI DM/EDM
      output.
  • ElecState:
    • Implemented complex PEXSI DM/EDM to density handling in ElecStateLCAO.
  • PEXSI module:
    • Added IPexsiSolver.
    • Extended BCD/CCS transformations for complex matrices.
    • Added complex PEXSI expert-routine workflow and conversion timers.

@Flying-dragon-boxing
Copy link
Copy Markdown
Collaborator

Flying-dragon-boxing commented May 25, 2026

Nice try! I will test the correctness of total energy on my machine later. A few small questions:

  • You mentioned that you've optimized BCD-to-CCS H/S redistribution by packing H and S values into one
    MPI_Alltoallv, have you tested the speed up?
  • For the cases that don't pass in 1800s, you may try reducing the pexsi_npole.
  • You may test the correctness of force calculation after the total energy is properly dealt with.

@JohnHe233 JohnHe233 marked this pull request as ready for review May 25, 2026 07:33
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