Skip to content

Commit 38d3eb9

Browse files
authored
Python DFT (and Unit Test Race Condition) (#47)
* add Python DFT test * MPI safe file names in grid_from_file.cpp
1 parent 1896312 commit 38d3eb9

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

tests/cxx/unit_tests/xc/grid_from_file.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ TEST_CASE("GridFromFile") {
2727
scf::load_modules(mm);
2828
auto& mod = mm.at("Grid From File");
2929

30+
int process_rank;
31+
MPI_Comm_rank(mm.get_runtime().mpi_comm(), &process_rank);
32+
auto rank_str = std::to_string(process_rank);
33+
3034
auto h2 = test_scf::make_h2<chemist::Molecule>();
3135

3236
SECTION("file doesn't exist") {
@@ -36,7 +40,7 @@ TEST_CASE("GridFromFile") {
3640
}
3741

3842
SECTION("only three points") {
39-
std::filesystem::path p = "unit_test_pretend_h2_grid.txt";
43+
std::filesystem::path p = "only_three_points" + rank_str + ".txt";
4044
std::ofstream file(p);
4145
file << "1.0 2.0 3.0\n";
4246
file << "5.0 6.0 7.0 8.0\n";
@@ -47,7 +51,7 @@ TEST_CASE("GridFromFile") {
4751
}
4852

4953
SECTION("five numbers points") {
50-
std::filesystem::path p = "unit_test_pretend_h2_grid.txt";
54+
std::filesystem::path p = "five_numbers_points" + rank_str + ".txt";
5155
std::ofstream file(p);
5256
file << "1.0 2.0 3.0 4.0 5.0\n";
5357
file << "5.0 6.0 7.0 8.0\n";
@@ -58,7 +62,7 @@ TEST_CASE("GridFromFile") {
5862
}
5963

6064
SECTION("non-mumeric data") {
61-
std::filesystem::path p = "unit_test_pretend_h2_grid.txt";
65+
std::filesystem::path p = "non-numeric_data" + rank_str + ".txt";
6266
std::ofstream file(p);
6367
file << "1.0 2.0 3.0 hello\n";
6468
file << "5.0 6.0 7.0 8.0\n";
@@ -69,7 +73,7 @@ TEST_CASE("GridFromFile") {
6973
}
7074

7175
SECTION("good file") {
72-
std::filesystem::path p = "unit_test_pretend_h2_grid.txt";
76+
std::filesystem::path p = "good_file" + rank_str + ".txt";
7377
std::ofstream file(p);
7478
file << "1.0 2.0 3.0 4.0\n";
7579
file << "5.0 6.0 7.0 8.0\n";
@@ -89,7 +93,7 @@ TEST_CASE("GridFromFile") {
8993
}
9094

9195
SECTION("skip blank line") {
92-
std::filesystem::path p = "unit_test_pretend_h2_grid.txt";
96+
std::filesystem::path p = "skip_blank_line" + rank_str + ".txt";
9397
std::ofstream file(p);
9498
file << "1.0 2.0 3.0 4.0\n";
9599
file << "\n";

tests/python/integration_tests/driver/test_scf_driver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ def test_scf_driver_diis(self):
3333
egy = self.mm.run_as(self.ao_energy, "SCF Driver", self.aos, self.sys)
3434
self.assertAlmostEqual(np.array(egy), -74.94208027122616, places=6)
3535

36+
def test_dft_driver(self):
37+
func = chemist.qm_operator.xc_functional.PBE
38+
RKS_op = "Restricted Kohn-Sham Op"
39+
rks_op = "Restricted One-Electron Kohn-Sham Op"
40+
self.mm.change_input(RKS_op, "XC Potential", func)
41+
self.mm.change_input(rks_op, "XC Potential", func)
42+
self.mm.change_submod("Loop", "One-electron Fock operator", rks_op)
43+
self.mm.change_submod("Loop", "Fock operator", RKS_op)
44+
self.mm.change_submod("Core guess", "Build Fock Operator", rks_op)
45+
egy = self.mm.run_as(self.ao_energy, "SCF Driver", self.aos, self.sys)
46+
self.assertAlmostEqual(np.array(egy), -75.22989870343218, places=6)
47+
3648
def setUp(self):
3749
# Setup Module Manager
3850
self.mm = pp.ModuleManager(pz.runtime.RuntimeView())

0 commit comments

Comments
 (0)