Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor namespace Exx_Opt_Orb #5226

Closed
wants to merge 7 commits into from

Conversation

PeizeLin
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@kirk0830 kirk0830 left a comment

Choose a reason for hiding this comment

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

this PR do some minor refactor on codes that add "this->" to instance named "orb_", which makes the code clearer, this is acceptable.
However, it also shows me very astonishing use of nested std::map (I had never known them before), and very long lambda function that makes me confused about the program design.
There are also parameters packed in struct and named as "info", which I think, will bring more difficulty on program maintainment, so I request a change on it.

The use of extern keyword seems confusing and needs more explanation.

There are also new code added which depends explicitly on instance of class LCAO_Orbitals (is it a to-be-deprecated class? @mohanchen ).

Because seems there are already many codes in this module, so an immediate thoroughful improvement on code structure is nearly impossible, I recommend not introduce more cognition complexity into codes.

Exx_Abfs::Jle::Lmax = PARAM.inp.exx_opt_orb_lmax;
Exx_Abfs::Jle::Ecut_exx = PARAM.inp.exx_opt_orb_ecut;
Exx_Abfs::Jle::tolerence = PARAM.inp.exx_opt_orb_tolerence;
GlobalC::exx_info.info_opt_abfs.abfs_Lmax = PARAM.inp.exx_opt_orb_lmax;
Copy link
Collaborator

Choose a reason for hiding this comment

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

use of GlobalC is highly discouraged

const LCAO_Orbitals &orb_in,
const double kmesh_times );
static std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> change_orbs(
extern std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> change_orbs(
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you explain why you change all static to extern???
from https://en.cppreference.com/w/cpp/keyword/extern, which is the result want to get?

void Exx_Abfs::Jle::init_jle( const double kmesh_times, const LCAO_Orbitals& orb )
std::vector< std::vector< std::vector< Numerical_Orbital_Lm>>>
Exx_Abfs::Jle::init_jle(
const Exx_Info::Exx_Info_Opt_ABFs &info,
Copy link
Collaborator

Choose a reason for hiding this comment

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

the "info" used here has very straight forward drawback: it is impossible to know what one function really needs according to its parameter list. This will brings difficulty to code maintaining, unless this code is not expected to be maintained by any other

const ModuleBase::Element_Basis_Index::IndexLNM &index_jles) const
const std::vector<double>& orb_cutoff,
const ModuleBase::Element_Basis_Index::Range &range_jles,
const ModuleBase::Element_Basis_Index::IndexLNM &index_jles)
{
auto print_header = [&]( std::ofstream &ofs )
Copy link
Collaborator

Choose a reason for hiding this comment

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

why use lambda here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated



auto print_Q = [&]( std::ofstream &ofs )
Copy link
Collaborator

Choose a reason for hiding this comment

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

why use lambda here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@PeizeLin
Copy link
Collaborator Author

PeizeLin commented Oct 15, 2024

this PR do some minor refactor on codes that add "this->" to instance named "orb_", which makes the code clearer, this is acceptable. However, it also shows me very astonishing use of nested std::map (I had never known them before), and very long lambda function that makes me confused about the program design. There are also parameters packed in struct and named as "info", which I think, will bring more difficulty on program maintainment, so I request a change on it.

The use of extern keyword seems confusing and needs more explanation.

There are also new code added which depends explicitly on instance of class LCAO_Orbitals (is it a to-be-deprecated class? @mohanchen ).

Because seems there are already many codes in this module, so an immediate thoroughful improvement on code structure is nearly impossible, I recommend not introduce more cognition complexity into codes.

This PR is just to fix these codes from at least five years ago, making it can be run again under the LibRI framework. Many years ago, the codes of exx without LibRI were completely different from today.
So if you want to make more modifications to this code, I think it's better to be put in the future PR.

==============================

As for info, its definition can be seen in exx_info.h.
Perhaps the instantiation can be moved from GlobalC to PARAM in the future?

@kirk0830
Copy link
Collaborator

kirk0830 commented Oct 15, 2024

@PeizeLin Hi, I understand the historical reason you mentioned.
There are reasons why I call "info" brings difficulty to code maintainment:

  1. As the rule of thumb, functions should only take variables they really need, otherwise all possible caller will have an unnecessary long parameter list, or say it appears to be something like other developers are forced to know about exx_info instead of merely understand the function itself
  2. a single call to function whose parameter list have an exx_info datatype obj, should be behind the construction of exx_info, or an explicit inclusion of file exx_info.h, this means a strong coupling between struct exx_info and functions. This will bring inconvienence on unittest which partially ensuring the function can work as expected.

@mohanchen mohanchen added EXX and lr-TDDFT Related to EXX, this label is designed only for PeizeLin and Maki49 Refactor Refactor ABACUS codes labels Oct 17, 2024
@PeizeLin
Copy link
Collaborator Author

PeizeLin commented Oct 18, 2024

@PeizeLin Hi, I understand the historical reason you mentioned. There are reasons why I call "info" brings difficulty to code maintainment:

  1. As the rule of thumb, functions should only take variables they really need, otherwise all possible caller will have an unnecessary long parameter list, or say it appears to be something like other developers are forced to know about exx_info instead of merely understand the function itself
  2. a single call to function whose parameter list have an exx_info datatype obj, should be behind the construction of exx_info, or an explicit inclusion of file exx_info.h, this means a strong coupling between struct exx_info and functions. This will bring inconvienence on unittest which partially ensuring the function can work as expected.

All the variables in info is needed in the function. They come from INPUT.
I think it's better to use this four variables struct as the formal parameter explicitly than use the static variable PARAM.inp.xxx without formal parameter?
Maybe finally the actual argument is also the static variable PARAM.exx_info.info_opt_abfs when invoked, I think for this function itself, the formal parameter is better than static variable in the function at least.

Copy link
Collaborator

@kirk0830 kirk0830 left a comment

Choose a reason for hiding this comment

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

I retract my file change request presently

@mohanchen
Copy link
Collaborator

I have seen new PR, so this one will be closed.

@mohanchen mohanchen closed this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EXX and lr-TDDFT Related to EXX, this label is designed only for PeizeLin and Maki49 Refactor Refactor ABACUS codes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants