Skip to content
Draft
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 docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -2593,7 +2593,7 @@

- **Type**: Integer
- **Availability**: *Numerical atomic orbital basis*
- **Description**: Include V_delta/V_delta_R (Hamiltonian in k/real space) label for DeePKS training. When deepks_out_labels is true and deepks_v_delta > 0 (k space), ABACUS will output deepks_hbase.npy, deepks_vdelta.npy and deepks_htot.npy(htot=hbase+vdelta). When deepks_out_labels is true and deepks_v_delta < 0 (real space), ABACUS will output deepks_hrtot.csr, deepks_hrdelta.csr. Some more files output for different settings. NOTICE: To match the unit Normally used in DeePKS, the unit of Hamiltonian in k space is Hartree. However, currently in R space the unit is still Ry.
- **Description**: Include V_delta/V_delta_R (Hamiltonian in k/real space) label for DeePKS training. When deepks_out_labels is true and deepks_v_delta > 0 (k space), ABACUS will output deepks_hbase.npy, deepks_vdelta.npy and deepks_htot.npy(htot=hbase+vdelta). When deepks_out_labels is true and deepks_v_delta < 0 (real space), ABACUS will output deepks_hrtot.csr, deepks_hrdelta.csr. All DeePKS energy and Hamiltonian labels are output in Hartree.
- deepks_v_delta = 1: deepks_vdpre.npy, which is used to calculate V_delta during DeePKS training.
- deepks_v_delta = 2: deepks_phialpha.npy and deepks_gevdm.npy, which can be used to calculate deepks_vdpre.npy. A recommanded method for memory saving.
- deepks_v_delta = -1: deepks_vdrpre.npy, which is used to calculate V_delta_R during DeePKS training.
Expand Down
9 changes: 8 additions & 1 deletion docs/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2397,14 +2397,21 @@ parameters:
category: DeePKS
type: Integer
description: |
Include V_delta/V_delta_R (Hamiltonian in k/real space) label for DeePKS training. When deepks_out_labels is true and deepks_v_delta > 0 (k space), ABACUS will output deepks_hbase.npy, deepks_vdelta.npy and deepks_htot.npy(htot=hbase+vdelta). When deepks_out_labels is true and deepks_v_delta < 0 (real space), ABACUS will output deepks_hrtot.csr, deepks_hrdelta.csr. Some more files output for different settings. NOTICE: To match the unit Normally used in DeePKS, the unit of Hamiltonian in k space is Hartree. However, currently in R space the unit is still Ry.
Include V_delta/V_delta_R (Hamiltonian in k/real space) label for DeePKS training. When deepks_out_labels is true and deepks_v_delta > 0 (k space), ABACUS will output deepks_hbase.npy, deepks_vdelta.npy and deepks_htot.npy(htot=hbase+vdelta). When deepks_out_labels is true and deepks_v_delta < 0 (real space), ABACUS will output deepks_hrtot.csr, deepks_hrdelta.csr. All DeePKS energy and Hamiltonian labels are output in Hartree.
* deepks_v_delta = 1: deepks_vdpre.npy, which is used to calculate V_delta during DeePKS training.
* deepks_v_delta = 2: deepks_phialpha.npy and deepks_gevdm.npy, which can be used to calculate deepks_vdpre.npy. A recommanded method for memory saving.
* deepks_v_delta = -1: deepks_vdrpre.npy, which is used to calculate V_delta_R during DeePKS training.
* deepks_v_delta = -2: deepks_phialpha_r.npy and deepks_gevdm.npy, which can be used to calculate deepks_vdrpre.npy. A recommanded method for memory saving.
default_value: "0"
unit: ""
availability: Numerical atomic orbital basis
- name: deepks_grad
category: DeePKS
type: Boolean
description: ""
default_value: "False"
unit: ""
availability: "NAO basis; requires deepks_out_labels >= 1 and deepks_v_delta < 0"
Comment on lines +2408 to +2414
- name: deepks_out_unittest
category: DeePKS
type: Boolean
Expand Down
1 change: 1 addition & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ OBJS_DEEPKS=LCAO_deepks.o\
deepks_vdelta.o\
deepks_vdpre.o\
deepks_vdrpre.o\
deepks_grad.o\
deepks_pdm.o\
deepks_phialpha.o\
LCAO_deepks_io.o\
Expand Down
11 changes: 8 additions & 3 deletions source/source_hamilt/module_hcontainer/output_hcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ template <typename T>
Output_HContainer<T>::Output_HContainer(hamilt::HContainer<T>* hcontainer,
std::ostream& ofs,
double sparse_threshold,
int precision)
: _hcontainer(hcontainer), _ofs(ofs), _sparse_threshold(sparse_threshold), _precision(precision)
int precision,
double value_scale)
: _hcontainer(hcontainer),
_ofs(ofs),
_sparse_threshold(sparse_threshold),
_precision(precision),
_value_scale(value_scale)
{
if (this->_sparse_threshold == -1)
{
Expand Down Expand Up @@ -133,7 +138,7 @@ void Output_HContainer<T>::write_single_R(int rx, int ry, int rz)
{
for (int icol = tmp_index[2]; icol < tmp_index[2] + tmp_index[3]; ++icol)
{
sparse_matrix.insert(irow, icol, *tmp_data);
sparse_matrix.insert(irow, icol, *tmp_data * this->_value_scale);
tmp_data++;
// to do: consider 2D block-cyclic distribution
}
Expand Down
10 changes: 6 additions & 4 deletions source/source_hamilt/module_hcontainer/output_hcontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ template <typename T>
class Output_HContainer
{
public:
Output_HContainer(hamilt::HContainer<T>* hcontainer,
std::ostream& ofs,
double sparse_threshold = -1,
int precision = -1);
Output_HContainer(hamilt::HContainer<T>* hcontainer,
std::ostream& ofs,
double sparse_threshold = -1,
int precision = -1,
double value_scale = 1.0);

// write the matrices of all R vectors to the output stream
void write(bool write_empty = false);
Expand All @@ -38,6 +39,7 @@ class Output_HContainer
std::ostream& _ofs;
double _sparse_threshold;
int _precision;
double _value_scale;
};

} // namespace hamilt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,12 @@ TEST_F(OutputHContainerTest, Write)
EXPECT_THAT(output, testing::HasSubstr(" 5.00e+00 6.00e+00 1.00e+01"));
EXPECT_THAT(output, testing::HasSubstr(" 2 3 3"));
EXPECT_THAT(output, testing::HasSubstr(" 0 0 0 2 3"));

// Output-only scaling converts units without modifying the HContainer.
hamilt::Output_HContainer<double> scaled_output_HR(&HR, std::cout, sparse_threshold, 2, 0.5);
testing::internal::CaptureStdout();
scaled_output_HR.write(0, 0, 0);
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr(" 2.50e+00 3.00e+00 5.00e+00"));
EXPECT_DOUBLE_EQ(HR.find_matrix(1, 1, 0, 0, 0)->get_pointer()[0], 5.0);
}
1 change: 1 addition & 0 deletions source/source_io/module_parameter/input_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ struct Input_para
int deepks_bandgap = 0; ///< for bandgap label. QO added 2021-12-15
std::vector<int> deepks_band_range = {-1, 0}; ///< the range of bands to calculate bandgap
int deepks_v_delta = 0; ///< for v_delta label. xuan added
bool deepks_grad = false; ///< output descriptor-gradient label intermediates for DeePKS training
bool deepks_equiv = false; ///< whether to use equivariant version of DeePKS
bool deepks_out_unittest = false; ///< if set to true, prints intermediate quantities that shall
///< be used for making unit test
Expand Down
20 changes: 19 additions & 1 deletion source/source_io/module_parameter/read_input_item_deepks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void ReadInput::item_deepks()
" -1 for vdrpre, -2 for phialpha_r and gevdm (can save memory)";
item.category = "DeePKS";
item.type = "Integer";
item.description = R"(Include V_delta/V_delta_R (Hamiltonian in k/real space) label for DeePKS training. When deepks_out_labels is true and deepks_v_delta > 0 (k space), ABACUS will output deepks_hbase.npy, deepks_vdelta.npy and deepks_htot.npy(htot=hbase+vdelta). When deepks_out_labels is true and deepks_v_delta < 0 (real space), ABACUS will output deepks_hrtot.csr, deepks_hrdelta.csr. Some more files output for different settings. NOTICE: To match the unit Normally used in DeePKS, the unit of Hamiltonian in k space is Hartree. However, currently in R space the unit is still Ry.
item.description = R"(Include V_delta/V_delta_R (Hamiltonian in k/real space) label for DeePKS training. When deepks_out_labels is true and deepks_v_delta > 0 (k space), ABACUS will output deepks_hbase.npy, deepks_vdelta.npy and deepks_htot.npy(htot=hbase+vdelta). When deepks_out_labels is true and deepks_v_delta < 0 (real space), ABACUS will output deepks_hrtot.csr, deepks_hrdelta.csr. All DeePKS energy and Hamiltonian labels are output in Hartree.
* deepks_v_delta = 1: deepks_vdpre.npy, which is used to calculate V_delta during DeePKS training.
* deepks_v_delta = 2: deepks_phialpha.npy and deepks_gevdm.npy, which can be used to calculate deepks_vdpre.npy. A recommanded method for memory saving.
* deepks_v_delta = -1: deepks_vdrpre.npy, which is used to calculate V_delta_R during DeePKS training.
Expand All @@ -307,6 +307,24 @@ void ReadInput::item_deepks()
};
this->add_item(item);
}
{
Input_Item item("deepks_grad");
item.annotation = "output descriptor-gradient label intermediates for DeePKS training";
item.category = "DeePKS";
item.type = "Boolean";
item.default_value = "False";
item.unit = "";
item.availability = "NAO basis; requires deepks_out_labels >= 1 and deepks_v_delta < 0";
read_sync_bool(input.deepks_grad);
item.check_value = [](const Input_Item& item, const Parameter& para) {
if (para.input.deepks_grad && para.input.deepks_out_labels == 0)
{
ModuleBase::WARNING_QUIT("ReadInput",
"deepks_grad requires deepks_out_labels 1");
}
};
Comment on lines +319 to +325
this->add_item(item);
}
{
Input_Item item("deepks_out_unittest");
item.annotation = "if set 1, prints intermediate quantities that shall "
Expand Down
1 change: 1 addition & 0 deletions source/source_lcao/module_deepks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if(ENABLE_MLALGO)
deepks_vdelta.cpp
deepks_vdpre.cpp
deepks_vdrpre.cpp
deepks_grad.cpp
deepks_pdm.cpp
deepks_phialpha.cpp
LCAO_deepks_io.cpp
Expand Down
Loading
Loading