diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bc1679..53596d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ if("${BUILD_TESTING}") python_mpi_test( unit_test_scf "${PYTHON_TEST_DIR}/unit_tests/run_unit_tests.py" - SUBMODULES simde chemist pluginplay parallelzone + SUBMODULES simde chemist pluginplay parallelzone tensorwrapper ) if("${INTEGRATION_TESTING}") diff --git a/tests/cxx/integration_tests/driver/scf_driver.cpp b/tests/cxx/integration_tests/driver/scf_driver.cpp index d7a562f..cf6e44b 100644 --- a/tests/cxx/integration_tests/driver/scf_driver.cpp +++ b/tests/cxx/integration_tests/driver/scf_driver.cpp @@ -38,18 +38,21 @@ TEMPLATE_LIST_TEST_CASE("SCFDriver", "", test_scf::float_types) { REQUIRE(approximately_equal(corr, e, 1E-6)); } SECTION("DFT") { - auto func = chemist::qm_operator::xc_functional::PBE; - const auto RKS_op = "Restricted Kohn-Sham Op"; - const auto rks_op = "Restricted One-Electron Kohn-Sham Op"; - mm.change_input(RKS_op, "XC Potential", func); - mm.change_input(rks_op, "XC Potential", func); - mm.change_submod("Loop", "One-electron Fock operator", rks_op); - mm.change_submod("Loop", "Fock operator", RKS_op); - mm.change_submod("Core guess", "Build Fock Operator", rks_op); - const auto e = mm.template run_as("SCF Driver", aos, h2); - pcorr->set_elem({}, -1.15207); - simde::type::tensor corr(shape_corr, std::move(pcorr)); - REQUIRE(approximately_equal(corr, e, 1E-5)); + // GauXC not currently compatible with Uncertain values + if constexpr(!tensorwrapper::types::is_uncertain_v) { + auto func = chemist::qm_operator::xc_functional::PBE; + const auto RKS_op = "Restricted Kohn-Sham Op"; + const auto rks_op = "Restricted One-Electron Kohn-Sham Op"; + mm.change_input(RKS_op, "XC Potential", func); + mm.change_input(rks_op, "XC Potential", func); + mm.change_submod("Loop", "One-electron Fock operator", rks_op); + mm.change_submod("Loop", "Fock operator", RKS_op); + mm.change_submod("Core guess", "Build Fock Operator", rks_op); + const auto e = mm.template run_as("SCF Driver", aos, h2); + pcorr->set_elem({}, -1.15207); + simde::type::tensor corr(shape_corr, std::move(pcorr)); + REQUIRE(approximately_equal(corr, e, 1E-5)); + } } } diff --git a/tests/python/integration_tests/test_scf/__init__.py b/tests/python/integration_tests/driver/__init__.py similarity index 100% rename from tests/python/integration_tests/test_scf/__init__.py rename to tests/python/integration_tests/driver/__init__.py diff --git a/tests/python/integration_tests/driver/test_scf_driver.py b/tests/python/integration_tests/driver/test_scf_driver.py new file mode 100644 index 0000000..dbb1077 --- /dev/null +++ b/tests/python/integration_tests/driver/test_scf_driver.py @@ -0,0 +1,52 @@ +# Copyright 2025 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import nux +import simde +import parallelzone as pz +import chemist +import pluginplay as pp +import nwchemex as nwx +import numpy as np +import unittest + + +class TestSCFDriver(unittest.TestCase): + + def test_scf_driver(self): + # Property Types + mol_from_str = simde.MoleculeFromString() + mol_basis_set = simde.MolecularBasisSet() + ao_energy = simde.AOEnergy() + + # Inputs + water = self.mm.at("NWX Molecules").run_as(mol_from_str, "water") + aos = self.mm.at('STO-3G').run_as(mol_basis_set, water) + sys = chemist.ChemicalSystem(water) + + # Run module + egy = self.mm.run_as(ao_energy, "SCF Driver", aos, sys) + self.assertAlmostEqual(np.array(egy), -74.94208027122616, places=6) + + def setUp(self): + self.mm = pp.ModuleManager(pz.runtime.RuntimeView()) + nux.load_modules(self.mm) + nwx.load_modules(self.mm) + self.mm.change_submod("SCF Driver", "Hamiltonian", + "Born-Oppenheimer Approximation") + self.mm.change_submod("SCF integral driver", "Fundamental matrices", + "AO integral driver") + self.mm.change_submod("Diagonalization Fock update", + "Overlap matrix builder", "Overlap") + self.mm.change_submod("Loop", "Overlap matrix builder", "Overlap") diff --git a/tests/python/integration_tests/test_scf/test_tamm_scf.py b/tests/python/integration_tests/test_tamm_scf.py similarity index 100% rename from tests/python/integration_tests/test_scf/test_tamm_scf.py rename to tests/python/integration_tests/test_tamm_scf.py diff --git a/tests/python/unit_tests/test_scf/__init__.py b/tests/python/unit_tests/eigen_solver/__init__.py similarity index 100% rename from tests/python/unit_tests/test_scf/__init__.py rename to tests/python/unit_tests/eigen_solver/__init__.py diff --git a/tests/python/unit_tests/eigen_solver/test_eigen_generalized.py b/tests/python/unit_tests/eigen_solver/test_eigen_generalized.py new file mode 100644 index 0000000..a992b63 --- /dev/null +++ b/tests/python/unit_tests/eigen_solver/test_eigen_generalized.py @@ -0,0 +1,43 @@ +# Copyright 2025 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import pluginplay as pp +import parallelzone as pz +import scf +import simde +import tensorwrapper as tw +import numpy as np + + +class TestEigenGeneralized(unittest.TestCase): + + def test_eigen_generalized(self): + # Property Type + pt = simde.GeneralizedEigenSolve() + + # Inputs + A = tw.Tensor(np.array([[1.0, 2.0], [2.0, 3.0]])) + B = tw.Tensor(np.array([[1.0, 0.0], [0.0, 1.0]])) + + # Run module + mod_name = "Generalized eigensolve via Eigen" + values, vector = self.mm.run_as(pt, mod_name, A, B) + test_values = np.array(values) + self.assertAlmostEqual(test_values[0], -0.236068, places=6) + self.assertAlmostEqual(test_values[1], 4.236068, places=6) + + def setUp(self): + self.mm = pp.ModuleManager(pz.runtime.RuntimeView()) + scf.load_modules(self.mm) diff --git a/tests/python/unit_tests/molecules.py b/tests/python/unit_tests/molecules.py deleted file mode 100644 index a6fe9ee..0000000 --- a/tests/python/unit_tests/molecules.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2023 NWChemEx-Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from chemist import Atom, Molecule, ChemicalSystem - - -def make_h2(): - mol = Molecule() - mol.push_back(Atom('H', 1, 1837.15264648179, 0.0, 0.0, 0.0)) - mol.push_back(Atom('H', 1, 1837.15264648179, 0.0, 0.0, 1.68185)) - - return ChemicalSystem(mol)