Skip to content

Formatting files in /source/source_hamilt/module_xc#7399

Open
mohanchen wants to merge 11 commits into
deepmodeling:developfrom
mohanchen:20260530
Open

Formatting files in /source/source_hamilt/module_xc#7399
mohanchen wants to merge 11 commits into
deepmodeling:developfrom
mohanchen:20260530

Conversation

@mohanchen
Copy link
Copy Markdown
Collaborator

Formatting files in /source/source_hamilt/module_xc

abacus_fixer added 2 commits May 30, 2026 06:32
- Add tau_xc overload with hybrid_alpha parameter
- Add ElecState::set_exx overload with cal_exx and hybrid_alpha parameters
- Format code: one parameter per line, align code, initialize variables, one variable per line, add braces to single-line for/if
@mohanchen mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels May 29, 2026
abacus_fixer added 4 commits May 30, 2026 07:15
- Format function parameters to one per line
- Initialize all variables when declared
- Separate variable declarations onto individual lines
- Add braces for single-line if/for statements
- Improve code alignment and readability
@mohanchen mohanchen requested a review from zzlinpku May 30, 2026 01:52
Copy link
Copy Markdown
Collaborator

@zzlinpku zzlinpku left a comment

Choose a reason for hiding this comment

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

Code Review Summary

This is a well-executed code style refactoring PR. The new file naming scheme (xc_*.cpp for native implementations, libxc_*.cpp for Libxc wrappers) is clear and consistent. A few items to address:

🔴 Must fix: Header guard in libxc.h still uses the old name.
🟡 Consider: Update comment references to old file names, and note the reference member risk in exx_info.h.

Comment thread source/source_hamilt/module_xc/libxc.h Outdated
Comment thread source/source_hamilt/module_xc/libxc.h Outdated
Comment thread source/source_hamilt/module_xc/libxc.h Outdated
Comment thread source/source_hamilt/module_xc/libxc.h Outdated
Comment thread source/source_hamilt/module_xc/libxc.h Outdated
Comment thread source/source_hamilt/module_xc/libxc.h Outdated
Comment thread source/source_hamilt/module_xc/xc_functional.h Outdated
Comment thread source/source_hamilt/module_xc/xc_functional.h
Comment thread source/source_hamilt/module_xc/libxc_mgga_wrap.cpp Outdated
Comment thread source/source_hamilt/module_xc/exx_info.h
Copy link
Copy Markdown
Collaborator

@zzlinpku zzlinpku left a comment

Choose a reason for hiding this comment

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

Code Review Summary

This is a well-structured refactoring PR. The file renames are consistent and improve readability, the indentation cleanup is thorough, and the exx_info.h lifetime warning is valuable.

However, there are two issues that should be addressed before merging — one potential name collision risk and one concern about mixing behavioral changes with formatting.

See inline comments for details.

#endif // USE_LIBXC

#endif // XC_FUNCTIONAL_LIBXC_H No newline at end of file
#ifndef LIBXC_H
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.

🔴 Header guard LIBXC_H is too generic — risk of collision with the actual libxc library.

The guard was renamed from XC_FUNCTIONAL_LIBXC_H to LIBXC_H. Since this project links against the external libxc library, a guard this generic could collide with libxc's own internal headers (or any future header that uses this common name). If a collision occurs, one header would silently be skipped, causing hard-to-diagnose compilation errors.

Suggestion: use a project-namespaced guard, e.g.:

#ifndef ABACUS_MODULE_XC_LIBXC_H
#define ABACUS_MODULE_XC_LIBXC_H

#include <array>

//tau_xc and tau_xc_spin: interface for calling xc_mgga_exc_vxc from LIBXC
//XC_POLARIZED, XC_UNPOLARIZED: internal flags used in LIBXC,
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.

🔴 Behavioral change: tau_xc signature now takes hybrid_alpha as a parameter.

The old implementation read GlobalC::exx_info.info_global.hybrid_alpha directly inside the function body. Passing it as a parameter is a good decoupling improvement, but this is a functional change hidden inside a formatting PR.

  1. Please confirm all call sites have been updated (not just test_xc4.cpp). The new xc_grad.cpp must also pass the correct hybrid_alpha value wherever tau_xc / tau_xc_spin are called.
  2. Consider noting this interface change explicitly in the PR description so reviewers don't miss it among ~3000 lines of formatting changes.

// Perdew gradient correction on correlation: PRB 33, 8822 (1986)

// USE kinds
// implicit none
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.

🟡 Redundant zero-initialization — all these variables are assigned real values on the very next lines.

For example, p1 is initialized to 0.0 here but immediately set to 0.0232660 two lines below. This pattern repeats throughout xc_gga_corr.cpp, xc_gga_exch.cpp, and xc_gga_wrap.cpp (~200+ lines total). While it suppresses compiler warnings, it significantly inflates the diff and makes it harder to spot the actual logic changes (like the tau_xc signature change).

Suggestion: either combine declaration and assignment (double p1 = 0.0232660;), or keep the original uninitialized declarations since they're assigned before any use.

};
Exx_Info_Global info_global;

// WARNING: Lifetime dependency
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.

🟢 Good addition. This lifetime dependency warning is valuable — the dangling-reference risk with const& members is a subtle trap, and documenting it here will prevent future bugs if Exx_Info is ever copied or moved.

#ifdef USE_LIBXC
#include "libxc.h"
#ifdef __EXX
#include "source_hamilt/module_xc/exx_info.h"
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.

🟡 New #include dependency introduced.

The old xc_functional_gradcorr.cpp included xc_functional_libxc.h under USE_LIBXC, but did NOT include exx_info.h. This new include under __EXX is presumably needed because the old tau_xc read GlobalC::exx_info internally, while the new version requires the caller (gradcorr) to pass hybrid_alpha. This is consistent with the interface change — just flagging it for awareness since it's a new compile-time dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants