From 717f8d8c037f02cd843ba00399731e84b8b0f545 Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Wed, 28 Jan 2026 15:55:01 -0600 Subject: [PATCH 1/5] it at least compiles... --- src/scf/driver/scf_loop.cpp | 49 ++-- src/scf/eigen_solver/eigen_generalized.cpp | 61 +++-- src/scf/matrix_builder/density_matrix.cpp | 41 +-- src/scf/xc/aos_on_grid.cpp | 7 +- src/scf/xc/gau2grid.cpp | 10 +- src/scf/xc/gauxc/utilities.hpp | 18 +- src/scf/xc/libxc/libxc.cpp | 256 ++++++++++-------- tests/cxx/integration_tests/coulombs_law.cpp | 6 +- .../integration_tests/driver/scf_driver.cpp | 11 +- .../cxx/integration_tests/driver/scf_loop.cpp | 12 +- tests/cxx/integration_tests/guess/core.cpp | 7 +- tests/cxx/integration_tests/guess/sad.cpp | 7 +- .../matrix_builder/determinant_driver.cpp | 12 +- .../matrix_builder/electronic_energy.cpp | 6 +- .../integration_tests/matrix_builder/fock.cpp | 20 +- .../update/diagonalization.cpp | 5 +- tests/cxx/test_scf.hpp | 72 ++--- tests/cxx/unit_tests/coulombs_law.cpp | 11 +- .../eigen_solver/eigen_generalized.cpp | 28 +- .../matrix_builder/density_matrix.cpp | 5 +- .../cxx/unit_tests/xc/gauxc/gauxc_driver.cpp | 7 +- .../cxx/unit_tests/xc/gauxc/xc_potential.cpp | 7 +- 22 files changed, 342 insertions(+), 316 deletions(-) diff --git a/src/scf/driver/scf_loop.cpp b/src/scf/driver/scf_loop.cpp index 6b334c5..bc9f7bf 100644 --- a/src/scf/driver/scf_loop.cpp +++ b/src/scf/driver/scf_loop.cpp @@ -22,20 +22,23 @@ namespace { // Comparison between convergence metrics based on floating point type struct Kernel { - using rv_t = parallelzone::runtime::RuntimeView; + double m_tol; - explicit Kernel(rv_t rv) : m_rv(rv) {} + explicit Kernel(double tol) : m_tol(tol) {} template - auto run(const tensorwrapper::buffer::BufferBase& a, double tol) { - tensorwrapper::allocator::Eigen allocator(m_rv); - const auto& eigen_a = allocator.rebind(a); - return tensorwrapper::types::fabs(eigen_a.get_data(0)) < FloatType(tol); + auto operator()(const std::span& a) { + using tensorwrapper::types::fabs; + return fabs(a[0]) < std::decay_t(m_tol); } - - rv_t m_rv; }; +auto check_tolerance(const tensorwrapper::buffer::BufferBase& v, double tol) { + Kernel kernel(tol); + const auto& buffer = tensorwrapper::buffer::make_contiguous(v); + return tensorwrapper::buffer::visit_contiguous_buffer(kernel, buffer); +} + // Pull out nuclear-nuclear interaction term, if there is one. struct GrabNuclear : chemist::qm_operator::OperatorVisitor { using V_nn_type = simde::type::V_nn_type; @@ -76,8 +79,6 @@ using pt = simde::Optimize, WfType>; template using update_pt = simde::UpdateGuess; -using tensorwrapper::utilities::floating_point_dispatch; - MODULE_CTOR(SCFLoop) { using wf_type = simde::type::rscf_wf; description(desc); @@ -243,10 +244,9 @@ MODULE_RUN(SCFLoop) { logger.log(" dG = " + grad_norm.to_string()); // Check for convergence - Kernel k(get_runtime()); - auto e_conv = floating_point_dispatch(k, de.buffer(), e_tol); - auto g_conv = floating_point_dispatch(k, grad_norm.buffer(), g_tol); - auto dp_conv = floating_point_dispatch(k, dp_norm.buffer(), dp_tol); + auto e_conv = check_tolerance(de.buffer(), e_tol); + auto g_conv = check_tolerance(grad_norm.buffer(), g_tol); + auto dp_conv = check_tolerance(dp_norm.buffer(), dp_tol); if(e_conv && g_conv && dp_conv) converged = true; // If using DIIS and not converged, extrapolate new Fock matrix @@ -272,16 +272,19 @@ MODULE_RUN(SCFLoop) { tensor_t e_total; // e_nuclear is a double. This hack converts it to udouble (if needed) - tensorwrapper::allocator::Eigen dalloc(get_runtime()); - using tensorwrapper::types::udouble; - tensorwrapper::allocator::Eigen ualloc(get_runtime()); - - if(ualloc.can_rebind(e_old.buffer())) { - tensor_t temp(e_old); - auto val = dalloc.rebind(e_nuclear.buffer()).get_data(0); - ualloc.rebind(temp.buffer()).set_data(0, val); - e_nuclear = temp; + try { + using tensorwrapper::buffer::make_contiguous; + using tensorwrapper::types::udouble; + const auto& e_contig = make_contiguous(e_nuclear.buffer()); + auto val = wtf::fp::float_cast(e_contig.get_elem({})); + std::vector val_vector{val}; + tensorwrapper::shape::Smooth scalar{}; + tensorwrapper::buffer::Contiguous nuc_buffer(val_vector, scalar); + e_nuclear = tensor_t(scalar, std::move(nuc_buffer)); + } catch(...) { + // Nothing to do here } + e_total("") = e_old("") + e_nuclear(""); auto rv = results(); diff --git a/src/scf/eigen_solver/eigen_generalized.cpp b/src/scf/eigen_solver/eigen_generalized.cpp index 89e8947..bc70ce4 100644 --- a/src/scf/eigen_solver/eigen_generalized.cpp +++ b/src/scf/eigen_solver/eigen_generalized.cpp @@ -22,25 +22,38 @@ namespace scf::eigen_solver { namespace { struct Kernel { + std::size_t m_n_rows; + std::size_t m_n_cols; + + using tensor_t = simde::type::tensor; + using return_t = std::pair; + + Kernel(std::size_t n_rows, std::size_t n_cols) : + m_n_rows(n_rows), m_n_cols(n_cols) {} + + template + return_t operator()(const std::span& A, + const std::span& B) { + throw std::runtime_error( + "EigenGeneralized Kernel: Mixed float types not supported"); + } + template - auto run(const tensorwrapper::buffer::BufferBase& A, - const tensorwrapper::buffer::BufferBase& B, - parallelzone::runtime::RuntimeView& rv) { + return_t operator()(const std::span& A, + const std::span& B) { + using clean_t = std::decay_t; // Convert to Eigen buffers - tensorwrapper::allocator::Eigen allocator(rv); - const auto& eigen_A = allocator.rebind(A); - const auto& eigen_B = allocator.rebind(B); // Wrap the tensors in Eigen::Map objects to avoid copy - const auto* pA = eigen_A.get_immutable_data(); - const auto* pB = eigen_B.get_immutable_data(); - const auto& shape_A = eigen_A.layout().shape().as_smooth(); - auto rows = shape_A.extent(0); - auto cols = shape_A.extent(1); + const auto* pA = A.data(); + const auto* pB = B.data(); + auto rows = m_n_rows; + auto cols = m_n_cols; constexpr auto rmajor = Eigen::RowMajor; constexpr auto edynam = Eigen::Dynamic; - using matrix_type = Eigen::Matrix; + using clean_type = std::decay_t; + using matrix_type = Eigen::Matrix; using map_type = Eigen::Map; map_type A_map(pA, rows, cols); @@ -57,13 +70,15 @@ struct Kernel { tensorwrapper::layout::Physical vector_layout(vector_shape); tensorwrapper::layout::Physical matrix_layout(matrix_shape); - auto pvalues_buffer = allocator.allocate(vector_layout); - auto pvectors_buffer = allocator.allocate(matrix_layout); + using tensorwrapper::buffer::make_contiguous; + + auto pvalues_buffer = make_contiguous(vector_shape); + auto pvectors_buffer = make_contiguous(matrix_shape); for(decltype(rows) i = 0; i < rows; ++i) { - pvalues_buffer->set_elem({i}, eigen_values(i)); + pvalues_buffer.set_elem({i}, eigen_values(i)); for(decltype(cols) j = 0; j < cols; ++j) { - pvectors_buffer->set_elem({i, j}, eigen_vectors(i, j)); + pvectors_buffer.set_elem({i, j}, eigen_vectors(i, j)); } } @@ -91,13 +106,13 @@ MODULE_CTOR(EigenGeneralized) { MODULE_RUN(EigenGeneralized) { auto&& [A, B] = pt::unwrap_inputs(inputs); - using tensorwrapper::utilities::floating_point_dispatch; - - auto r = get_runtime(); - Kernel k; - const auto& A_buffer = A.buffer(); - const auto& B_buffer = B.buffer(); - auto [values, vectors] = floating_point_dispatch(k, A_buffer, B_buffer, r); + const auto& A_shape = A.logical_layout().shape().as_smooth(); + Kernel k(A_shape.extent(0), A_shape.extent(1)); + using tensorwrapper::buffer::make_contiguous; + const auto& A_buffer = make_contiguous(A.buffer()); + const auto& B_buffer = make_contiguous(B.buffer()); + using tensorwrapper::buffer::visit_contiguous_buffer; + auto [values, vectors] = visit_contiguous_buffer(k, A_buffer, B_buffer); auto rv = results(); return pt::wrap_results(rv, values, vectors); diff --git a/src/scf/matrix_builder/density_matrix.cpp b/src/scf/matrix_builder/density_matrix.cpp index 8269d93..627e95f 100644 --- a/src/scf/matrix_builder/density_matrix.cpp +++ b/src/scf/matrix_builder/density_matrix.cpp @@ -24,32 +24,32 @@ const auto desc = R"( )"; struct Kernel { + Kernel(std::size_t n_aos, std::size_t n_occ) : + m_n_aos(n_aos), m_n_occ(n_occ) {} + std::size_t m_n_aos; + std::size_t m_n_occ; + template - auto run(const tensorwrapper::buffer::BufferBase& c, std::size_t n_aos, - std::size_t n_occ) { + auto operator()(const std::span& c) { constexpr auto rmajor = Eigen::RowMajor; constexpr auto edynam = Eigen::Dynamic; - using allocator_type = tensorwrapper::allocator::Eigen; - using tensor_type = Eigen::Matrix; + using clean_type = std::decay_t; + using tensor_type = Eigen::Matrix; using const_map_type = Eigen::Map; - auto rv = c.allocator().runtime(); - allocator_type alloc(rv); - tensorwrapper::shape::Smooth p_shape{n_aos, n_aos}; - tensorwrapper::layout::Physical l(p_shape); - auto pp_buffer = alloc.allocate(l); + tensorwrapper::shape::Smooth p_shape{m_n_aos, m_n_aos}; + auto pp_buffer = + tensorwrapper::buffer::make_contiguous(p_shape); // Step 2: Grab the orbitals in the ensemble - auto& c_buffer = alloc.rebind(c); - - const_map_type c_eigen(c_buffer.get_immutable_data(), n_aos, n_aos); - auto slice = c_eigen.block(0, 0, n_aos, n_occ); + const_map_type c_eigen(c.data(), m_n_aos, m_n_aos); + auto slice = c_eigen.block(0, 0, m_n_aos, m_n_occ); // Step 3: CC_dagger tensor_type p_eigen = slice * slice.transpose(); - for(std::size_t i = 0; i < n_aos; ++i) { - for(std::size_t j = 0; j < n_aos; ++j) { - pp_buffer->set_elem({i, j}, p_eigen(i, j)); + for(std::size_t i = 0; i < m_n_aos; ++i) { + for(std::size_t j = 0; j < m_n_aos; ++j) { + pp_buffer.set_elem({i, j}, p_eigen(i, j)); } } return simde::type::tensor(p_shape, std::move(pp_buffer)); @@ -96,10 +96,11 @@ MODULE_RUN(DensityMatrix) { "contiguous slice of the orbitals."); // TODO: The need to dispatch like this goes away when TW supports slicing - using tensorwrapper::utilities::floating_point_dispatch; - Kernel k; - auto p = floating_point_dispatch(k, c.buffer(), n_aos, participants.size()); - auto rv = results(); + using tensorwrapper::buffer::visit_contiguous_buffer; + Kernel k(n_aos, participants.size()); + const auto& c_buffer = tensorwrapper::buffer::make_contiguous(c.buffer()); + auto p = visit_contiguous_buffer(k, c_buffer); + auto rv = results(); return pt::wrap_results(rv, p); } diff --git a/src/scf/xc/aos_on_grid.cpp b/src/scf/xc/aos_on_grid.cpp index 3ee3e53..cb790ea 100644 --- a/src/scf/xc/aos_on_grid.cpp +++ b/src/scf/xc/aos_on_grid.cpp @@ -40,10 +40,9 @@ MODULE_RUN(AOsOnGrid) { auto n_aos = ao_basis.n_aos(); using float_type = double; - tensorwrapper::allocator::Eigen allocator(get_runtime()); tensorwrapper::shape::Smooth matrix_shape{n_aos, n_points}; - tensorwrapper::layout::Physical layout(matrix_shape); - auto buffer = allocator.allocate(layout); + auto buffer = + tensorwrapper::buffer::make_contiguous(matrix_shape); std::vector idx{0, 0}; for(const auto& atomic_basis : ao_basis) { @@ -59,7 +58,7 @@ MODULE_RUN(AOsOnGrid) { auto norm = std::sqrt(std::pow(2.0 * exponent / M_PI, 1.5)); ao_value += norm * val; } - buffer->set_elem(idx, ao_value); + buffer.set_elem(idx, ao_value); } idx[0] += shell_i.size(); idx[1] = 0; diff --git a/src/scf/xc/gau2grid.cpp b/src/scf/xc/gau2grid.cpp index fe02556..ef8f99e 100644 --- a/src/scf/xc/gau2grid.cpp +++ b/src/scf/xc/gau2grid.cpp @@ -58,11 +58,8 @@ MODULE_RUN(Gau2Grid) { using float_type = double; auto flattened_grid = flatten_grid(grid); - tensorwrapper::allocator::Eigen allocator(get_runtime()); tensorwrapper::shape::Smooth matrix_shape{ao_basis.n_aos(), n_points}; - tensorwrapper::layout::Physical layout(matrix_shape); - auto matrix_buffer = allocator.allocate(layout); - auto matrix_data = matrix_buffer->get_mutable_data(); + std::vector matrix_data(matrix_shape.size()); std::size_t ao_i = 0; for(const auto& atomic_basis : ao_basis) { @@ -89,7 +86,7 @@ MODULE_RUN(Gau2Grid) { auto order = is_pure ? GG_SPHERICAL_CCA : GG_CARTESIAN_CCA; auto offset = ao_i * n_points; - auto shell_i_data = matrix_data + offset; + auto shell_i_data = matrix_data.data() + offset; gg_collocation(static_cast(L), static_cast(n_points), flattened_grid.data(), 3, static_cast(n_primitives), coefficients.data(), @@ -99,7 +96,8 @@ MODULE_RUN(Gau2Grid) { ao_i += n_aos; } } - + tensorwrapper::buffer::Contiguous matrix_buffer(std::move(matrix_data), + matrix_shape); simde::type::tensor collocation_matrix(matrix_shape, std::move(matrix_buffer)); diff --git a/src/scf/xc/gauxc/utilities.hpp b/src/scf/xc/gauxc/utilities.hpp index 9a28fa9..8cc9a31 100644 --- a/src/scf/xc/gauxc/utilities.hpp +++ b/src/scf/xc/gauxc/utilities.hpp @@ -26,13 +26,11 @@ auto tw_to_eigen(const tensorwrapper::Tensor& t) { auto m = t.logical_layout().shape().as_smooth().extent(1); Eigen::Matrix t_eigen(n, m); - const auto& rt = t.buffer().allocator().runtime(); - tensorwrapper::allocator::Eigen alloc(rt); - - auto t_vector = alloc.rebind(t.buffer()); - auto begin = t_vector.get_immutable_data(); - auto end = begin + (n * m); - std::copy(begin, end, t_eigen.data()); + auto t_vector = tensorwrapper::buffer::make_contiguous(t.buffer()); + auto t_data = t_vector.get_immutable_data(); + auto begin = wtf::buffer::contiguous_buffer_cast(t_data); + auto end = begin.data() + (n * m); + std::copy(begin.data(), end, t_eigen.data()); return t_eigen; } @@ -40,16 +38,14 @@ template auto eigen_to_tw( const Eigen::Matrix& t_eigen, const parallelzone::runtime::RuntimeView& rt) { - tensorwrapper::allocator::Eigen alloc(rt); auto n = static_cast(t_eigen.rows()); auto m = static_cast(t_eigen.cols()); tensorwrapper::shape::Smooth shape{n, m}; - tensorwrapper::layout::Physical layout(shape); - auto pbuffer = alloc.allocate(layout); + auto pbuffer = tensorwrapper::buffer::make_contiguous(shape); for(std::size_t i = 0; i < n; ++i) { for(std::size_t j = 0; j < m; ++j) - pbuffer->set_elem({i, j}, t_eigen(i, j)); + pbuffer.set_elem({i, j}, t_eigen(i, j)); } return tensorwrapper::Tensor(std::move(shape), std::move(pbuffer)); } diff --git a/src/scf/xc/libxc/libxc.cpp b/src/scf/xc/libxc/libxc.cpp index 2269d4b..4b68dd6 100644 --- a/src/scf/xc/libxc/libxc.cpp +++ b/src/scf/xc/libxc/libxc.cpp @@ -21,6 +21,24 @@ #endif namespace scf::xc::libxc { +namespace { +template +auto* get_pointer(tensorwrapper::buffer::BufferBase& buffer) { + using tensorwrapper::buffer::make_contiguous; + auto& contig_buffer = make_contiguous(buffer); + auto wtf_buffer = contig_buffer.get_mutable_data(); + return wtf::buffer::contiguous_buffer_cast(wtf_buffer).data(); +} + +template +const auto* get_const_pointer(const tensorwrapper::buffer::BufferBase& buffer) { + using tensorwrapper::buffer::make_contiguous; + const auto& contig_buffer = make_contiguous(buffer); + auto wtf_buffer = contig_buffer.get_immutable_data(); + return wtf::buffer::contiguous_buffer_cast(wtf_buffer) + .data(); +} +} // namespace void load_modules(pluginplay::ModuleManager& mm) { mm.add_module("LibXC Energy"); @@ -71,21 +89,18 @@ simde::type::tensor libxc_lda_energy_density( throw std::runtime_error("Failed to initialize libxc functional "); const auto& rho_buffer = rho_on_grid.buffer(); - auto& rv = rho_buffer.allocator().runtime(); - tensorwrapper::allocator::Eigen allocator(rv); - const auto* prho = allocator.rebind(rho_buffer).get_immutable_data(); + const auto* prho = get_const_pointer(rho_buffer); auto n_grid = rho_on_grid.logical_layout().shape().as_smooth().extent(0); // Buffers for exchange and correlation energy densities per particle tensorwrapper::shape::Smooth shape{n_grid}; - tensorwrapper::layout::Physical layout(shape); - auto pbuffer_x = allocator.allocate(layout); - auto pbuffer_c = allocator.allocate(layout); + auto pbuffer_x = tensorwrapper::buffer::make_contiguous(rho_buffer, shape); + auto pbuffer_c = tensorwrapper::buffer::make_contiguous(rho_buffer, shape); - auto* pepsilon_x = pbuffer_x->get_mutable_data(); - auto* pepsilon_c = pbuffer_c->get_mutable_data(); + auto* pepsilon_x = get_pointer(pbuffer_x); + auto* pepsilon_c = get_pointer(pbuffer_c); xc_lda_exc(&func_c, n_grid, prho, pepsilon_x); xc_lda_exc(&func_x, n_grid, prho, pepsilon_c); @@ -117,22 +132,19 @@ simde::type::tensor libxc_lda_energy_density_derivative( if(xc_func_init(&func_c, id_c, XC_UNPOLARIZED) != 0) throw std::runtime_error("Failed to initialize libxc functional "); - const auto& rho_buffer = rho_on_grid.buffer(); - auto& rv = rho_buffer.allocator().runtime(); - tensorwrapper::allocator::Eigen allocator(rv); - const auto* prho = allocator.rebind(rho_buffer).get_immutable_data(); + const auto& rho_buffer = make_contiguous(rho_on_grid.buffer()); + const auto* prho = get_const_pointer(rho_buffer); auto n_grid = rho_on_grid.logical_layout().shape().as_smooth().extent(0); // Buffers for derivative of exchange and correlation energy densities tensorwrapper::shape::Smooth shape{n_grid}; - tensorwrapper::layout::Physical layout(shape); - auto pbuffer_x = allocator.allocate(layout); - auto pbuffer_c = allocator.allocate(layout); + auto pbuffer_x = make_contiguous(rho_buffer, shape); + auto pbuffer_c = make_contiguous(rho_buffer, shape); - auto* pdepsilon_x = pbuffer_x->get_mutable_data(); - auto* pdepsilon_c = pbuffer_c->get_mutable_data(); + auto* pdepsilon_x = get_pointer(pbuffer_x); + auto* pdepsilon_c = get_pointer(pbuffer_c); xc_lda_vxc(&func_c, n_grid, prho, pdepsilon_x); xc_lda_vxc(&func_x, n_grid, prho, pdepsilon_c); @@ -153,15 +165,15 @@ simde::type::tensor libxc_lda_energy_density_derivative( } simde::type::tensor tensorify_weights(const chemist::Grid& grid, - parallelzone::runtime::RuntimeView rv) { + parallelzone::runtime::RuntimeView) { auto n_grid = grid.size(); - tensorwrapper::allocator::Eigen allocator(rv); tensorwrapper::shape::Smooth shape{n_grid}; - tensorwrapper::layout::Physical layout(shape); - auto weight_buffer = allocator.allocate(layout); + std::vector weights(n_grid); for(std::size_t i = 0; i < n_grid; ++i) { - weight_buffer->set_elem({i}, grid.at(i).weight()); + weights[i] = grid.at(i).weight(); } + using namespace tensorwrapper::buffer; + auto weight_buffer = Contiguous(std::move(weights), shape); return simde::type::tensor(shape, std::move(weight_buffer)); } @@ -170,127 +182,137 @@ namespace { // A(m,i) = w(i) * B(m,i); struct WeightMatrixKernel { using buffer_base = tensorwrapper::buffer::BufferBase; + using tensor_type = simde::type::tensor; - template - auto run(const buffer_base& w, const buffer_base& b, - parallelzone::runtime::RuntimeView& rv) { - tensorwrapper::allocator::Eigen allocator(rv); - - const auto& eigen_w = allocator.rebind(w); - const auto& eigen_b = allocator.rebind(b); - - const auto* pw = eigen_w.get_immutable_data(); - const auto* pb = eigen_b.get_immutable_data(); + WeightMatrixKernel(std::size_t n_aos, std::size_t n_grid) : + m_n_aos(n_aos), m_n_grid(n_grid) {} - const auto& shape_b = eigen_b.layout().shape().as_smooth(); - auto n_aos = shape_b.extent(0); - auto n_grid = shape_b.extent(1); + template + tensor_type operator()(const std::span& w, + const std::span& b) { + throw std::runtime_error( + "WeightMatrixKernel: Mixed float types not supported"); + } - tensorwrapper::shape::Smooth rv_shape{n_aos, n_grid}; - tensorwrapper::layout::Physical rv_layout(rv_shape); - auto rv_buffer = allocator.allocate(rv_layout); + template + tensor_type operator()(const std::span& w, + const std::span& b) { + tensorwrapper::shape::Smooth rv_shape{m_n_aos, m_n_grid}; + using clean_type = std::remove_cv_t; + std::vector rv_buffer(m_n_aos * m_n_grid); // AOs on rows, grid points on columns - for(std::size_t grid_i = 0; grid_i < n_grid; ++grid_i) { - for(std::size_t ao_i = 0; ao_i < n_aos; ++ao_i) { - auto value = pw[grid_i] * pb[ao_i * n_grid + grid_i]; - rv_buffer->set_elem(std::vector{ao_i, grid_i}, value); + for(std::size_t grid_i = 0; grid_i < m_n_grid; ++grid_i) { + for(std::size_t ao_i = 0; ao_i < m_n_aos; ++ao_i) { + auto value = w[grid_i] * b[ao_i * m_n_grid + grid_i]; + rv_buffer[ao_i * m_n_grid + grid_i] = value; } } - return simde::type::tensor(rv_shape, std::move(rv_buffer)); + auto contig_buffer = + tensorwrapper::buffer::Contiguous(std::move(rv_buffer), rv_shape); + return simde::type::tensor(rv_shape, std::move(contig_buffer)); } + + std::size_t m_n_aos; + std::size_t m_n_grid; }; // Does A(m,i) = 1/sqrt(w(m)) * B(m,i); struct NormalizeKernel { using buffer_base = tensorwrapper::buffer::BufferBase; - template - auto run(const buffer_base& w, const buffer_base& b, - parallelzone::runtime::RuntimeView& rv) { - tensorwrapper::allocator::Eigen allocator(rv); - - const auto& eigen_w = allocator.rebind(w); - const auto& eigen_b = allocator.rebind(b); + using tensor_type = simde::type::tensor; - const auto* pw = eigen_w.get_immutable_data(); - const auto* pb = eigen_b.get_immutable_data(); + NormalizeKernel(std::size_t n_aos, std::size_t n_grid) : + m_n_aos(n_aos), m_n_grid(n_grid) {} - const auto& shape_b = eigen_b.layout().shape().as_smooth(); - auto n_aos = shape_b.extent(0); - auto n_grid = shape_b.extent(1); + template + tensor_type operator()(const std::span& w, + const std::span& b) { + throw std::runtime_error( + "NormalizeKernel: Mixed float types not supported"); + } - tensorwrapper::shape::Smooth rv_shape{n_aos, n_grid}; - tensorwrapper::layout::Physical rv_layout(rv_shape); - auto rv_buffer = allocator.allocate(rv_layout); + template + tensor_type operator()(const std::span& w, + const std::span& b) { + tensorwrapper::shape::Smooth rv_shape{m_n_aos, m_n_grid}; + using clean_type = std::remove_cv_t; + std::vector rv_buffer(m_n_aos * m_n_grid); // AOs on rows, grid points on columns - for(std::size_t grid_i = 0; grid_i < n_grid; ++grid_i) { - for(std::size_t ao_i = 0; ao_i < n_aos; ++ao_i) { + for(std::size_t grid_i = 0; grid_i < m_n_grid; ++grid_i) { + for(std::size_t ao_i = 0; ao_i < m_n_aos; ++ao_i) { if constexpr(std::is_same_v) { - auto new_weight = 1.0 / std::sqrt(pw[ao_i]); - auto value = new_weight * pb[ao_i * n_grid + grid_i]; - rv_buffer->set_elem(std::vector{ao_i, grid_i}, value); + auto new_weight = 1.0 / std::sqrt(w[ao_i]); + auto value = new_weight * b[ao_i * m_n_grid + grid_i]; + rv_buffer[ao_i * m_n_grid + grid_i] = value; } else { throw std::runtime_error( "Normalization not implemented for uncertain floats"); } } } - return simde::type::tensor(rv_shape, std::move(rv_buffer)); + auto cbuffer = + tensorwrapper::buffer::Contiguous(std::move(rv_buffer), rv_shape); + return simde::type::tensor(rv_shape, std::move(cbuffer)); } + + std::size_t m_n_aos; + std::size_t m_n_grid; }; // Does rho(i) = X(n,i) * aos(n,i) or rh(n) = X(n,i) * aos(n,i) struct BatchedDotKernel { using buffer_base = tensorwrapper::buffer::BufferBase; + using tensor_type = simde::type::tensor; bool m_sum_row = true; - - BatchedDotKernel() = default; - explicit BatchedDotKernel(bool sum_row) : m_sum_row(sum_row) {} + std::size_t m_n_grid; + std::size_t m_n_aos; + + BatchedDotKernel(std::size_t n_aos, std::size_t n_grid, + bool sum_row = true) : + m_sum_row(true), m_n_grid(n_grid), m_n_aos(n_aos) {} + + template + tensor_type operator()(const std::span& w, + const std::span& b) { + throw std::runtime_error( + "BatchedDotKernel: Mixed float types not supported"); + } template - auto run(const buffer_base& aos_on_grid, const buffer_base& X, - parallelzone::runtime::RuntimeView& rv) { - tensorwrapper::allocator::Eigen allocator(rv); - - const auto& eigen_aos_on_grid = allocator.rebind(aos_on_grid); - const auto& eigen_X = allocator.rebind(X); - - const auto* paos_on_grid = eigen_aos_on_grid.get_immutable_data(); - const auto* pX = eigen_X.get_immutable_data(); - - const auto& shape_X = eigen_X.layout().shape().as_smooth(); - auto n_aos = shape_X.extent(0); - auto n_grid = shape_X.extent(1); - - auto out_size = m_sum_row ? n_grid : n_aos; + tensor_type operator()(const std::span& aos_on_grid, + const std::span& X) { + auto out_size = m_sum_row ? m_n_grid : m_n_aos; tensorwrapper::shape::Smooth rv_shape{out_size}; - tensorwrapper::layout::Physical rv_layout(rv_shape); - auto rv_buffer = allocator.allocate(rv_layout); + using clean_type = std::remove_cv_t; + std::vector rv_buffer(out_size); // AOs on rows, grid points on columns if(m_sum_row) { - for(std::size_t grid_i = 0; grid_i < n_grid; ++grid_i) { - FloatType sum = 0.0; - for(std::size_t ao_i = 0; ao_i < n_aos; ++ao_i) { - const auto idx = ao_i * n_grid + grid_i; - sum += paos_on_grid[idx] * pX[idx]; + for(std::size_t grid_i = 0; grid_i < m_n_grid; ++grid_i) { + clean_type sum = 0.0; + for(std::size_t ao_i = 0; ao_i < m_n_aos; ++ao_i) { + const auto idx = ao_i * m_n_grid + grid_i; + sum += aos_on_grid[idx] * X[idx]; } - rv_buffer->set_elem(std::vector{grid_i}, sum); + rv_buffer[grid_i] = sum; } } else { - for(std::size_t ao_i = 0; ao_i < n_aos; ++ao_i) { - FloatType sum = 0.0; - for(std::size_t grid_i = 0; grid_i < n_grid; ++grid_i) { - const auto idx = ao_i * n_grid + grid_i; - sum += paos_on_grid[idx] * pX[idx]; + for(std::size_t ao_i = 0; ao_i < m_n_aos; ++ao_i) { + clean_type sum = 0.0; + for(std::size_t grid_i = 0; grid_i < m_n_grid; ++grid_i) { + const auto idx = ao_i * m_n_grid + grid_i; + sum += aos_on_grid[idx] * X[idx]; } - rv_buffer->set_elem(std::vector{ao_i}, sum); + rv_buffer[ao_i] = sum; } } - return simde::type::tensor(rv_shape, std::move(rv_buffer)); + tensorwrapper::buffer::Contiguous cbuffer(std::move(rv_buffer), + rv_shape); + return simde::type::tensor(rv_shape, std::move(cbuffer)); } }; @@ -298,26 +320,40 @@ struct BatchedDotKernel { simde::type::tensor weight_a_matrix(const simde::type::tensor& w, const simde::type::tensor& b) { - using tensorwrapper::utilities::floating_point_dispatch; - WeightMatrixKernel k; - auto runtime = b.buffer().allocator().runtime(); - return floating_point_dispatch(k, w.buffer(), b.buffer(), runtime); + using tensorwrapper::buffer::make_contiguous; + using tensorwrapper::buffer::visit_contiguous_buffer; + auto shape = b.logical_layout().shape().as_smooth(); + auto n_aos = shape.extent(0); + auto n_grid = shape.extent(1); + WeightMatrixKernel k(n_aos, n_grid); + const auto& b_buffer = make_contiguous(b.buffer()); + const auto& w_buffer = make_contiguous(w.buffer()); + return visit_contiguous_buffer(k, w_buffer, b_buffer); } simde::type::tensor normalize_row(const simde::type::tensor& w, const simde::type::tensor& b) { - using tensorwrapper::utilities::floating_point_dispatch; - NormalizeKernel k; - auto runtime = b.buffer().allocator().runtime(); - return floating_point_dispatch(k, w.buffer(), b.buffer(), runtime); + using tensorwrapper::buffer::make_contiguous; + using tensorwrapper::buffer::visit_contiguous_buffer; + auto shape = b.logical_layout().shape().as_smooth(); + auto n_aos = shape.extent(0); + auto n_grid = shape.extent(1); + NormalizeKernel k(n_aos, n_grid); + const auto& b_buffer = make_contiguous(b.buffer()); + const auto& w_buffer = make_contiguous(w.buffer()); + return visit_contiguous_buffer(k, w_buffer, b_buffer); } simde::type::tensor batched_dot(const simde::type::tensor& aos_on_grid, const simde::type::tensor& X, bool sum_row) { - using tensorwrapper::utilities::floating_point_dispatch; - BatchedDotKernel k(sum_row); - auto rv = X.buffer().allocator().runtime(); - return floating_point_dispatch(std::move(k), aos_on_grid.buffer(), - X.buffer(), rv); + using tensorwrapper::buffer::make_contiguous; + using tensorwrapper::buffer::visit_contiguous_buffer; + auto shape = X.logical_layout().shape().as_smooth(); + auto n_aos = shape.extent(0); + auto n_grid = shape.extent(1); + BatchedDotKernel k(n_aos, n_grid, sum_row); + const auto& aos_on_grid_buffer = make_contiguous(aos_on_grid.buffer()); + const auto& X_buffer = make_contiguous(X.buffer()); + return visit_contiguous_buffer(std::move(k), aos_on_grid_buffer, X_buffer); } } // namespace scf::xc::libxc diff --git a/tests/cxx/integration_tests/coulombs_law.cpp b/tests/cxx/integration_tests/coulombs_law.cpp index 8fe56a4..f552c84 100644 --- a/tests/cxx/integration_tests/coulombs_law.cpp +++ b/tests/cxx/integration_tests/coulombs_law.cpp @@ -24,9 +24,9 @@ TEMPLATE_LIST_TEST_CASE("CoulombsLaw", "", test_scf::float_types) { auto mm = test_scf::load_modules(); auto& mod = mm.at("Coulomb's Law"); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); tensorwrapper::shape::Smooth shape_corr{}; - auto pcorr = alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); + using tensorwrapper::buffer::make_contiguous; + auto pcorr = make_contiguous(shape_corr); using tensorwrapper::operations::approximately_equal; auto h2_nuclei = test_scf::make_h2(); @@ -37,7 +37,7 @@ TEMPLATE_LIST_TEST_CASE("CoulombsLaw", "", test_scf::float_types) { auto e_nuclear = mod.run_as(qs, qs); - pcorr->set_elem({}, 0.71510297482837526); + pcorr.set_elem({}, 0.71510297482837526); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e_nuclear, 1E-6)); } diff --git a/tests/cxx/integration_tests/driver/scf_driver.cpp b/tests/cxx/integration_tests/driver/scf_driver.cpp index 50a6450..d229a69 100644 --- a/tests/cxx/integration_tests/driver/scf_driver.cpp +++ b/tests/cxx/integration_tests/driver/scf_driver.cpp @@ -22,17 +22,16 @@ using tensorwrapper::operations::approximately_equal; TEMPLATE_LIST_TEST_CASE("SCFDriver", "", test_scf::float_types) { using float_type = TestType; auto mm = test_scf::load_modules(); - - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); + using tensorwrapper::buffer::make_contiguous; tensorwrapper::shape::Smooth shape_corr{}; - auto pcorr = alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); + auto pcorr = make_contiguous(shape_corr); SECTION("H2") { auto h2 = test_scf::make_h2(); auto aos = test_scf::h2_aos().ao_basis_set(); SECTION("SCF") { - pcorr->set_elem({}, -1.1167592336); + pcorr.set_elem({}, -1.1167592336); simde::type::tensor corr(shape_corr, std::move(pcorr)); const auto e = mm.template run_as("SCF Driver", aos, h2); REQUIRE(approximately_equal(corr, e, 1E-6)); @@ -49,7 +48,7 @@ TEMPLATE_LIST_TEST_CASE("SCFDriver", "", test_scf::float_types) { 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); + pcorr.set_elem({}, -1.15207); simde::type::tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-5)); } @@ -67,7 +66,7 @@ TEMPLATE_LIST_TEST_CASE("SCFDriver", "", test_scf::float_types) { simde::type::chemical_system h2_dimer_sys(h2_dimer_mol); const auto e = mm.template run_as("SCF Driver", ao_bs, h2_dimer_sys); - pcorr->set_elem({}, -2.2260535919670001); + pcorr.set_elem({}, -2.2260535919670001); simde::type::tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } diff --git a/tests/cxx/integration_tests/driver/scf_loop.cpp b/tests/cxx/integration_tests/driver/scf_loop.cpp index 240dc64..60ce0ba 100644 --- a/tests/cxx/integration_tests/driver/scf_loop.cpp +++ b/tests/cxx/integration_tests/driver/scf_loop.cpp @@ -32,9 +32,9 @@ TEMPLATE_LIST_TEST_CASE("SCFLoop", "", test_scf::float_types) { auto mm = test_scf::load_modules(); auto& mod = mm.at("Loop"); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); + using tensorwrapper::buffer::make_contiguous; tensorwrapper::shape::Smooth shape_corr{}; - auto pcorr = alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); + auto pcorr = make_contiguous(shape_corr); using tensorwrapper::operations::approximately_equal; SECTION("H2") { @@ -47,14 +47,14 @@ TEMPLATE_LIST_TEST_CASE("SCFLoop", "", test_scf::float_types) { mod.change_input("DIIS", true); const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr->set_elem({}, -1.1167592336); + pcorr.set_elem({}, -1.1167592336); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } SECTION("With DIIS") { const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr->set_elem({}, -1.1167592336); + pcorr.set_elem({}, -1.1167592336); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } @@ -70,7 +70,7 @@ TEMPLATE_LIST_TEST_CASE("SCFLoop", "", test_scf::float_types) { mod.change_input("DIIS", true); const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr->set_elem({}, -2.807783957539); + pcorr.set_elem({}, -2.807783957539); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } @@ -78,7 +78,7 @@ TEMPLATE_LIST_TEST_CASE("SCFLoop", "", test_scf::float_types) { SECTION("With DIIS") { const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr->set_elem({}, -2.807783957539); + pcorr.set_elem({}, -2.807783957539); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } diff --git a/tests/cxx/integration_tests/guess/core.cpp b/tests/cxx/integration_tests/guess/core.cpp index 9faf9a9..0c64c61 100644 --- a/tests/cxx/integration_tests/guess/core.cpp +++ b/tests/cxx/integration_tests/guess/core.cpp @@ -34,10 +34,11 @@ TEMPLATE_LIST_TEST_CASE("Core", "", test_scf::float_types) { REQUIRE(psi.orbital_indices() == occs); REQUIRE(psi.orbitals().from_space() == aos); const auto& evals = psi.orbitals().diagonalized_matrix(); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); tensorwrapper::shape::Smooth shape_corr{2}; - auto pbuffer = alloc.construct({-1.25330893, -0.47506974}); - tensorwrapper::Tensor corr(shape_corr, std::move(pbuffer)); + std::vector corr_buffer{-1.25330893, -0.47506974}; + tensorwrapper::buffer::Contiguous buffer(std::move(corr_buffer), + shape_corr); + tensorwrapper::Tensor corr(shape_corr, std::move(buffer)); using tensorwrapper::operations::approximately_equal; REQUIRE(approximately_equal(corr, evals, 1E-6)); diff --git a/tests/cxx/integration_tests/guess/sad.cpp b/tests/cxx/integration_tests/guess/sad.cpp index 63ccaa5..58cdcd0 100644 --- a/tests/cxx/integration_tests/guess/sad.cpp +++ b/tests/cxx/integration_tests/guess/sad.cpp @@ -29,8 +29,7 @@ using initial_rho_pt = simde::InitialDensity; using tensorwrapper::operations::approximately_equal; TEMPLATE_LIST_TEST_CASE("SAD", "", test_scf::float_types) { - using float_type = TestType; - using allocator_type = tensorwrapper::allocator::Eigen; + using float_type = TestType; auto mm = test_scf::load_modules(); auto aos = test_scf::h2_aos(); @@ -42,9 +41,9 @@ TEMPLATE_LIST_TEST_CASE("SAD", "", test_scf::float_types) { const auto& evals = psi.orbitals().diagonalized_matrix(); occ_index occs{0}; - allocator_type alloc(rt); shape_type shape_corr{2}; - auto pbuffer = alloc.construct({-0.498376, 0.594858}); + std::vector buffer{-0.498376, 0.594858}; + tensorwrapper::buffer::Contiguous pbuffer(std::move(buffer), shape_corr); tensor corr(shape_corr, std::move(pbuffer)); REQUIRE(psi.orbital_indices() == occs); diff --git a/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp b/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp index a89c460..f2e3900 100644 --- a/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp +++ b/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp @@ -37,9 +37,9 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { wf_type psi(index_set{0}, test_scf::h2_cmos()); simde::type::many_electrons es{2}; - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); + using tensorwrapper::buffer::make_contiguous; tensorwrapper::shape::Smooth shape_corr{}; - auto pcorr = alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); + auto pcorr = make_contiguous(shape_corr); using tensorwrapper::operations::approximately_equal; SECTION("Calling Kinetic") { @@ -48,7 +48,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& T = mod.template run_as>(copy_braket); - pcorr->set_elem({}, 0.637692); + pcorr.set_elem({}, 0.637692); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, T, 1E-6)); } @@ -60,7 +60,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& V = mod.template run_as>(copy_braket); - pcorr->set_elem({}, -1.96830777255516853); + pcorr.set_elem({}, -1.96830777255516853); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, V, 1E-6)); } @@ -72,7 +72,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& J = mod.template run_as>(copy_braket); - pcorr->set_elem({}, 0.76056339681664897); + pcorr.set_elem({}, 0.76056339681664897); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, J, 1E-6)); } @@ -84,7 +84,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& K = mod.template run_as>(copy_braket); - pcorr->set_elem({}, 0.76056339681664897); + pcorr.set_elem({}, 0.76056339681664897); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, K, 1E-6)); } diff --git a/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp b/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp index 82de8b0..ae69fc5 100644 --- a/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp +++ b/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp @@ -29,9 +29,9 @@ TEMPLATE_LIST_TEST_CASE("ElectronicEnergy", "", test_scf::float_types) { using wf_type = simde::type::rscf_wf; using index_set = typename wf_type::orbital_index_set_type; - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); + using tensorwrapper::buffer::make_contiguous; tensorwrapper::shape::Smooth shape_corr{}; - auto pcorr = alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); + auto pcorr = make_contiguous(shape_corr); using tensorwrapper::operations::approximately_equal; wf_type psi(index_set{0}, test_scf::h2_cmos()); @@ -52,7 +52,7 @@ TEMPLATE_LIST_TEST_CASE("ElectronicEnergy", "", test_scf::float_types) { const auto& E_elec = mod.template run_as>(braket); - pcorr->set_elem({}, -1.90066758625308307); + pcorr.set_elem({}, -1.90066758625308307); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, E_elec, 1E-6)); } diff --git a/tests/cxx/integration_tests/matrix_builder/fock.cpp b/tests/cxx/integration_tests/matrix_builder/fock.cpp index 7378ec3..520db4f 100644 --- a/tests/cxx/integration_tests/matrix_builder/fock.cpp +++ b/tests/cxx/integration_tests/matrix_builder/fock.cpp @@ -29,10 +29,8 @@ TEMPLATE_LIST_TEST_CASE("Fock Matrix Builder", "", test_scf::float_types) { auto aos = test_scf::h2_aos(); using tensorwrapper::operations::approximately_equal; - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); tensorwrapper::shape::Smooth shape_corr{2, 2}; - tensorwrapper::layout::Physical l(shape_corr); - auto pcorr = alloc.allocate(l); + auto pcorr = tensorwrapper::buffer::make_contiguous(shape_corr); SECTION("No J or K") { auto h2 = test_scf::make_h2(); @@ -44,10 +42,10 @@ TEMPLATE_LIST_TEST_CASE("Fock Matrix Builder", "", test_scf::float_types) { chemist::braket::BraKet f_mn(aos, f_e, aos); const auto& F = mod.template run_as(f_mn); - pcorr->set_elem({0, 0}, -1.120958); - pcorr->set_elem({0, 1}, -0.959374); - pcorr->set_elem({1, 0}, -0.959374); - pcorr->set_elem({1, 1}, -1.120958); + pcorr.set_elem({0, 0}, -1.120958); + pcorr.set_elem({0, 1}, -0.959374); + pcorr.set_elem({1, 0}, -0.959374); + pcorr.set_elem({1, 1}, -1.120958); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); @@ -59,10 +57,10 @@ TEMPLATE_LIST_TEST_CASE("Fock Matrix Builder", "", test_scf::float_types) { chemist::braket::BraKet f_mn(aos, f_e, aos); const auto& F = mod.template run_as(f_mn); - pcorr->set_elem({0, 0}, -0.319459); - pcorr->set_elem({0, 1}, -0.571781); - pcorr->set_elem({1, 0}, -0.571781); - pcorr->set_elem({1, 1}, -0.319459); + pcorr.set_elem({0, 0}, -0.319459); + pcorr.set_elem({0, 1}, -0.571781); + pcorr.set_elem({1, 0}, -0.571781); + pcorr.set_elem({1, 1}, -0.319459); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); diff --git a/tests/cxx/integration_tests/update/diagonalization.cpp b/tests/cxx/integration_tests/update/diagonalization.cpp index cd50f23..65aba77 100644 --- a/tests/cxx/integration_tests/update/diagonalization.cpp +++ b/tests/cxx/integration_tests/update/diagonalization.cpp @@ -48,9 +48,10 @@ TEMPLATE_LIST_TEST_CASE("Diagaonalization", "", test_scf::float_types) { // Check orbital energies const auto& evals = psi.orbitals().diagonalized_matrix(); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); - auto corr_buffer = alloc.construct({-1.25330893, -0.47506974}); + std::vector corr_data{-1.25330893, -0.47506974}; tensorwrapper::shape::Smooth corr_shape{2}; + using tensorwrapper::buffer::Contiguous; + Contiguous corr_buffer(std::move(corr_data), corr_shape); tensorwrapper::Tensor corr(corr_shape, std::move(corr_buffer)); using tensorwrapper::operations::approximately_equal; diff --git a/tests/cxx/test_scf.hpp b/tests/cxx/test_scf.hpp index 4fc8175..7514b5d 100644 --- a/tests/cxx/test_scf.hpp +++ b/tests/cxx/test_scf.hpp @@ -163,60 +163,48 @@ inline auto he_aos() { template inline auto h2_mos() { - using mos_type = simde::type::mos; - using tensor_type = typename mos_type::transform_type; - using allocator_type = tensorwrapper::allocator::Eigen; - allocator_type alloc(parallelzone::runtime::RuntimeView{}); + using mos_type = simde::type::mos; + using tensor_type = typename mos_type::transform_type; tensorwrapper::shape::Smooth shape{2, 2}; - tensorwrapper::layout::Physical l(shape); - auto c_buffer = alloc.allocate(l); - c_buffer->set_elem({0, 0}, -0.565516); - c_buffer->set_elem({0, 1}, -1.07019); - c_buffer->set_elem({1, 0}, -0.565516); - c_buffer->set_elem({1, 1}, 1.07019); + auto c_buffer = tensorwrapper::buffer::make_contiguous(shape); + c_buffer.set_elem({0, 0}, -0.565516); + c_buffer.set_elem({0, 1}, -1.07019); + c_buffer.set_elem({1, 0}, -0.565516); + c_buffer.set_elem({1, 1}, 1.07019); tensor_type t(shape, std::move(c_buffer)); return mos_type(h2_aos(), std::move(t)); } template inline auto he_mos() { - using mos_type = simde::type::mos; - using tensor_type = typename mos_type::transform_type; - using allocator_type = tensorwrapper::allocator::Eigen; - allocator_type alloc(parallelzone::runtime::RuntimeView{}); + using mos_type = simde::type::mos; + using tensor_type = typename mos_type::transform_type; tensorwrapper::shape::Smooth shape{1, 1}; - tensorwrapper::layout::Physical l(shape); - auto c_buffer = alloc.allocate(l); - c_buffer->set_elem({0, 0}, 1.0000); + auto c_buffer = tensorwrapper::buffer::make_contiguous(shape); + c_buffer.set_elem({0, 0}, 1.0000); tensor_type t(shape, std::move(c_buffer)); return mos_type(he_aos(), std::move(t)); } template inline auto h2_cmos() { - using cmos_type = simde::type::cmos; - using tensor_type = typename cmos_type::transform_type; - using allocator_type = tensorwrapper::allocator::Eigen; - allocator_type alloc(parallelzone::runtime::RuntimeView{}); + using cmos_type = simde::type::cmos; + using tensor_type = typename cmos_type::transform_type; tensorwrapper::shape::Smooth shape{2}; - tensorwrapper::layout::Physical l(shape); - auto e_buffer = alloc.allocate(l); - e_buffer->set_elem({0}, -1.25330893); - e_buffer->set_elem({1}, -0.47506974); + auto e_buffer = tensorwrapper::buffer::make_contiguous(shape); + e_buffer.set_elem({0}, -1.25330893); + e_buffer.set_elem({1}, -0.47506974); tensor_type e(shape, std::move(e_buffer)); return cmos_type(std::move(e), h2_aos(), h2_mos().transform()); } template inline auto he_cmos() { - using cmos_type = simde::type::cmos; - using tensor_type = typename cmos_type::transform_type; - using allocator_type = tensorwrapper::allocator::Eigen; - allocator_type alloc(parallelzone::runtime::RuntimeView{}); + using cmos_type = simde::type::cmos; + using tensor_type = typename cmos_type::transform_type; tensorwrapper::shape::Smooth shape{1}; - tensorwrapper::layout::Physical l(shape); - auto e_buffer = alloc.allocate(l); - e_buffer->set_elem({0}, -0.876036); + auto e_buffer = tensorwrapper::buffer::make_contiguous(shape); + e_buffer.set_elem({0}, -0.876036); tensor_type e(shape, std::move(e_buffer)); return cmos_type(std::move(e), he_aos(), he_mos().transform()); } @@ -238,26 +226,22 @@ inline auto he_wave_function() { template inline auto h2_density() { - using density_type = simde::type::decomposable_e_density; - using tensor_type = typename density_type::value_type; - using allocator_type = tensorwrapper::allocator::Eigen; - allocator_type alloc(parallelzone::runtime::RuntimeView{}); + using density_type = simde::type::decomposable_e_density; + using tensor_type = typename density_type::value_type; tensorwrapper::shape::Smooth shape{2, 2}; - tensorwrapper::layout::Physical l(shape); - auto pbuffer = alloc.construct(l, 0.31980835); + FloatType init{0.31980835}; + auto pbuffer = tensorwrapper::buffer::make_contiguous(shape, init); tensor_type t(shape, std::move(pbuffer)); return density_type(std::move(t), h2_mos()); } template inline auto he_density() { - using density_type = simde::type::decomposable_e_density; - using tensor_type = typename density_type::value_type; - using allocator_type = tensorwrapper::allocator::Eigen; - allocator_type alloc(parallelzone::runtime::RuntimeView{}); + using density_type = simde::type::decomposable_e_density; + using tensor_type = typename density_type::value_type; tensorwrapper::shape::Smooth shape{1, 1}; - tensorwrapper::layout::Physical l(shape); - auto pbuffer = alloc.construct(l, 1.000); + FloatType init{1.000}; + auto pbuffer = tensorwrapper::buffer::make_contiguous(shape, init); tensor_type t(shape, std::move(pbuffer)); return density_type(std::move(t), he_mos()); } diff --git a/tests/cxx/unit_tests/coulombs_law.cpp b/tests/cxx/unit_tests/coulombs_law.cpp index d7ad445..628c9e3 100644 --- a/tests/cxx/unit_tests/coulombs_law.cpp +++ b/tests/cxx/unit_tests/coulombs_law.cpp @@ -28,9 +28,8 @@ TEST_CASE("CoulombsLaw") { scf::load_modules(mm); auto& mod = mm.at("Coulomb's Law"); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); tensorwrapper::shape::Smooth shape_corr{}; - auto pcorr = alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); + auto pcorr = tensorwrapper::buffer::make_contiguous(shape_corr); using tensorwrapper::operations::approximately_equal; using charge_type = typename simde::type::charges::value_type; @@ -43,21 +42,21 @@ TEST_CASE("CoulombsLaw") { SECTION("empty points") { auto e = mod.run_as(empty, empty); - pcorr->set_elem({}, 0.0); + pcorr.set_elem({}, 0.0); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } SECTION("charges w/ itself") { auto e = mod.run_as(qs, qs); - pcorr->set_elem({}, -1.0103629710818451); + pcorr.set_elem({}, -1.0103629710818451); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } SECTION("charges w/ empty") { auto e = mod.run_as(qs, empty); - pcorr->set_elem({}, 0.0); + pcorr.set_elem({}, 0.0); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } @@ -66,7 +65,7 @@ TEST_CASE("CoulombsLaw") { simde::type::charges qs0{q0}; simde::type::charges qs12{q1, q2}; auto e = mod.run_as(qs0, qs12); - pcorr->set_elem({}, -0.1443375672974065); + pcorr.set_elem({}, -0.1443375672974065); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } diff --git a/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp b/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp index 9880f72..71c4d3f 100644 --- a/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp +++ b/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp @@ -27,28 +27,28 @@ TEMPLATE_LIST_TEST_CASE("EigenGeneralized", "", test_scf::float_types) { auto& mod = mm.at("Generalized eigensolve via Eigen"); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); tensorwrapper::shape::Smooth shape{2, 2}; - tensorwrapper::layout::Physical l(shape); - auto A_buffer = alloc.allocate(l); - A_buffer->set_elem({0, 0}, 1.0); - A_buffer->set_elem({0, 1}, 2.0); - A_buffer->set_elem({1, 0}, 2.0); - A_buffer->set_elem({1, 1}, 3.0); - - auto B_buffer = alloc.allocate(l); - B_buffer->set_elem({0, 0}, 1.0); - B_buffer->set_elem({0, 1}, 0.0); - B_buffer->set_elem({1, 0}, 0.0); - B_buffer->set_elem({1, 1}, 1.0); + using tensorwrapper::buffer::make_contiguous; + auto A_buffer = make_contiguous(shape); + A_buffer.set_elem({0, 0}, 1.0); + A_buffer.set_elem({0, 1}, 2.0); + A_buffer.set_elem({1, 0}, 2.0); + A_buffer.set_elem({1, 1}, 3.0); + + auto B_buffer = make_contiguous(shape); + B_buffer.set_elem({0, 0}, 1.0); + B_buffer.set_elem({0, 1}, 0.0); + B_buffer.set_elem({1, 0}, 0.0); + B_buffer.set_elem({1, 1}, 1.0); simde::type::tensor A(shape, std::move(A_buffer)); simde::type::tensor B(shape, std::move(B_buffer)); auto&& [values, vector] = mod.run_as(A, B); - auto corr_buffer = alloc.construct({-0.236068, 4.236068}); + std::vector expected_values{-0.236068, 4.236068}; tensorwrapper::shape::Smooth corr_shape{2}; + tensorwrapper::buffer::Contiguous corr_buffer(expected_values, corr_shape); simde::type::tensor corr(corr_shape, std::move(corr_buffer)); REQUIRE(tensorwrapper::operations::approximately_equal(corr, values, 1E-6)); diff --git a/tests/cxx/unit_tests/matrix_builder/density_matrix.cpp b/tests/cxx/unit_tests/matrix_builder/density_matrix.cpp index 27262d2..87c806d 100644 --- a/tests/cxx/unit_tests/matrix_builder/density_matrix.cpp +++ b/tests/cxx/unit_tests/matrix_builder/density_matrix.cpp @@ -30,10 +30,9 @@ TEMPLATE_LIST_TEST_CASE("Density Matrix Builder", "", test_scf::float_types) { chemist::braket::BraKet p_mn(aos, rho_hat, aos); const auto& P = mod.run_as(p_mn); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); tensorwrapper::shape::Smooth corr_shape{2, 2}; - tensorwrapper::layout::Physical l(corr_shape); - auto corr_buffer = alloc.construct(l, 0.31980835); + float_type init{0.31980835}; + auto corr_buffer = tensorwrapper::buffer::make_contiguous(corr_shape, init); tensorwrapper::Tensor corr(corr_shape, std::move(corr_buffer)); using tensorwrapper::operations::approximately_equal; diff --git a/tests/cxx/unit_tests/xc/gauxc/gauxc_driver.cpp b/tests/cxx/unit_tests/xc/gauxc/gauxc_driver.cpp index 5c18d6a..6c37a67 100644 --- a/tests/cxx/unit_tests/xc/gauxc/gauxc_driver.cpp +++ b/tests/cxx/unit_tests/xc/gauxc/gauxc_driver.cpp @@ -51,11 +51,10 @@ TEST_CASE("GauXCDriver") { simde::type::tensor exc_corr(-0.819986); REQUIRE(approximately_equal(exc_corr, exc, 1E-5)); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); + using tensorwrapper::buffer::make_contiguous; tensorwrapper::shape::Smooth shape_corr{1, 1}; - auto pcorr = - alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); - pcorr->set_elem({0, 0}, -0.526535); + auto pcorr = make_contiguous(shape_corr); + pcorr.set_elem({0, 0}, -0.526535); simde::type::tensor vxc_corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(vxc, vxc_corr, 1E-5)); } diff --git a/tests/cxx/unit_tests/xc/gauxc/xc_potential.cpp b/tests/cxx/unit_tests/xc/gauxc/xc_potential.cpp index 7c23235..307ca56 100644 --- a/tests/cxx/unit_tests/xc/gauxc/xc_potential.cpp +++ b/tests/cxx/unit_tests/xc/gauxc/xc_potential.cpp @@ -49,11 +49,10 @@ TEST_CASE("XCPotential") { chemist::braket::BraKet xc_ij(aos, xc_op, aos); auto vxc = mod.run_as(xc_ij); - tensorwrapper::allocator::Eigen alloc(mm.get_runtime()); + using tensorwrapper::buffer::make_contiguous; tensorwrapper::shape::Smooth shape_corr{1, 1}; - auto pcorr = - alloc.allocate(tensorwrapper::layout::Physical(shape_corr)); - pcorr->set_elem({0, 0}, -0.526535); + auto pcorr = make_contiguous(shape_corr); + pcorr.set_elem({0, 0}, -0.526535); simde::type::tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(vxc, corr, 1E-5)); } From 206178dec32cf40a0679401850c5a25c64895d98 Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Thu, 29 Jan 2026 13:07:23 -0600 Subject: [PATCH 2/5] scf works again!!! --- src/scf/driver/scf_loop.cpp | 43 +++++++++++++------ src/scf/eigen_solver/eigen_generalized.cpp | 4 +- src/scf/xc/libxc/libxc.cpp | 21 ++++----- .../integration_tests/driver/scf_driver.cpp | 6 +-- .../cxx/integration_tests/driver/scf_loop.cpp | 8 ++-- .../matrix_builder/determinant_driver.cpp | 8 ++-- .../matrix_builder/electronic_energy.cpp | 2 +- .../integration_tests/matrix_builder/fock.cpp | 16 +++---- tests/cxx/test_scf.hpp | 16 +++---- .../eigen_solver/eigen_generalized.cpp | 16 +++---- 10 files changed, 76 insertions(+), 64 deletions(-) diff --git a/src/scf/driver/scf_loop.cpp b/src/scf/driver/scf_loop.cpp index bc9f7bf..f50a51d 100644 --- a/src/scf/driver/scf_loop.cpp +++ b/src/scf/driver/scf_loop.cpp @@ -50,6 +50,34 @@ struct GrabNuclear : chemist::qm_operator::OperatorVisitor { const V_nn_type* m_pv = nullptr; }; +struct ChangeTypeVisitor { + double m_val; + explicit ChangeTypeVisitor(double val) : m_val(val) {} + + template + void operator()(std::span out) { + if constexpr(std::is_const_v) { + throw std::runtime_error( + "ChangeTypeVisitor: Cannot write to const buffer"); + } else { + out[0] = std::decay_t(m_val); + } + } +}; + +// corr_type is only non-const so underlying type has correct cv-qualifiers +auto convert_e_nuclear(simde::type::tensor& corr_type, + const simde::type::tensor& e_nuc) { + using tensorwrapper::buffer::make_contiguous; + const auto& nuc_buffer = make_contiguous(e_nuc.buffer()); + auto val = wtf::fp::float_cast(nuc_buffer.get_elem({})); + tensorwrapper::shape::Smooth shape{}; + ChangeTypeVisitor visitor(val); + auto temp_buffer = make_contiguous(corr_type.buffer(), shape); + tensorwrapper::buffer::visit_contiguous_buffer(visitor, temp_buffer); + return simde::type::tensor(shape, std::move(temp_buffer)); +} + const auto desc = R"( )"; @@ -271,19 +299,8 @@ MODULE_RUN(SCFLoop) { tensor_t e_total; - // e_nuclear is a double. This hack converts it to udouble (if needed) - try { - using tensorwrapper::buffer::make_contiguous; - using tensorwrapper::types::udouble; - const auto& e_contig = make_contiguous(e_nuclear.buffer()); - auto val = wtf::fp::float_cast(e_contig.get_elem({})); - std::vector val_vector{val}; - tensorwrapper::shape::Smooth scalar{}; - tensorwrapper::buffer::Contiguous nuc_buffer(val_vector, scalar); - e_nuclear = tensor_t(scalar, std::move(nuc_buffer)); - } catch(...) { - // Nothing to do here - } + // This is a hack because WTF doesn't do auto-conversions yet + e_nuclear = convert_e_nuclear(e_old, e_nuclear); e_total("") = e_old("") + e_nuclear(""); diff --git a/src/scf/eigen_solver/eigen_generalized.cpp b/src/scf/eigen_solver/eigen_generalized.cpp index bc70ce4..b82589c 100644 --- a/src/scf/eigen_solver/eigen_generalized.cpp +++ b/src/scf/eigen_solver/eigen_generalized.cpp @@ -106,11 +106,11 @@ MODULE_CTOR(EigenGeneralized) { MODULE_RUN(EigenGeneralized) { auto&& [A, B] = pt::unwrap_inputs(inputs); - const auto& A_shape = A.logical_layout().shape().as_smooth(); - Kernel k(A_shape.extent(0), A_shape.extent(1)); using tensorwrapper::buffer::make_contiguous; const auto& A_buffer = make_contiguous(A.buffer()); const auto& B_buffer = make_contiguous(B.buffer()); + const auto& A_shape = A_buffer.shape(); + Kernel k(A_shape.extent(0), A_shape.extent(1)); using tensorwrapper::buffer::visit_contiguous_buffer; auto [values, vectors] = visit_contiguous_buffer(k, A_buffer, B_buffer); diff --git a/src/scf/xc/libxc/libxc.cpp b/src/scf/xc/libxc/libxc.cpp index 4b68dd6..998ff18 100644 --- a/src/scf/xc/libxc/libxc.cpp +++ b/src/scf/xc/libxc/libxc.cpp @@ -273,7 +273,7 @@ struct BatchedDotKernel { BatchedDotKernel(std::size_t n_aos, std::size_t n_grid, bool sum_row = true) : - m_sum_row(true), m_n_grid(n_grid), m_n_aos(n_aos) {} + m_sum_row(sum_row), m_n_grid(n_grid), m_n_aos(n_aos) {} template tensor_type operator()(const std::span& w, @@ -322,12 +322,11 @@ simde::type::tensor weight_a_matrix(const simde::type::tensor& w, const simde::type::tensor& b) { using tensorwrapper::buffer::make_contiguous; using tensorwrapper::buffer::visit_contiguous_buffer; - auto shape = b.logical_layout().shape().as_smooth(); - auto n_aos = shape.extent(0); - auto n_grid = shape.extent(1); - WeightMatrixKernel k(n_aos, n_grid); const auto& b_buffer = make_contiguous(b.buffer()); const auto& w_buffer = make_contiguous(w.buffer()); + + auto b_shape = b_buffer.shape(); + WeightMatrixKernel k(b_shape.extent(0), b_shape.extent(1)); return visit_contiguous_buffer(k, w_buffer, b_buffer); } @@ -335,12 +334,10 @@ simde::type::tensor normalize_row(const simde::type::tensor& w, const simde::type::tensor& b) { using tensorwrapper::buffer::make_contiguous; using tensorwrapper::buffer::visit_contiguous_buffer; - auto shape = b.logical_layout().shape().as_smooth(); - auto n_aos = shape.extent(0); - auto n_grid = shape.extent(1); - NormalizeKernel k(n_aos, n_grid); const auto& b_buffer = make_contiguous(b.buffer()); const auto& w_buffer = make_contiguous(w.buffer()); + auto b_shape = b_buffer.shape(); + NormalizeKernel k(b_shape.extent(0), b_shape.extent(1)); return visit_contiguous_buffer(k, w_buffer, b_buffer); } @@ -348,12 +345,10 @@ simde::type::tensor batched_dot(const simde::type::tensor& aos_on_grid, const simde::type::tensor& X, bool sum_row) { using tensorwrapper::buffer::make_contiguous; using tensorwrapper::buffer::visit_contiguous_buffer; - auto shape = X.logical_layout().shape().as_smooth(); - auto n_aos = shape.extent(0); - auto n_grid = shape.extent(1); - BatchedDotKernel k(n_aos, n_grid, sum_row); const auto& aos_on_grid_buffer = make_contiguous(aos_on_grid.buffer()); const auto& X_buffer = make_contiguous(X.buffer()); + auto X_shape = X_buffer.shape(); + BatchedDotKernel k(X_shape.extent(0), X_shape.extent(1), sum_row); return visit_contiguous_buffer(std::move(k), aos_on_grid_buffer, X_buffer); } } // namespace scf::xc::libxc diff --git a/tests/cxx/integration_tests/driver/scf_driver.cpp b/tests/cxx/integration_tests/driver/scf_driver.cpp index d229a69..33e2dd9 100644 --- a/tests/cxx/integration_tests/driver/scf_driver.cpp +++ b/tests/cxx/integration_tests/driver/scf_driver.cpp @@ -31,7 +31,7 @@ TEMPLATE_LIST_TEST_CASE("SCFDriver", "", test_scf::float_types) { auto aos = test_scf::h2_aos().ao_basis_set(); SECTION("SCF") { - pcorr.set_elem({}, -1.1167592336); + pcorr.set_elem({}, float_type{-1.1167592336}); simde::type::tensor corr(shape_corr, std::move(pcorr)); const auto e = mm.template run_as("SCF Driver", aos, h2); REQUIRE(approximately_equal(corr, e, 1E-6)); @@ -48,7 +48,7 @@ TEMPLATE_LIST_TEST_CASE("SCFDriver", "", test_scf::float_types) { 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); + pcorr.set_elem({}, float_type{-1.15207}); simde::type::tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-5)); } @@ -66,7 +66,7 @@ TEMPLATE_LIST_TEST_CASE("SCFDriver", "", test_scf::float_types) { simde::type::chemical_system h2_dimer_sys(h2_dimer_mol); const auto e = mm.template run_as("SCF Driver", ao_bs, h2_dimer_sys); - pcorr.set_elem({}, -2.2260535919670001); + pcorr.set_elem({}, float_type{-2.2260535919670001}); simde::type::tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } diff --git a/tests/cxx/integration_tests/driver/scf_loop.cpp b/tests/cxx/integration_tests/driver/scf_loop.cpp index 60ce0ba..53c5c0c 100644 --- a/tests/cxx/integration_tests/driver/scf_loop.cpp +++ b/tests/cxx/integration_tests/driver/scf_loop.cpp @@ -47,14 +47,14 @@ TEMPLATE_LIST_TEST_CASE("SCFLoop", "", test_scf::float_types) { mod.change_input("DIIS", true); const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr.set_elem({}, -1.1167592336); + pcorr.set_elem({}, float_type{-1.1167592336}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } SECTION("With DIIS") { const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr.set_elem({}, -1.1167592336); + pcorr.set_elem({}, float_type{-1.1167592336}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } @@ -70,7 +70,7 @@ TEMPLATE_LIST_TEST_CASE("SCFLoop", "", test_scf::float_types) { mod.change_input("DIIS", true); const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr.set_elem({}, -2.807783957539); + pcorr.set_elem({}, float_type{-2.807783957539}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } @@ -78,7 +78,7 @@ TEMPLATE_LIST_TEST_CASE("SCFLoop", "", test_scf::float_types) { SECTION("With DIIS") { const auto& [e, psi] = mod.template run_as>(H_00, psi0); - pcorr.set_elem({}, -2.807783957539); + pcorr.set_elem({}, float_type{-2.807783957539}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, e, 1E-6)); } diff --git a/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp b/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp index f2e3900..587618a 100644 --- a/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp +++ b/tests/cxx/integration_tests/matrix_builder/determinant_driver.cpp @@ -48,7 +48,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& T = mod.template run_as>(copy_braket); - pcorr.set_elem({}, 0.637692); + pcorr.set_elem({}, float_type{0.637692}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, T, 1E-6)); } @@ -60,7 +60,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& V = mod.template run_as>(copy_braket); - pcorr.set_elem({}, -1.96830777255516853); + pcorr.set_elem({}, float_type{-1.96830777255516853}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, V, 1E-6)); } @@ -72,7 +72,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& J = mod.template run_as>(copy_braket); - pcorr.set_elem({}, 0.76056339681664897); + pcorr.set_elem({}, float_type{0.76056339681664897}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, J, 1E-6)); } @@ -84,7 +84,7 @@ TEMPLATE_LIST_TEST_CASE("DeterminantDriver", "", test_scf::float_types) { erased_type copy_braket(braket); const auto& K = mod.template run_as>(copy_braket); - pcorr.set_elem({}, 0.76056339681664897); + pcorr.set_elem({}, float_type{0.76056339681664897}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, K, 1E-6)); } diff --git a/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp b/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp index ae69fc5..52b84d0 100644 --- a/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp +++ b/tests/cxx/integration_tests/matrix_builder/electronic_energy.cpp @@ -52,7 +52,7 @@ TEMPLATE_LIST_TEST_CASE("ElectronicEnergy", "", test_scf::float_types) { const auto& E_elec = mod.template run_as>(braket); - pcorr.set_elem({}, -1.90066758625308307); + pcorr.set_elem({}, float_type{-1.90066758625308307}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); REQUIRE(approximately_equal(corr, E_elec, 1E-6)); } diff --git a/tests/cxx/integration_tests/matrix_builder/fock.cpp b/tests/cxx/integration_tests/matrix_builder/fock.cpp index 520db4f..c45b9b1 100644 --- a/tests/cxx/integration_tests/matrix_builder/fock.cpp +++ b/tests/cxx/integration_tests/matrix_builder/fock.cpp @@ -42,10 +42,10 @@ TEMPLATE_LIST_TEST_CASE("Fock Matrix Builder", "", test_scf::float_types) { chemist::braket::BraKet f_mn(aos, f_e, aos); const auto& F = mod.template run_as(f_mn); - pcorr.set_elem({0, 0}, -1.120958); - pcorr.set_elem({0, 1}, -0.959374); - pcorr.set_elem({1, 0}, -0.959374); - pcorr.set_elem({1, 1}, -1.120958); + pcorr.set_elem({0, 0}, float_type{-1.120958}); + pcorr.set_elem({0, 1}, float_type{-0.959374}); + pcorr.set_elem({1, 0}, float_type{-0.959374}); + pcorr.set_elem({1, 1}, float_type{-1.120958}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); @@ -57,10 +57,10 @@ TEMPLATE_LIST_TEST_CASE("Fock Matrix Builder", "", test_scf::float_types) { chemist::braket::BraKet f_mn(aos, f_e, aos); const auto& F = mod.template run_as(f_mn); - pcorr.set_elem({0, 0}, -0.319459); - pcorr.set_elem({0, 1}, -0.571781); - pcorr.set_elem({1, 0}, -0.571781); - pcorr.set_elem({1, 1}, -0.319459); + pcorr.set_elem({0, 0}, float_type{-0.319459}); + pcorr.set_elem({0, 1}, float_type{-0.571781}); + pcorr.set_elem({1, 0}, float_type{-0.571781}); + pcorr.set_elem({1, 1}, float_type{-0.319459}); tensorwrapper::Tensor corr(shape_corr, std::move(pcorr)); diff --git a/tests/cxx/test_scf.hpp b/tests/cxx/test_scf.hpp index 7514b5d..82aabb3 100644 --- a/tests/cxx/test_scf.hpp +++ b/tests/cxx/test_scf.hpp @@ -167,10 +167,10 @@ inline auto h2_mos() { using tensor_type = typename mos_type::transform_type; tensorwrapper::shape::Smooth shape{2, 2}; auto c_buffer = tensorwrapper::buffer::make_contiguous(shape); - c_buffer.set_elem({0, 0}, -0.565516); - c_buffer.set_elem({0, 1}, -1.07019); - c_buffer.set_elem({1, 0}, -0.565516); - c_buffer.set_elem({1, 1}, 1.07019); + c_buffer.set_elem({0, 0}, FloatType{-0.565516}); + c_buffer.set_elem({0, 1}, FloatType{-1.07019}); + c_buffer.set_elem({1, 0}, FloatType{-0.565516}); + c_buffer.set_elem({1, 1}, FloatType{1.07019}); tensor_type t(shape, std::move(c_buffer)); return mos_type(h2_aos(), std::move(t)); } @@ -181,7 +181,7 @@ inline auto he_mos() { using tensor_type = typename mos_type::transform_type; tensorwrapper::shape::Smooth shape{1, 1}; auto c_buffer = tensorwrapper::buffer::make_contiguous(shape); - c_buffer.set_elem({0, 0}, 1.0000); + c_buffer.set_elem({0, 0}, FloatType{1.0000}); tensor_type t(shape, std::move(c_buffer)); return mos_type(he_aos(), std::move(t)); } @@ -192,8 +192,8 @@ inline auto h2_cmos() { using tensor_type = typename cmos_type::transform_type; tensorwrapper::shape::Smooth shape{2}; auto e_buffer = tensorwrapper::buffer::make_contiguous(shape); - e_buffer.set_elem({0}, -1.25330893); - e_buffer.set_elem({1}, -0.47506974); + e_buffer.set_elem({0}, FloatType{-1.25330893}); + e_buffer.set_elem({1}, FloatType{-0.47506974}); tensor_type e(shape, std::move(e_buffer)); return cmos_type(std::move(e), h2_aos(), h2_mos().transform()); } @@ -204,7 +204,7 @@ inline auto he_cmos() { using tensor_type = typename cmos_type::transform_type; tensorwrapper::shape::Smooth shape{1}; auto e_buffer = tensorwrapper::buffer::make_contiguous(shape); - e_buffer.set_elem({0}, -0.876036); + e_buffer.set_elem({0}, FloatType{-0.876036}); tensor_type e(shape, std::move(e_buffer)); return cmos_type(std::move(e), he_aos(), he_mos().transform()); } diff --git a/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp b/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp index 71c4d3f..96e56a7 100644 --- a/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp +++ b/tests/cxx/unit_tests/eigen_solver/eigen_generalized.cpp @@ -30,16 +30,16 @@ TEMPLATE_LIST_TEST_CASE("EigenGeneralized", "", test_scf::float_types) { tensorwrapper::shape::Smooth shape{2, 2}; using tensorwrapper::buffer::make_contiguous; auto A_buffer = make_contiguous(shape); - A_buffer.set_elem({0, 0}, 1.0); - A_buffer.set_elem({0, 1}, 2.0); - A_buffer.set_elem({1, 0}, 2.0); - A_buffer.set_elem({1, 1}, 3.0); + A_buffer.set_elem({0, 0}, float_type{1.0}); + A_buffer.set_elem({0, 1}, float_type{2.0}); + A_buffer.set_elem({1, 0}, float_type{2.0}); + A_buffer.set_elem({1, 1}, float_type{3.0}); auto B_buffer = make_contiguous(shape); - B_buffer.set_elem({0, 0}, 1.0); - B_buffer.set_elem({0, 1}, 0.0); - B_buffer.set_elem({1, 0}, 0.0); - B_buffer.set_elem({1, 1}, 1.0); + B_buffer.set_elem({0, 0}, float_type{1.0}); + B_buffer.set_elem({0, 1}, float_type{0.0}); + B_buffer.set_elem({1, 0}, float_type{0.0}); + B_buffer.set_elem({1, 1}, float_type{1.0}); simde::type::tensor A(shape, std::move(A_buffer)); simde::type::tensor B(shape, std::move(B_buffer)); From 2444e5ef21902c4177d13ff9fc1431654ee99fa0 Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Mon, 2 Feb 2026 10:58:52 -0600 Subject: [PATCH 3/5] disable mpi --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4ba93d..f34602c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,7 @@ if("${BUILD_TESTING}") include(get_catch2) include(cmake/mpi_test.cmake) - cxx_mpi_test( + cmaize_add_tests( unit_test_scf SOURCE_DIR "${CXX_TEST_DIR}/unit_tests" INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/src/scf" @@ -131,7 +131,7 @@ if("${BUILD_TESTING}") if("${INTEGRATION_TESTING}") include(get_nwchemex) - cxx_mpi_test( + cmaize_add_tests( integration_test_scf SOURCE_DIR "${CXX_TEST_DIR}/integration_tests" INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/src/scf" From 9bae818395a33da7817cffef97cb17e3e87bb6a4 Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Mon, 2 Feb 2026 11:27:33 -0600 Subject: [PATCH 4/5] comment out python tests --- CMakeLists.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f34602c..a8f2f9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,11 +123,11 @@ if("${BUILD_TESTING}") INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/src/scf" DEPENDS Catch2 scf ) - python_mpi_test( - unit_test_scf - "${PYTHON_TEST_DIR}/unit_tests/run_unit_tests.py" - SUBMODULES simde chemist pluginplay parallelzone tensorwrapper - ) + # python_mpi_test( + # unit_test_scf + # "${PYTHON_TEST_DIR}/unit_tests/run_unit_tests.py" + # SUBMODULES simde chemist pluginplay parallelzone tensorwrapper + # ) if("${INTEGRATION_TESTING}") include(get_nwchemex) @@ -138,12 +138,12 @@ if("${BUILD_TESTING}") DEPENDS Catch2 nwchemex scf ) - python_mpi_test( - integration_test_scf - "${PYTHON_TEST_DIR}/integration_tests/run_integration_tests.py" - SUBMODULES nwchemex chemcache integrals simde chemist pluginplay - parallelzone friendzone tensorwrapper nux - ) + # python_mpi_test( + # integration_test_scf + # "${PYTHON_TEST_DIR}/integration_tests/run_integration_tests.py" + # SUBMODULES nwchemex chemcache integrals simde chemist pluginplay + # parallelzone friendzone tensorwrapper nux + # ) # Workaround for the NWX being pure python if("${BUILD_PYBIND11_PYBINDINGS}") From 336828f81d73016c89a3e032a469e94055816400 Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Mon, 2 Feb 2026 12:22:02 -0600 Subject: [PATCH 5/5] missed comment --- CMakeLists.txt | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8f2f9e..38cbe13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,19 +146,19 @@ if("${BUILD_TESTING}") # ) # Workaround for the NWX being pure python - if("${BUILD_PYBIND11_PYBINDINGS}") - get_test_property( - py_integration_test_scf - ENVIRONMENT py_path - ) - set( - py_path "${py_path}:${nwchemex_SOURCE_DIR}/src/python" - ) - set_tests_properties( - py_integration_test_scf - PROPERTIES ENVIRONMENT "${py_path}" - ) - endif() + # if("${BUILD_PYBIND11_PYBINDINGS}") + # get_test_property( + # py_integration_test_scf + # ENVIRONMENT py_path + # ) + # set( + # py_path "${py_path}:${nwchemex_SOURCE_DIR}/src/python" + # ) + # set_tests_properties( + # py_integration_test_scf + # PROPERTIES ENVIRONMENT "${py_path}" + # ) + # endif() endif() endif()