Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/slurm/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ resource = gpu2
runner = autotest
[case.009]
suite = 03_NAO_multik
name = scf_bisecuo_gpu
name = scf_bisecuo
resource = gpu4
runner = autotest
[case.010]
Expand Down
4 changes: 2 additions & 2 deletions .ci/slurm/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def test_current_matrix_is_loaded_from_ini(self):
self.assertEqual(config.resources["gpu4x2"].label, "2 nodes / 8 GPUs")
resources = {(case.suite, case.name): case.resource for case in config.cases}
self.assertEqual(resources[("11_PW_GPU", "scf_cg")], "gpu4")
self.assertEqual(resources[("03_NAO_multik", "scf_bisecuo_gpu")], "gpu4")
self.assertEqual(resources[("03_NAO_multik", "scf_bisecuo")], "gpu4")
self.assertEqual(resources[("05_rtTDDFT", "12_NO_re_TDDFT")], "gpu4")
self.assertEqual(resources[("05_rtTDDFT", "00_NO_Si48_CUSOLVERMP_TDDFT_GPU")], "gpu4x2")
self.assertEqual(
{identity for identity, resource in resources.items() if resource == "gpu4"},
{
("11_PW_GPU", "scf_cg"),
("03_NAO_multik", "scf_bisecuo_gpu"),
("03_NAO_multik", "scf_bisecuo"),
("05_rtTDDFT", "12_NO_re_TDDFT"),
},
)
Expand Down
22 changes: 22 additions & 0 deletions interfaces/Wannier90_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# The consumer check requires the external Wannier90 and postw90 executables.
find_program(WANNIER90_EXECUTABLE wannier90.x)
find_program(POSTW90_EXECUTABLE postw90.x)
if(ENABLE_LCAO
AND ENABLE_MPI
AND WANNIER90_EXECUTABLE
AND POSTW90_EXECUTABLE)
find_package(Python3 QUIET COMPONENTS Interpreter NumPy)
if(Python3_NumPy_FOUND AND MPIEXEC_EXECUTABLE)
add_test(
NAME 03_NAO_wannier_spn
COMMAND
${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tests/check_wannier_spn.py
${WANNIER90_EXECUTABLE} ${POSTW90_EXECUTABLE} ${MPIEXEC_EXECUTABLE}
${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${ABACUS_BIN_PATH}
${MPIEXEC_POSTFLAGS})
set_tests_properties(
03_NAO_wannier_spn PROPERTIES PROCESSORS 4 TIMEOUT 300 ENVIRONMENT
"OMP_NUM_THREADS=1")
endif()
endif()
2 changes: 1 addition & 1 deletion interfaces/Wannier90_interface/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PYTHONPATH=.. python -m pytest test_interface.py
The driver runs a spinor LCAO SCF and NSCF calculation, Wannier90 and
`postw90.x` in a temporary directory. It reads the oxygen inputs from the
test case and the pseudopotential and orbitals from `tests/PP_ORB/`.
[Test driver](check_wannier_spn.py) and [oxygen inputs](../../../tests/03_NAO_multik/wannier_spn/)
[Test driver](check_wannier_spn.py) and [oxygen inputs](wannier_spn/)

Use an MPI-enabled LCAO build with ScaLAPACK (`ks_solver=scalapack_gvx`).
Configure with `BUILD_TESTING=ON` and make sure CMake can find an MPI launcher,
Expand Down
2 changes: 1 addition & 1 deletion interfaces/Wannier90_interface/tests/check_wannier_spn.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def check_spn_io_failure(work, abacus, logs, error):

def main(work, wannier, postw90, abacus):
tests = Path(__file__).resolve().parents[3] / "tests"
case = tests / "03_NAO_multik" / "wannier_spn"
case = Path(__file__).resolve().parent / "wannier_spn"
shutil.copy(case / "STRU", work)
shutil.copy(case / "KPT", work)
shutil.copy(case / "oxygen.win", work)
Expand Down
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ abacus_apply_build_options(${ABACUS_BIN_NAME})
# available. Unit tests are added by source subdirectories through AddTest().
if(BUILD_TESTING)
add_subdirectory("${ABACUS_TEST_DIR}" "${PROJECT_BINARY_DIR}/tests")
add_subdirectory("${PROJECT_SOURCE_DIR}/interfaces/Wannier90_interface"
"${PROJECT_BINARY_DIR}/interfaces/Wannier90_interface")
endif()

install(PROGRAMS ${ABACUS_BIN_PATH} TYPE BIN)
Expand Down
8 changes: 5 additions & 3 deletions source/source_esolver/esolver_dm2rho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "source_cell/module_neighbor/sltk_atom_arrange.h"
#include "source_cell/read_pp_ucell.h"
#include "source_estate/elecstate_lcao.h"
#include "source_io/module_dm/write_dmr.h"
#include "source_io/module_ml/io_npz.h"
#include "source_io/module_output/cube_io.h"
#include "source_lcao/hamilt_lcao.h"
Expand Down Expand Up @@ -51,16 +52,17 @@ void ESolver_DM2rho<TK, TR>::runner(BaseCell &basecell, const int istep)

ESolver_KS_LCAO<TK, TR>::before_scf(ucell, istep);

// file name of DM
std::string zipname = "output_DM0.npz";
// File name of DM(R); out_dmr 2 writes one-based spin names that match the
// csr files produced by out_dmr 1.
std::string zipname = ModuleIO::dmr_gen_fname(2, 0);

// read DM from file
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_dmr_ptr(1)));

// if nspin=2, need extra reading
if (this->inp_->nspin == 2)
{
zipname = "output_DM1.npz";
zipname = ModuleIO::dmr_gen_fname(2, 1);
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_dmr_ptr(2)));
}

Expand Down
17 changes: 13 additions & 4 deletions source/source_io/module_ctrl/ctrl_scf_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
}

//------------------------------------------------------------------
//! 2) Output density matrix DM(R)
//! 2) Output density matrix DM(R) in csr text format
//------------------------------------------------------------------
if (inp.out_dmr[0])
if (inp.out_dmr[0] == 1)
{
// Mode-2 MAT/ subdirectory is created lazily at write time.
ModuleBase::ensure_directory(global_mat_dir);
Expand Down Expand Up @@ -357,15 +357,24 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
}
}

if (inp.out_dm_npz)
if (inp.out_dmr[0] == 2)
{
// Mode-2 MAT/ subdirectory is created lazily at write time.
ModuleBase::ensure_directory(global_mat_dir);
// Match the csr naming of out_dmr 1: dmrs{spin+1}[g{step+1}]_nao.npz.
// npz cannot append frames, so out_app_flag = 1 keeps a fixed name and
// overwrites it; out_app_flag = 2 embeds the one-based step.
const bool numbered = (out_app_flag == 2);
if (out_app_flag == 1)
{
ModuleBase::WARNING("ctrl_scf_lcao",
"out_dmr format 2 (npz) does not support appending; the fixed file is overwritten");
}
const std::vector<hamilt::HContainer<double>*>& dmr_vec = dm->get_dmr_vec();
for (int ispin = 0; ispin < dmr_vec.size(); ++ispin)
{
std::string zipname
= global_mat_dir + "output_DM" + std::to_string(ispin) + ".npz";
= global_mat_dir + ModuleIO::dmr_gen_fname(2, ispin, numbered, istep);
ModuleIO::output_mat_npz(ucell, zipname, *(dmr_vec[ispin]));
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_io/module_dm/write_dmr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string dmr_gen_fname(const int out_type, const int ispin, const bool number
}
else if (out_type == 2)
{
return detail::make_sparse_R_filename("dmr", spin_suffix, false, istep, ".npz");
return detail::make_sparse_R_filename("dmr", spin_suffix, numbered, istep, ".npz");
}
ModuleBase::WARNING("write_dmr", "the output type of density matrix DM(R) should be csr or npz.");
return "dmr.csr";
Expand Down
6 changes: 5 additions & 1 deletion source/source_io/module_hs/unittests/test_hs_dense_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ int read_binary_dim(const std::string& filename)
return -1;
}
int dim = 0;
std::fread(&dim, sizeof(int), 1, fp);
const size_t read_count = std::fread(&dim, sizeof(int), 1, fp);
std::fclose(fp);
if (read_count != 1)
{
return -1;
}
return dim;
}

Expand Down
4 changes: 2 additions & 2 deletions source/source_io/module_parameter/input_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ struct Input_para
bool out_mul = false; ///< qifeng add 2019-9-10
bool out_proj_band = false; ///< projected band structure calculation jiyy add 2022-05-11
std::string out_level = "ie"; ///< control the output information.
std::vector<int> out_dmr = {0, 8}; ///< output density matrix in real space DM(R)
std::vector<int> out_dmr = {0, 8}; ///< output DM(R): [format, precision]; 0 = off, 1 = csr, 2 = npz
std::vector<int> out_dmk = {0, 8}; ///< output density matrix in reciprocal space DM(k)
bool out_bandgap = false; ///< QO added for bandgap printing
std::vector<int> out_hsk = {0, 8}; ///< output H(k) and S(k): format and text precision
Expand Down Expand Up @@ -514,7 +514,7 @@ struct Input_para
bool out_eband_terms_compat = false; ///< legacy alias out_eband_terms for out_eband
bool out_hr_npz = false; ///< output H(R) matrix in npz format
bool out_hsr_npz = false; ///< output H(R) and S(R) matrices in npz format
bool out_dm_npz = false; ///< output DM(R) matrix in npz format
bool out_dm_npz_compat = false; ///< legacy alias out_dm_npz mapped to out_dmr format 2
int out_app_flag = 0; ///< 0: fixed filename, truncated and overwritten at every write;
///< 1: append to the same fixed file; 2: write to subdirectory
///< (PSI/, CHG/, POT/, ELF/, DOS/, DIP/, MAT/) with a g{step} suffix
Expand Down
93 changes: 70 additions & 23 deletions source/source_io/module_parameter/read_inp_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,66 @@ The optional second integer controls the output precision. If not provided, the
}
{
Input_Item item("out_dmr");
item.annotation = "output density matrix DM(R) with respect to lattice vector R (with precision 8)";
item.annotation = "output density matrix DM(R) in csr or npz format";
item.category = "Output information";
item.type = R"(Boolean \[Integer\](optional))";
item.description = R"(Whether to output the density matrix with Bravias lattice vector R index into files in the folder OUT.${suffix}. The files are named as dmr{s}{spin index}{g}{geometry index}{_nao} + {".csr"}. Here, 's' refers to spin, where s1 means spin up channel while s2 means spin down channel, and the sparse matrix format 'csr' is mentioned in out_hsr. Finally, the file name is fixed for out_app_flag = 0 (truncated and overwritten at every write) and out_app_flag = 1 (the first written step truncates it and later steps append complete records); only out_app_flag = 2 inserts a one-based geometry-step index for each ionic step that may have different geometries:
item.type = R"(Integer \[Integer\](optional))";
item.description = R"(Controls whether the density matrix with Bravias lattice vector R index is written to files in the folder OUT.${suffix}. The first value selects the output format:
* 0: do not write DM(R);
* 1: write the sparse matrix in the csr text format; the optional second integer sets the text precision (default 8);
* 2: write the dense matrix in the npz format (requires a build with -DENABLE_CNPY=1); no precision is applied.

For format 1, the files are named as dmr{s}{spin index}{g}{geometry index}{_nao} + {".csr"}. Here, 's' refers to spin, where s1 means spin up channel while s2 means spin down channel, and the sparse matrix format 'csr' is mentioned in out_hsr. Finally, the file name is fixed for out_app_flag = 0 (truncated and overwritten at every write) and out_app_flag = 1 (the first written step truncates it and later steps append complete records); only out_app_flag = 2 inserts a one-based geometry-step index for each ionic step that may have different geometries:
* nspin = 1: dmrs1_nao.csr;
* nspin = 2: dmrs1_nao.csr and dmrs2_nao.csr for the two spin channels.

[NOTE] In the 3.10-LTS version, the parameter is named out_dm1, and the file names are data-DMR-sparse_SPIN0.csr and data-DMR-sparse_SPIN1.csr, etc.)";
item.default_value = "False";
For format 2, the files are named dmrs{spin index}_nao.npz, where the spin index starts from 1. With out_app_flag = 2 the one-based geometry step is inserted, e.g. dmrs1g3_nao.npz.

[NOTE] In the 3.10-LTS version, the parameter is named out_dm1, and the file names are data-DMR-sparse_SPIN0.csr and data-DMR-sparse_SPIN1.csr, etc. The legacy boolean spelling is still accepted: true maps to format 1 and false maps to format 0.)";
item.default_value = "0";
item.unit = "";
item.set_availability("basis_type==lcao and gamma_only==0");
item.read_value = [](const Input_Item& item, Parameter& para) {
const size_t count = item.get_size();
if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_dmr needs at least 1 value");
para.input.out_dmr[0] = assume_as_boolean(item.str_values[0]);
// The first token is the output format: 0 = off, 1 = csr text, 2 = npz.
// The historical boolean spelling is still accepted for on/off.
int format = 0;
bool parsed_as_int = false;
try
{
size_t consumed = 0;
const int value = std::stoi(item.str_values[0], &consumed);
if (consumed == item.str_values[0].size())
{
format = value;
parsed_as_int = true;
}
}
catch (const std::invalid_argument&)
{
}
catch (const std::out_of_range&)
{
}
if (!parsed_as_int)
{
format = assume_as_boolean(item.str_values[0]) ? 1 : 0;
}
para.input.out_dmr[0] = format;
para.input.out_dmr[1] = 8;
if (count >= 2) try { para.input.out_dmr[1] = std::stoi(item.str_values[1]); }
catch (const std::invalid_argument&) { /* do nothing */ }
catch (const std::out_of_range&) {/* do nothing */}
if (count >= 2)
{
try
{
para.input.out_dmr[1] = std::stoi(item.str_values[1]);
}
catch (const std::invalid_argument&)
{
}
catch (const std::out_of_range&)
{
}
}
};
item.reset_value = [](const Input_Item& item, Parameter& para) {
if (para.input.calculation == "get_wf" || para.input.calculation == "get_pchg")
Expand All @@ -302,7 +343,20 @@ The optional second integer controls the output precision. If not provided, the
}
};
item.check_value = [](const Input_Item& item, const Parameter& para) {
if (para.sys.gamma_only_local == true && para.input.out_dmr[0])
const int format = para.input.out_dmr[0];
if (format < 0 || format > 2)
{
ModuleBase::WARNING_QUIT("ReadInput", "out_dmr format must be 0 (off), 1 (csr) or 2 (npz)");
}
if (format == 2)
{
#ifndef __CNPY
ModuleBase::WARNING_QUIT("ReadInput",
"to write in npz format, please "
"recompile with -DENABLE_CNPY=1");
#endif
}
if (para.sys.gamma_only_local == true && format != 0)
{
ModuleBase::WARNING_QUIT("ReadInput", "out_dmr is only valid for multi-k calculation");
}
Expand Down Expand Up @@ -821,7 +875,7 @@ For binary output, each file uses the same basename as text output with a .dat s
};
item.check_value = [](const Input_Item& item, const Parameter& para) {
if ((para.inp.out_mat_r[0] || para.inp.out_mat_t[0]
|| para.inp.out_hr_npz || para.inp.out_dm_npz || para.inp.dm_to_rho)
|| para.inp.out_hr_npz || para.inp.dm_to_rho)
&& para.sys.gamma_only_local)
{
ModuleBase::WARNING_QUIT("ReadInput",
Expand Down Expand Up @@ -1590,24 +1644,17 @@ The circle order of the charge density on real space grids is: x is the outer lo
}
{
Input_Item item("out_dm_npz");
item.annotation = "output DM(R) matrix in npz format";
item.annotation = "deprecated alias for out_dmr 2 (DM(R) in npz format)";
item.category = "Output information";
item.type = "Boolean";
item.description = "Whether to print density matrices DM(R) in npz format. This feature does not work for gamma-only calculations.";
item.description = "Deprecated alias for writing DM(R) in npz format. Use out_dmr 2 instead. When out_dmr is not set explicitly, this flag is mapped to out_dmr with format 2; if both are present, out_dmr takes precedence. This feature does not work for gamma-only calculations.";
item.default_value = "False";
item.unit = "";
item.set_availability("basis_type==lcao and gamma_only==0");
read_sync_bool(input.out_dm_npz);
item.check_value = [](const Input_Item& item, const Parameter& para) {
if (para.input.out_dm_npz)
{
#ifndef __CNPY
ModuleBase::WARNING_QUIT("ReadInput",
"to write in npz format, please "
"recompile with -DENABLE_CNPY=1");
#endif
}
item.read_value = [](const Input_Item& item, Parameter& para) {
para.input.out_dm_npz_compat = assume_as_boolean(item.str_values[0]);
};
add_bool_bcast(input.out_dm_npz_compat);
this->add_item(item);
}
{
Expand Down
36 changes: 36 additions & 0 deletions source/source_io/module_parameter/read_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ std::string ReadInput::prepare_input(Parameter& param)
this->normalize_occ_mat_options(param);
this->normalize_out_eband_alias(param);
this->normalize_td_output_frequency(param);
this->normalize_dm_output_options(param);

// The CSR angular-momentum writer indexes the scalar real-harmonic basis.
// In nspin = 4 the spinor basis doubles nlocal and uses a different
Expand Down Expand Up @@ -800,6 +801,41 @@ void ReadInput::normalize_td_output_frequency(Parameter& param)
}
}

void ReadInput::normalize_dm_output_options(Parameter& param)
{
const auto item_is_read = [this](const std::string& label) {
const std::vector<std::pair<std::string, ModuleIO::Input_Item>>::iterator item = std::find_if(
this->input_lists.begin(),
this->input_lists.end(),
[&label](const std::pair<std::string, Input_Item>& entry) { return entry.first == label; });
return item != this->input_lists.end() && item->second.is_read();
};

// out_dm_npz is the legacy spelling of out_dmr with format 2. It is mapped
// to the canonical parameter so that a single code path writes the npz
// matrices; the canonical out_dmr wins when both are present.
if (!item_is_read("out_dm_npz"))
{
return;
}
ModuleBase::WARNING("ReadInput", "out_dm_npz is deprecated; use out_dmr 2 instead");
if (item_is_read("out_dmr"))
{
ModuleBase::WARNING("ReadInput", "both out_dmr and out_dm_npz are set; out_dmr takes precedence");
return;
}
// Match the out_dmr reset rule: wavefunction/partial-charge runs do not
// write DM(R), so the alias must not turn it back on.
if (param.input.calculation == "get_wf" || param.input.calculation == "get_pchg")
{
return;
}
if (param.input.out_dm_npz_compat)
{
param.input.out_dmr[0] = 2;
}
}

void ReadInput::write_txt_input(const Parameter& param, const std::string& filename)
{
ModuleBase::TITLE("ReadInput", "write_txt_input");
Expand Down
10 changes: 10 additions & 0 deletions source/source_io/module_parameter/read_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ class ReadInput
* @param param parameters of ABACUS
*/
void normalize_td_output_frequency(Parameter& param);
/**
* @brief Resolve out_dm_npz, the legacy deprecated alias of out_dmr with format 2.
*
* This is called after all INPUT values have been read so that the result
* does not depend on the order of keywords in the INPUT file. The canonical
* out_dmr takes precedence when both parameters are present.
*
* @param param parameters of ABACUS
*/
void normalize_dm_output_options(Parameter& param);
/**
* @brief write INPUT file of txt format
*
Expand Down
Loading
Loading