Skip to content

Refactor selfEnergy implementation and lead matrices#39

Merged
AsymmetryChou merged 4 commits into
deepmodeling:mainfrom
AsymmetryChou:rgf_acc
Jul 12, 2026
Merged

Refactor selfEnergy implementation and lead matrices#39
AsymmetryChou merged 4 commits into
deepmodeling:mainfrom
AsymmetryChou:rgf_acc

Conversation

@AsymmetryChou

Copy link
Copy Markdown
Collaborator

This pull request introduces performance optimizations and code refactoring to the surface Green's function calculation in the NEGF module. The main improvements are the precomputation and reuse of matrix conjugate-transposes, efficient conversion of tensors to NumPy arrays, and a more consistent interface for the surface Green's function core routines. These changes reduce redundant computations and improve compatibility with Numba and multiprocessing.

Performance and Memory Optimizations

  • Added the _pack_lead_matrices utility in lead_property.py to precompute and store conj(HLLk.T) and conj(SLLk.T) as h10 and s10, and to convert relevant matrices to C-contiguous np.complex128 arrays. This minimizes repeated torch→numpy conversions and avoids recomputing conjugate-transposes per energy. (dpnegf/negf/lead_property.py dpnegf/negf/lead_property.pyR911-R948)
  • Updated the lead k-point precomputation routines to use _pack_lead_matrices, ensuring all workers receive efficiently packed data. (dpnegf/negf/lead_property.py [1] [2]

API and Interface Changes

  • Modified the selfEnergy and surface_green functions to accept optional h10 and s10 arguments for the precomputed conjugate-transposes, defaulting to on-the-fly computation if not provided. (dpnegf/negf/surface_green.py [1] [2]
  • Updated all internal calls and the Numba/Scipy core routines to use the new arguments and interface, ensuring consistency and backward compatibility. (dpnegf/negf/surface_green.py [1] [2] [3]

Algorithmic Refactoring

  • Refactored the Numba and Scipy Lopez-Sancho core implementations to use batched GEMM operations for updating recursion variables, improving cache efficiency and matching the new interface. Also, replaced the convergence test with a slightly cheaper but equivalent probe. (dpnegf/negf/surface_green.py [1] [2]

Compatibility and Reliability

  • Ensured all matrix conversions and precomputations are compatible with both direct NumPy arrays and torch tensors, and with multiprocessing (joblib-memmapped) environments. (dpnegf/negf/lead_property.py [1] [2]
  • Added a regression-testable Numba core variant with fastmath=False for validation purposes. (dpnegf/negf/surface_green.py dpnegf/negf/surface_green.pyR171-R176)

These changes should yield a noticeable speedup in NEGF calculations, especially in parallel or high-throughput scenarios, by avoiding redundant computation and memory layout conversions.

@AsymmetryChou

AsymmetryChou commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

solve #38 in the last commit @Lonya0

@AsymmetryChou
AsymmetryChou merged commit 57f1493 into deepmodeling:main Jul 12, 2026
1 check passed
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.

1 participant