Skip to content

Refactor std::system in DeePKS (should not use system command, especially the rm operation should be prohibited) #6958

Description

@mohanchen

Describe the Code Quality Issue

void DeePKS_domain::cal_edelta_gedm_equiv(const int nat,
const DeePKS_Param& deepks_param,
const std::vectortorch::Tensor& descriptor,
double** gedm,
double& E_delta,
const int rank)
{
ModuleBase::TITLE("DeePKS_domain", "cal_edelta_gedm_equiv");
ModuleBase::timer::tick("DeePKS_domain", "cal_edelta_gedm_equiv");

const std::string file_d = PARAM.globalv.global_out_dir + "deepks_dm_eig.npy";
LCAO_deepks_io::save_npy_d(nat, PARAM.inp.deepks_equiv, deepks_param, descriptor, file_d,
                           rank); // libnpy needed

if (rank == 0)
{
    generate_py_files(deepks_param, PARAM.globalv.global_out_dir);
    std::string cmd = "python cal_edelta_gedm.py " + PARAM.inp.deepks_model;
    int stat = std::system(cmd.c_str());
    assert(stat == 0);
}

MPI_Barrier(MPI_COMM_WORLD);

LCAO_deepks_io::load_npy_gedm(nat, deepks_param.des_per_atom, gedm, E_delta, rank);

std::string cmd = "rm -f cal_edelta_gedm.py basis.yaml ec.npy gedm.npy";
std::system(cmd.c_str());

ModuleBase::timer::tick("DeePKS_domain", "cal_edelta_gedm_equiv");
return;

}

Additional Context

No response

Task list for Issue attackers (only for developers)

  • Identify the specific code file or section with the code quality issue.
  • Investigate the issue and determine the root cause.
  • Research best practices and potential solutions for the identified issue.
  • Refactor the code to improve code quality, following the suggested solution.
  • Ensure the refactored code adheres to the project's coding standards.
  • Test the refactored code to ensure it functions as expected.
  • Update any relevant documentation, if necessary.
  • Submit a pull request with the refactored code and a description of the changes made.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions