diff --git a/README.md b/README.md index 082ac6cd..3bbba673 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ for flexible and agile development in the field of KS-DFT. * [Gau2Grid](https://github.com/dgasmith/gau2grid) (pregenerated source packaged with GauXC) * MPI (Optional) * OpenMP (CPU parallelism, Optional) -* [Cereal](https://github.com/USCiLab/cereal) (Optional) * [HDF5](https://www.hdfgroup.org/solutions/hdf5/) (Optional) * [Eigen3](https://eigen.tuxfamily.org/dox/) (Testing Only) * [CUDA](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html)/[cuBLAS](https://docs.nvidia.com/cuda/cublas/index.html) (Required only if CUDA enabled) diff --git a/cmake/BuildFindCereal.cmake b/cmake/BuildFindCereal.cmake deleted file mode 100644 index f6787d4d..00000000 --- a/cmake/BuildFindCereal.cmake +++ /dev/null @@ -1,32 +0,0 @@ -find_package( cereal QUIET ) -if( NOT cereal_FOUND ) - - include( gauxc-dep-versions ) - - message( STATUS "Could not find Cereal... Building" ) - message( STATUS "CEREAL REPO = ${GAUXC_CEREAL_REPOSITORY}" ) - message( STATUS "CEREAL REV = ${GAUXC_CEREAL_REVISION}" ) - - FetchContent_Declare( - cereal - GIT_REPOSITORY ${GAUXC_CEREAL_REPOSITORY} - GIT_TAG ${GAUXC_CEREAL_REVISION} - ) - - FetchContent_GetProperties(cereal) - if(NOT cereal_POPULATED) - FetchContent_Populate( cereal ) - add_library( cereal INTERFACE IMPORTED ) - set_target_properties( cereal PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${cereal_SOURCE_DIR}/include" - INTERFACE_COMPILE_DEFINITIONS "CEREAL_THREAD_SAFE=1;GAUXC_HAS_CEREAL=1" - ) - endif() - -else() - - target_compile_definitions( cereal INTERFACE - "CEREAL_THREAD_SAFE=1;GAUXC_HAS_CEREAL=1" - ) - -endif() diff --git a/cmake/gauxc-cereal.cmake b/cmake/gauxc-cereal.cmake deleted file mode 100644 index 5ddbc3bc..00000000 --- a/cmake/gauxc-cereal.cmake +++ /dev/null @@ -1 +0,0 @@ -include( BuildFindCereal ) diff --git a/cmake/gauxc-dep-versions.cmake b/cmake/gauxc-dep-versions.cmake index 7946af25..62fbcb26 100644 --- a/cmake/gauxc-dep-versions.cmake +++ b/cmake/gauxc-dep-versions.cmake @@ -1,9 +1,6 @@ set( GAUXC_LINALG_MODULES_REPOSITORY https://github.com/wavefunction91/linalg-cmake-modules.git ) set( GAUXC_LINALG_MODULES_REVISION 9d2c273a671d6811e9fd432f6a4fa3d915b144b8 ) -set( GAUXC_CEREAL_REPOSITORY https://github.com/USCiLab/cereal.git ) -set( GAUXC_CEREAL_REVISION v1.3.0 ) - set( GAUXC_CUB_REPOSITORY https://github.com/NVIDIA/cub.git ) set( GAUXC_CUB_REVISION 1.10.0 ) diff --git a/include/gauxc/atom.hpp b/include/gauxc/atom.hpp index 72b0673b..a7a864e9 100644 --- a/include/gauxc/atom.hpp +++ b/include/gauxc/atom.hpp @@ -46,18 +46,6 @@ struct Atom { Atom( AtomicNumber _Z, double _x, double _y, double _z ) : Z(_Z), x(_x), y(_y), z(_z) { } - /** - * @brief (De)serialize an atom object to/from a particular cereal archive - * - * @tparam Archive Cereal archive type - * - * @param[in/out] ar Cereal archive - */ - template - void serialize( Archive& ar ) { - ar( Z, x, y, z ); - } - }; // struct Atom /** diff --git a/include/gauxc/external/cereal.hpp b/include/gauxc/external/cereal.hpp deleted file mode 100644 index ba0b6ef9..00000000 --- a/include/gauxc/external/cereal.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/** - * GauXC Copyright (c) 2020-2024, The Regents of the University of California, - * through Lawrence Berkeley National Laboratory (subject to receipt of - * any required approvals from the U.S. Dept. of Energy). - * - * (c) 2024-2025, Microsoft Corporation - * - * All rights reserved. - * - * See LICENSE.txt for details - */ -#pragma once - -#include -#include - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5f00d7db..69b30ce5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,7 +39,6 @@ else() endif() include( gauxc-eigen3 ) -include( gauxc-cereal ) #add_library( catch2_main STATIC ut_main.cxx) #target_link_libraries( catch2_main PUBLIC gauxc_catch2 ) @@ -68,7 +67,7 @@ add_executable( gauxc_test dd_psi_potential_test.cxx 2nd_derivative_test.cxx ) -target_link_libraries( gauxc_test PUBLIC gauxc gauxc_catch2 Eigen3::Eigen cereal ) +target_link_libraries( gauxc_test PUBLIC gauxc gauxc_catch2 Eigen3::Eigen ) if(GAUXC_ENABLE_CUTLASS) include(gauxc-cutlass) target_link_libraries(gauxc_test PUBLIC gauxc_cutlass) @@ -82,19 +81,15 @@ target_include_directories( gauxc_test PRIVATE ${PROJECT_SOURCE_DIR}/tests ) add_executable( standalone_driver standalone_driver.cxx standards.cxx basis/parse_basis.cxx ini_input.cxx ) -target_link_libraries( standalone_driver PUBLIC gauxc gauxc_catch2 Eigen3::Eigen cereal ) +target_link_libraries( standalone_driver PUBLIC gauxc gauxc_catch2 Eigen3::Eigen ) target_include_directories( standalone_driver PRIVATE ${PROJECT_BINARY_DIR}/tests ) target_include_directories( standalone_driver PRIVATE ${PROJECT_SOURCE_DIR}/tests ) #add_executable( grid_opt grid_opt.cxx standards.cxx basis/parse_basis.cxx ini_input.cxx ) -#target_link_libraries( grid_opt PUBLIC gauxc gauxc_catch2 Eigen3::Eigen cereal ) +#target_link_libraries( grid_opt PUBLIC gauxc gauxc_catch2 Eigen3::Eigen ) #target_include_directories( grid_opt PRIVATE ${PROJECT_BINARY_DIR}/tests ) #target_include_directories( grid_opt PRIVATE ${PROJECT_SOURCE_DIR}/tests ) -#add_executable( conv_cereal_to_hdf5 conv_cereal_to_hdf5.cxx standards.cxx basis/parse_basis.cxx ) -#target_link_libraries( conv_cereal_to_hdf5 PUBLIC gauxc gauxc_catch2 Eigen3::Eigen cereal ) -#target_include_directories( conv_cereal_to_hdf5 PRIVATE ${PROJECT_BINARY_DIR}/tests ) -#target_include_directories( conv_cereal_to_hdf5 PRIVATE ${PROJECT_SOURCE_DIR}/tests ) add_test( NAME GAUXC_SERIAL_TEST COMMAND $ ) if( GAUXC_ENABLE_MPI ) diff --git a/tests/collocation.cxx b/tests/collocation.cxx index af85da77..74150590 100644 --- a/tests/collocation.cxx +++ b/tests/collocation.cxx @@ -37,64 +37,66 @@ TEST_CASE( "Water / cc-pVDZ", "[collocation]" ) { #ifdef GENERATE_TESTS - std::ofstream ref_data( "water_cc-pVDZ_collocation.bin", std::ios::binary ); - generate_collocation_data( mol, basis, ref_data ); + generate_collocation_data( mol, basis, "water_cc-pVDZ_collocation.hdf5" ); #else - std::ifstream ref_data( GAUXC_REF_DATA_PATH "/water_cc-pVDZ_collocation.bin", - std::ios::binary ); + std::string ref_file = GAUXC_REF_DATA_PATH "/water_cc-pVDZ_collocation.hdf5"; #ifdef GAUXC_HAS_HOST SECTION( "Host Eval" ) { - test_host_collocation( basis, ref_data ); + test_host_collocation( basis, ref_file ); } SECTION( "Host Eval Grad" ) { - test_host_collocation_deriv1( basis, ref_data ); + test_host_collocation_deriv1( basis, ref_file ); } SECTION( "Host Eval Hessian" ) { - test_host_collocation_deriv2( basis, ref_data ); + test_host_collocation_deriv2( basis, ref_file ); + } + + SECTION( "Host Eval Laplacian Gradient" ) { + test_host_collocation_deriv3( basis, ref_file ); } #endif #ifdef GAUXC_HAS_CUDA BasisSetMap basis_map( basis, mol ); SECTION( "CUDA Eval" ) { - test_cuda_collocation( basis, ref_data ); + test_cuda_collocation( basis, ref_file ); } SECTION( "CUDA Shell to Task Eval" ) { - test_cuda_collocation_shell_to_task( basis, basis_map, ref_data ); + test_cuda_collocation_shell_to_task( basis, basis_map, ref_file ); } SECTION( "CUDA Eval Grad" ) { - test_cuda_collocation_deriv1( basis, ref_data ); + test_cuda_collocation_deriv1( basis, ref_file ); } SECTION( "CUDA Shell to Task Eval Grad" ) { - test_cuda_collocation_shell_to_task_gradient( basis, basis_map, ref_data ); + test_cuda_collocation_shell_to_task_gradient( basis, basis_map, ref_file ); } SECTION( "CUDA Shell to Task Eval Hessian" ) { - test_cuda_collocation_shell_to_task_hessian( basis, basis_map, ref_data ); + test_cuda_collocation_shell_to_task_hessian( basis, basis_map, ref_file ); } SECTION( "CUDA Shell to Task Eval Laplacian" ) { - test_cuda_collocation_shell_to_task_laplacian( basis, basis_map, ref_data ); + test_cuda_collocation_shell_to_task_laplacian( basis, basis_map, ref_file ); } SECTION( "CUDA Shell to Task Eval Laplacian Gradient" ) { - test_cuda_collocation_shell_to_task_lapgrad( basis, basis_map, ref_data ); + test_cuda_collocation_shell_to_task_lapgrad( basis, basis_map, ref_file ); } #endif // GAUXC_HAS_CUDA #ifdef GAUXC_HAS_HIP SECTION( "HIP Eval" ) { - test_hip_collocation( basis, ref_data ); + test_hip_collocation( basis, ref_file ); } SECTION( "HIP Eval Grad" ) { - test_hip_collocation_deriv1( basis, ref_data ); + test_hip_collocation_deriv1( basis, ref_file ); } #endif // GAUXC_HAS_HIP diff --git a/tests/collocation_common.hpp b/tests/collocation_common.hpp index 567f8f40..4e212101 100644 --- a/tests/collocation_common.hpp +++ b/tests/collocation_common.hpp @@ -49,7 +49,20 @@ struct ref_collocation_data { }; -void check_collocation_transpose( int npts, int nbf, const double* ref_val, const double* comp_val, std::string msg = "" ) { +// Weights reference data structure +struct ref_weights_data { + Molecule mol; + std::shared_ptr meta; + std::vector tasks_unm; + std::vector tasks_mod; + + template + void serialize( Archive& ar ) { + ar( mol, tasks_unm, tasks_mod ); + } +}; + +inline void check_collocation_transpose( int npts, int nbf, const double* ref_val, const double* comp_val, std::string msg = "" ) { // Check transpose for( int i = 0; i < nbf; ++i ) @@ -60,7 +73,7 @@ void check_collocation_transpose( int npts, int nbf, const double* ref_val, cons } -void check_collocation( int npts, int nbf, const double* ref_val, const double* comp_val ) { +inline void check_collocation( int npts, int nbf, const double* ref_val, const double* comp_val ) { for( int i = 0; i < nbf; ++i ) for( int j = 0; j < npts; ++j ) { diff --git a/tests/collocation_cuda.hpp b/tests/collocation_cuda.hpp index b74d8476..d0a7012b 100644 --- a/tests/collocation_cuda.hpp +++ b/tests/collocation_cuda.hpp @@ -11,6 +11,8 @@ */ #ifdef GAUXC_HAS_CUDA #include "collocation_common.hpp" +#include "hdf5_test_serialization.hpp" +#include "hdf5_test_serialization_impl.hpp" #include "device/common/collocation_device.hpp" #include "device_specific/cuda_util.hpp" #include @@ -215,16 +217,12 @@ void cuda_check_collocation( const std::vector& tasks, -void test_cuda_collocation_masked_combined( const BasisSet& basis, std::ifstream& in_file, bool grad ) { +void test_cuda_collocation_masked_combined( const BasisSet& basis, const std::string& filename, bool grad ) { std::vector ref_data; - - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_collocation_data(ref_data, filename); device_queue stream( std::make_shared() ); @@ -264,15 +262,16 @@ void test_cuda_collocation_masked_combined( const BasisSet& basis, std:: } void test_cuda_collocation( const BasisSet& basis, - std::ifstream& in_file ) { + const std::string& filename ) { - test_cuda_collocation_masked_combined( basis, in_file, false ); + test_cuda_collocation_masked_combined( basis, filename, false ); } + void test_cuda_collocation_deriv1( const BasisSet& basis, - std::ifstream& in_file ) { + const std::string& filename ) { - test_cuda_collocation_masked_combined( basis, in_file, true ); + test_cuda_collocation_masked_combined( basis, filename, true ); } @@ -291,14 +290,11 @@ void test_cuda_collocation_deriv1( const BasisSet& basis, void test_cuda_collocation_shell_to_task( const BasisSet& basis, const BasisSetMap& basis_map, - std::ifstream& in_file, bool grad, bool hess, bool lapl, bool lapl_grad) { + const std::string& filename, bool grad, bool hess, bool lapl, bool lapl_grad) { // Load reference data std::vector ref_data; - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_collocation_data(ref_data, filename); // Populate base task information device_queue stream( std::make_shared() ); @@ -435,35 +431,35 @@ void test_cuda_collocation_shell_to_task( const BasisSet& basis, const void test_cuda_collocation_shell_to_task( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_cuda_collocation_shell_to_task(basis,basis_map,in_file,false, false, false, false); + test_cuda_collocation_shell_to_task(basis,basis_map,filename,false, false, false, false); } void test_cuda_collocation_shell_to_task_gradient( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_cuda_collocation_shell_to_task(basis,basis_map,in_file,true, false, false, false); + test_cuda_collocation_shell_to_task(basis,basis_map,filename,true, false, false, false); } void test_cuda_collocation_shell_to_task_hessian( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_cuda_collocation_shell_to_task(basis,basis_map,in_file,true, true, false, false); + test_cuda_collocation_shell_to_task(basis,basis_map,filename,true, true, false, false); } void test_cuda_collocation_shell_to_task_laplacian( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_cuda_collocation_shell_to_task(basis,basis_map,in_file,true, false, true, false); + test_cuda_collocation_shell_to_task(basis,basis_map,filename,true, false, true, false); } void test_cuda_collocation_shell_to_task_lapgrad( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_cuda_collocation_shell_to_task(basis,basis_map,in_file,true, true, true, true); + test_cuda_collocation_shell_to_task(basis,basis_map,filename,true, true, true, true); } diff --git a/tests/collocation_hip.hpp b/tests/collocation_hip.hpp index b6be897c..928ca4e1 100644 --- a/tests/collocation_hip.hpp +++ b/tests/collocation_hip.hpp @@ -11,6 +11,8 @@ */ #ifdef GAUXC_HAS_HIP #include "collocation_common.hpp" +#include "hdf5_test_serialization.hpp" +#include "hdf5_test_serialization_impl.hpp" #include "device/common/collocation_device.hpp" #include "device_specific/hip_util.hpp" #include @@ -177,16 +179,12 @@ void hip_check_collocation( const std::vector& tasks, -void test_hip_collocation_masked_combined( const BasisSet& basis, std::ifstream& in_file, bool grad ) { +void test_hip_collocation_masked_combined( const BasisSet& basis, const std::string& filename, bool grad ) { std::vector ref_data; - - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_collocation_data(ref_data, filename); device_queue stream( std::make_shared() ); @@ -226,15 +224,16 @@ void test_hip_collocation_masked_combined( const BasisSet& basis, std::i } void test_hip_collocation( const BasisSet& basis, - std::ifstream& in_file ) { + const std::string& filename ) { - test_hip_collocation_masked_combined( basis, in_file, false ); + test_hip_collocation_masked_combined( basis, filename, false ); } + void test_hip_collocation_deriv1( const BasisSet& basis, - std::ifstream& in_file ) { + const std::string& filename ) { - test_hip_collocation_masked_combined( basis, in_file, true ); + test_hip_collocation_masked_combined( basis, filename, true ); } @@ -253,14 +252,11 @@ void test_hip_collocation_deriv1( const BasisSet& basis, #if 0 void test_hip_collocation_shell_to_task( const BasisSet& basis, const BasisSetMap& basis_map, - std::ifstream& in_file, bool grad, bool hess) { + const std::string& filename, bool grad, bool hess) { // Load reference data std::vector ref_data; - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_collocation_data(ref_data, filename); // Populate base task information device_queue stream( std::make_shared() ); @@ -389,21 +385,21 @@ void test_hip_collocation_shell_to_task( const BasisSet& basis, const B void test_hip_collocation_shell_to_task( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_hip_collocation_shell_to_task(basis,basis_map,in_file,false, false); + test_hip_collocation_shell_to_task(basis,basis_map,filename,false, false); } void test_hip_collocation_shell_to_task_gradient( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_hip_collocation_shell_to_task(basis,basis_map,in_file,true, false); + test_hip_collocation_shell_to_task(basis,basis_map,filename,true, false); } void test_hip_collocation_shell_to_task_hessian( const BasisSet& basis, - const BasisSetMap& basis_map, std::ifstream& in_file) { + const BasisSetMap& basis_map, const std::string& filename) { - test_hip_collocation_shell_to_task(basis,basis_map,in_file,true, true); + test_hip_collocation_shell_to_task(basis,basis_map,filename,true, true); } #endif diff --git a/tests/collocation_host.hpp b/tests/collocation_host.hpp index 52dcaec0..c9f1b5c3 100644 --- a/tests/collocation_host.hpp +++ b/tests/collocation_host.hpp @@ -11,10 +11,12 @@ */ #ifdef GAUXC_HAS_HOST #include "collocation_common.hpp" +#include "hdf5_test_serialization.hpp" +#include "hdf5_test_serialization_impl.hpp" #include "host/reference/collocation.hpp" void generate_collocation_data( const Molecule& mol, const BasisSet& basis, - std::ofstream& out_file, size_t ntask_save = 10 ) { + const std::string& filename, size_t ntask_save = 10 ) { auto rt = RuntimeEnvironment(GAUXC_MPI_CODE(MPI_COMM_WORLD)); @@ -101,24 +103,17 @@ void generate_collocation_data( const Molecule& mol, const BasisSet& bas } - { - cereal::BinaryOutputArchive ar( out_file ); - ar( ref_data ); - } + write_collocation_data(ref_data, filename); } -void test_host_collocation( const BasisSet& basis, std::ifstream& in_file) { +void test_host_collocation( const BasisSet& basis, const std::string& filename) { std::vector ref_data; - - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_collocation_data(ref_data, filename); for( auto& d : ref_data ) { @@ -143,16 +138,10 @@ void test_host_collocation( const BasisSet& basis, std::ifstream& in_fil } -void test_host_collocation_deriv1( const BasisSet& basis, std::ifstream& in_file) { - - +void test_host_collocation_deriv1( const BasisSet& basis, const std::string& filename) { std::vector ref_data; - - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_collocation_data(ref_data, filename); for( auto& d : ref_data ) { @@ -186,16 +175,12 @@ void test_host_collocation_deriv1( const BasisSet& basis, std::ifstream& } -void test_host_collocation_deriv2( const BasisSet& basis, std::ifstream& in_file) { +void test_host_collocation_deriv2( const BasisSet& basis, const std::string& filename) { std::vector ref_data; - - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_collocation_data(ref_data, filename); for( auto& d : ref_data ) { @@ -247,4 +232,78 @@ void test_host_collocation_deriv2( const BasisSet& basis, std::ifstream& } } + +void test_host_collocation_deriv3( const BasisSet& basis, const std::string& filename) { + + std::vector ref_data; + read_collocation_data(ref_data, filename); + + for( auto& d : ref_data ) { + const auto npts = d.pts.size(); + const auto nbf = d.eval.size() / npts; + + const auto& mask = d.mask; + const auto& pts = d.pts; + + std::vector eval ( nbf * npts ), + deval_x( nbf * npts ), + deval_y( nbf * npts ), + deval_z( nbf * npts ), + d2eval_xx( nbf * npts ), + d2eval_xy( nbf * npts ), + d2eval_xz( nbf * npts ), + d2eval_yy( nbf * npts ), + d2eval_yz( nbf * npts ), + d2eval_zz( nbf * npts ), + d3eval_xxx( nbf * npts ), + d3eval_xxy( nbf * npts ), + d3eval_xxz( nbf * npts ), + d3eval_xyy( nbf * npts ), + d3eval_xyz( nbf * npts ), + d3eval_xzz( nbf * npts ), + d3eval_yyy( nbf * npts ), + d3eval_yyz( nbf * npts ), + d3eval_yzz( nbf * npts ), + d3eval_zzz( nbf * npts ); + + + gau2grid_collocation_der3( npts, mask.size(), nbf, + pts.data()->data(), basis, mask.data(), eval.data(), + deval_x.data(), deval_y.data(), deval_z.data(), + d2eval_xx.data(), d2eval_xy.data(), d2eval_xz.data(), + d2eval_yy.data(), d2eval_yz.data(), d2eval_zz.data(), + d3eval_xxx.data(), d3eval_xxy.data(), d3eval_xxz.data(), + d3eval_xyy.data(), d3eval_xyz.data(), d3eval_xzz.data(), + d3eval_yyy.data(), d3eval_yyz.data(), d3eval_yzz.data(), + d3eval_zzz.data()); + + // Compute laplacian gradient from 3rd derivatives + std::vector d3eval_lapl_x(nbf * npts); + std::vector d3eval_lapl_y(nbf * npts); + std::vector d3eval_lapl_z(nbf * npts); + for(auto i = 0ul; i < nbf*npts; ++i) { + d3eval_lapl_x[i] = d3eval_xxx[i] + d3eval_xyy[i] + d3eval_xzz[i]; + d3eval_lapl_y[i] = d3eval_xxy[i] + d3eval_yyy[i] + d3eval_yzz[i]; + d3eval_lapl_z[i] = d3eval_xxz[i] + d3eval_yyz[i] + d3eval_zzz[i]; + } + + // Check base function and 1st derivatives + for( auto i = 0ul; i < npts * nbf; ++i ) + CHECK( eval[i] == Approx( d.eval[i] ) ); + for( auto i = 0ul; i < npts * nbf; ++i ) + CHECK( deval_x[i] == Approx( d.deval_x[i] ) ); + for( auto i = 0ul; i < npts * nbf; ++i ) + CHECK( deval_y[i] == Approx( d.deval_y[i] ) ); + for( auto i = 0ul; i < npts * nbf; ++i ) + CHECK( deval_z[i] == Approx( d.deval_z[i] ) ); + + // Check laplacian gradient (3rd derivatives) + for( auto i = 0ul; i < npts * nbf; ++i ) + CHECK( d3eval_lapl_x[i] == Approx( d.d3eval_lapl_x[i] ) ); + for( auto i = 0ul; i < npts * nbf; ++i ) + CHECK( d3eval_lapl_y[i] == Approx( d.d3eval_lapl_y[i] ) ); + for( auto i = 0ul; i < npts * nbf; ++i ) + CHECK( d3eval_lapl_z[i] == Approx( d.d3eval_lapl_z[i] ) ); + } +} #endif diff --git a/tests/conv_cereal_to_hdf5.cxx b/tests/conv_cereal_to_hdf5.cxx deleted file mode 100644 index 682a6964..00000000 --- a/tests/conv_cereal_to_hdf5.cxx +++ /dev/null @@ -1,82 +0,0 @@ -/** - * GauXC Copyright (c) 2020-2024, The Regents of the University of California, - * through Lawrence Berkeley National Laboratory (subject to receipt of - * any required approvals from the U.S. Dept. of Energy). - * - * (c) 2024-2025, Microsoft Corporation - * - * All rights reserved. - * - * See LICENSE.txt for details - */ -#include -#include -#include -#include "eigen3_matrix_serialization.hpp" -#include -#include "standards.hpp" -#include "basis/parse_basis.hpp" -#include - -using namespace GauXC; -int main( int argc, char** argv ) { - - std::vector< std::string > opts( argc ); - for( int i = 0; i < argc; ++i ) opts[i] = argv[i]; - - std::string test_case = opts.at(1); - std::string basis_set = opts.at(2); - std::string cereal_file = opts.at(3); - std::string hdf5_file = opts.at(4); - - // Construct Molecule - Molecule mol; - if( test_case.find("benzene") != std::string::npos ) - mol = make_benzene(); - else if( test_case.find("water") != std::string::npos ) - mol = make_water(); - else if( test_case.find("taxol") != std::string::npos ) - mol = make_taxol(); - else if( test_case.find("ubiquitin") != std::string::npos ) - mol = make_ubiquitin(); - else - throw std::runtime_error("Unknown Test Case"); - - // Construct BasisSet - BasisSet basis; - if( basis_set.find("6-31gd") != std::string::npos ) - basis = std::move(make_631Gd( mol, SphericalType(false) )); - else if( basis_set.find("cc-pvdz") != std::string::npos ) - basis = std::move(make_ccpvdz( mol, SphericalType(true) )); - else - throw std::runtime_error("Unknown Basis Set"); - - // Read in cereal file - using matrix_type = Eigen::MatrixXd; - matrix_type P,VXC_ref; - double EXC_ref; - { - std::ifstream infile( cereal_file, std::ios::binary ); - - if( !infile.good() ) throw std::runtime_error(cereal_file + " not found"); - cereal::BinaryInputArchive ar(infile); - ar( EXC_ref, P, VXC_ref ); - } - - // Write HDF5 file - write_hdf5_record( mol, hdf5_file, "/MOLECULE" ); - write_hdf5_record( basis, hdf5_file, "/BASIS" ); - { - using namespace HighFive; - File file( hdf5_file, File::ReadWrite ); - DataSpace space( P.rows(), P.cols() ); - DataSet den = file.createDataSet( "/DENSITY", space ); - den.write_raw( P.data() ); - DataSet vxc = file.createDataSet( "/VXC", space ); - vxc.write_raw( VXC_ref.data() ); - - DataSpace singleton(1); - DataSet exc = file.createDataSet("/EXC", singleton ); - exc.write_raw( &EXC_ref ); - } -} diff --git a/tests/eigen3_matrix_serialization.hpp b/tests/eigen3_matrix_serialization.hpp deleted file mode 100644 index a810e8d1..00000000 --- a/tests/eigen3_matrix_serialization.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * GauXC Copyright (c) 2020-2024, The Regents of the University of California, - * through Lawrence Berkeley National Laboratory (subject to receipt of - * any required approvals from the U.S. Dept. of Energy). - * - * (c) 2024-2025, Microsoft Corporation - * - * All rights reserved. - * - * See LICENSE.txt for details - */ -#pragma once - -#include - -//#ifdef __PGI -// #define _GAUXC_COMP_IS_PGI -// #undef __PGI -//#endif -#define EIGEN_DONT_VECTORIZE -#define EIGEN_NO_CUDA -#include -//#ifdef _GAUXC_COMP_IS_PGI -// #define __PGI -//#endif - -namespace cereal { - -template -inline std::enable_if_t< - traits::is_output_serializable< BinaryData, Archive>::value and - std::is_arithmetic::value and not std::is_same::value -> CEREAL_SAVE_FUNCTION_NAME( - Archive &ar, - const Eigen::Matrix& mat -) { - - //ar( _Rows, _Cols, _Opts, _MaxRows, _MaxCols ); - int32_t rows = mat.rows(); - int32_t cols = mat.cols(); - ar( rows, cols ); - ar( binary_data( mat.data(), static_cast(rows * cols * sizeof(T)) )); - -} - - - -template -inline std::enable_if_t< - traits::is_input_serializable< BinaryData, Archive>::value and - std::is_arithmetic::value and not std::is_same::value -> CEREAL_LOAD_FUNCTION_NAME( - Archive &ar, - Eigen::Matrix& mat -) { - - //ar( Rows, Cols, Opts, MaxRows, MaxCols ); - - int32_t rows; - int32_t cols; - ar( rows, cols ); - - mat.resize( rows, cols ); - - ar( binary_data( mat.data(), static_cast(rows * cols * sizeof(T)) )); - -} - -} diff --git a/tests/hdf5_test_serialization.hpp b/tests/hdf5_test_serialization.hpp new file mode 100644 index 00000000..fa746126 --- /dev/null +++ b/tests/hdf5_test_serialization.hpp @@ -0,0 +1,224 @@ +/** + * GauXC Copyright (c) 2020-2024, The Regents of the University of California, + * through Lawrence Berkeley National Laboratory (subject to receipt of + * any required approvals from the U.S. Dept. of Energy). + * + * (c) 2024-2025, Microsoft Corporation + * + * All rights reserved. + * + * See LICENSE.txt for details + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace GauXC { + +// Forward declarations removed - actual definitions are in collocation_common.hpp +// which must be included before this file or hdf5_test_serialization_impl.hpp + +// Helper function to write std::array vectors as 2D arrays +inline void write_points_array(const std::vector>& pts, + HighFive::File& file, const std::string& dset_name) { + if (pts.empty()) return; + + // Convert to 2D vector for HighFive + std::vector> pts_2d(pts.size(), std::vector(3)); + for (size_t i = 0; i < pts.size(); ++i) { + pts_2d[i][0] = pts[i][0]; + pts_2d[i][1] = pts[i][1]; + pts_2d[i][2] = pts[i][2]; + } + + auto dset = file.createDataSet(dset_name, HighFive::DataSpace::From(pts_2d)); + dset.write(pts_2d); +} + +// Helper function to read std::array vectors from 2D arrays +inline void read_points_array(std::vector>& pts, + HighFive::File& file, const std::string& dset_name) { + // Check if dataset exists + if (!file.exist(dset_name)) { + pts.clear(); + return; + } + + auto dset = file.getDataSet(dset_name); + std::vector> pts_2d; + dset.read(pts_2d); + + pts.resize(pts_2d.size()); + for (size_t i = 0; i < pts_2d.size(); ++i) { + pts[i][0] = pts_2d[i][0]; + pts[i][1] = pts_2d[i][1]; + pts[i][2] = pts_2d[i][2]; + } +} + +// Helper to write vector with proper dimensionality +inline void write_double_vector(const std::vector& vec, + HighFive::File& file, const std::string& dset_name) { + if (vec.empty()) { + // Write empty dataset + HighFive::DataSpace space({0}); + auto dset = file.createDataSet(dset_name, space); + return; + } + + HighFive::DataSpace space(vec.size()); + auto dset = file.createDataSet(dset_name, space); + dset.write(vec); +} + +// Helper to read vector +inline void read_double_vector(std::vector& vec, + HighFive::File& file, const std::string& dset_name) { + auto dset = file.getDataSet(dset_name); + auto dims = dset.getDimensions(); + + if (dims.empty() || dims[0] == 0) { + vec.clear(); + return; + } + + vec.resize(dims[0]); + dset.read(vec); +} + +// Helper to write vector +inline void write_int32_vector(const std::vector& vec, + HighFive::File& file, const std::string& dset_name) { + if (vec.empty()) { + HighFive::DataSpace space({0}); + auto dset = file.createDataSet(dset_name, space); + return; + } + + HighFive::DataSpace space(vec.size()); + auto dset = file.createDataSet(dset_name, space); + dset.write(vec); +} + +// Helper to read vector +inline void read_int32_vector(std::vector& vec, + HighFive::File& file, const std::string& dset_name) { + auto dset = file.getDataSet(dset_name); + auto dims = dset.getDimensions(); + + if (dims.empty() || dims[0] == 0) { + vec.clear(); + return; + } + + vec.resize(dims[0]); + dset.read(vec); +} + +// Forward declare - implementations need the full struct definitions +// These will be defined after including collocation_common.hpp and weights_generate.hpp + +// Write XCTask vector to HDF5 +inline void write_xctask_vector(const std::vector& tasks, + const std::string& filename, + const std::string& group_name = "/tasks") { + HighFive::File file(filename, HighFive::File::OpenOrCreate); + + // Write number of tasks + { + HighFive::DataSpace space(1); + auto dset = file.createDataSet(group_name + "/ntasks", space); + size_t ntasks = tasks.size(); + dset.write(&ntasks); + } + + // Write each task + for (size_t i = 0; i < tasks.size(); ++i) { + std::string task_group = group_name + "/task_" + std::to_string(i); + + const auto& task = tasks[i]; + + // Write scalar fields + { + HighFive::DataSpace space(1); + auto dset_iparent = file.createDataSet(task_group + "/iParent", space); + dset_iparent.write(&task.iParent); + + auto dset_npts = file.createDataSet(task_group + "/npts", space); + dset_npts.write(&task.npts); + + auto dset_dist = file.createDataSet(task_group + "/dist_nearest", space); + dset_dist.write(&task.dist_nearest); + + auto dset_maxw = file.createDataSet(task_group + "/max_weight", space); + dset_maxw.write(&task.max_weight); + + auto dset_nbe = file.createDataSet(task_group + "/bfn_screening_nbe", space); + dset_nbe.write(&task.bfn_screening.nbe); + } + + // Write points and weights + write_points_array(task.points, file, task_group + "/points"); + write_double_vector(task.weights, file, task_group + "/weights"); + + // Write screening data + write_int32_vector(task.bfn_screening.shell_list, file, task_group + "/shell_list"); + } +} + +// Read XCTask vector from HDF5 +inline void read_xctask_vector(std::vector& tasks, + const std::string& filename, + const std::string& group_name = "/tasks") { + HighFive::File file(filename, HighFive::File::ReadOnly); + + // Read number of tasks + size_t ntasks; + { + auto dset = file.getDataSet(group_name + "/ntasks"); + dset.read(&ntasks); + } + + tasks.resize(ntasks); + + // Read each task + for (size_t i = 0; i < ntasks; ++i) { + std::string task_group = group_name + "/task_" + std::to_string(i); + + auto& task = tasks[i]; + + // Read scalar fields + { + auto dset_iparent = file.getDataSet(task_group + "/iParent"); + dset_iparent.read(&task.iParent); + + auto dset_npts = file.getDataSet(task_group + "/npts"); + dset_npts.read(&task.npts); + + auto dset_dist = file.getDataSet(task_group + "/dist_nearest"); + dset_dist.read(&task.dist_nearest); + + auto dset_maxw = file.getDataSet(task_group + "/max_weight"); + dset_maxw.read(&task.max_weight); + + auto dset_nbe = file.getDataSet(task_group + "/bfn_screening_nbe"); + dset_nbe.read(&task.bfn_screening.nbe); + } + + // Read points and weights + read_points_array(task.points, file, task_group + "/points"); + read_double_vector(task.weights, file, task_group + "/weights"); + + // Read screening data + read_int32_vector(task.bfn_screening.shell_list, file, task_group + "/shell_list"); + } +} + +} // namespace GauXC diff --git a/tests/hdf5_test_serialization_impl.hpp b/tests/hdf5_test_serialization_impl.hpp new file mode 100644 index 00000000..99a0c70d --- /dev/null +++ b/tests/hdf5_test_serialization_impl.hpp @@ -0,0 +1,129 @@ +/** + * GauXC Copyright (c) 2020-2024, The Regents of the University of California, + * through Lawrence Berkeley National Laboratory (subject to receipt of + * any required approvals from the U.S. Dept. of Energy). + * + * (c) 2024-2025, Microsoft Corporation + * + * All rights reserved. + * + * See LICENSE.txt for details + */ +#pragma once + +#include "collocation_common.hpp" +#include "hdf5_test_serialization.hpp" + +namespace GauXC { + +// Write ref_collocation_data to HDF5 +inline void write_collocation_data(const std::vector& ref_data, + const std::string& filename) { + HighFive::File file(filename, HighFive::File::Truncate); + + // Write number of data entries + { + HighFive::DataSpace space(1); + auto dset = file.createDataSet("/nentries", space); + size_t nentries = ref_data.size(); + dset.write_raw(&nentries); + } + + // Write each collocation data entry + for (size_t i = 0; i < ref_data.size(); ++i) { + std::string group = "/entry_" + std::to_string(i); + const auto& d = ref_data[i]; + + // Write all the data fields + write_int32_vector(d.mask, file, group + "/mask"); + write_points_array(d.pts, file, group + "/pts"); + write_double_vector(d.eval, file, group + "/eval"); + write_double_vector(d.deval_x, file, group + "/deval_x"); + write_double_vector(d.deval_y, file, group + "/deval_y"); + write_double_vector(d.deval_z, file, group + "/deval_z"); + write_double_vector(d.d2eval_xx, file, group + "/d2eval_xx"); + write_double_vector(d.d2eval_xy, file, group + "/d2eval_xy"); + write_double_vector(d.d2eval_xz, file, group + "/d2eval_xz"); + write_double_vector(d.d2eval_yy, file, group + "/d2eval_yy"); + write_double_vector(d.d2eval_yz, file, group + "/d2eval_yz"); + write_double_vector(d.d2eval_zz, file, group + "/d2eval_zz"); + write_double_vector(d.d2eval_lapl, file, group + "/d2eval_lapl"); + write_double_vector(d.d3eval_lapl_x, file, group + "/d3eval_lapl_x"); + write_double_vector(d.d3eval_lapl_y, file, group + "/d3eval_lapl_y"); + write_double_vector(d.d3eval_lapl_z, file, group + "/d3eval_lapl_z"); + } +} + +// Read ref_collocation_data from HDF5 +inline void read_collocation_data(std::vector& ref_data, + const std::string& filename) { + HighFive::File file(filename, HighFive::File::ReadOnly); + + // Read number of data entries + size_t nentries; + { + auto dset = file.getDataSet("/nentries"); + dset.read(&nentries); + } + + ref_data.resize(nentries); + + // Read each collocation data entry + for (size_t i = 0; i < nentries; ++i) { + std::string group = "/entry_" + std::to_string(i); + auto& d = ref_data[i]; + + // Read all the data fields + read_int32_vector(d.mask, file, group + "/mask"); + read_points_array(d.pts, file, group + "/pts"); + read_double_vector(d.eval, file, group + "/eval"); + read_double_vector(d.deval_x, file, group + "/deval_x"); + read_double_vector(d.deval_y, file, group + "/deval_y"); + read_double_vector(d.deval_z, file, group + "/deval_z"); + read_double_vector(d.d2eval_xx, file, group + "/d2eval_xx"); + read_double_vector(d.d2eval_xy, file, group + "/d2eval_xy"); + read_double_vector(d.d2eval_xz, file, group + "/d2eval_xz"); + read_double_vector(d.d2eval_yy, file, group + "/d2eval_yy"); + read_double_vector(d.d2eval_yz, file, group + "/d2eval_yz"); + read_double_vector(d.d2eval_zz, file, group + "/d2eval_zz"); + read_double_vector(d.d2eval_lapl, file, group + "/d2eval_lapl"); + read_double_vector(d.d3eval_lapl_x, file, group + "/d3eval_lapl_x"); + read_double_vector(d.d3eval_lapl_y, file, group + "/d3eval_lapl_y"); + read_double_vector(d.d3eval_lapl_z, file, group + "/d3eval_lapl_z"); + } +} + +// Write ref_weights_data to HDF5 +inline void write_weights_data(const ref_weights_data& ref_data, + const std::string& filename) { + HighFive::File file(filename, HighFive::File::Truncate); + + // Write molecule + write_hdf5_record(ref_data.mol, filename, "/MOLECULE"); + + // Write tasks_unm + write_xctask_vector(ref_data.tasks_unm, filename, "/tasks_unm"); + + // Write tasks_mod + write_xctask_vector(ref_data.tasks_mod, filename, "/tasks_mod"); +} + +// Read ref_weights_data from HDF5 +inline void read_weights_data(ref_weights_data& ref_data, + const std::string& filename) { + HighFive::File file(filename, HighFive::File::ReadOnly); + + // Read molecule + read_hdf5_record(ref_data.mol, filename, "/MOLECULE"); + + // Reconstruct meta from molecule + ref_data.meta = std::make_shared(ref_data.mol); + + // Read tasks_unm + read_xctask_vector(ref_data.tasks_unm, filename, "/tasks_unm"); + + // Read tasks_mod + read_xctask_vector(ref_data.tasks_mod, filename, "/tasks_mod"); +} + +} // namespace GauXC diff --git a/tests/load_balancer_test.cxx b/tests/load_balancer_test.cxx index 889bcb30..f3735a8b 100644 --- a/tests/load_balancer_test.cxx +++ b/tests/load_balancer_test.cxx @@ -10,6 +10,7 @@ * See LICENSE.txt for details */ #include "ut_common.hpp" +#include "hdf5_test_serialization.hpp" #include #include @@ -23,7 +24,7 @@ void gen_ref_lb_data( std::vector& tasks ) { int world_size = rt.comm_size(); std::string ref_file = GAUXC_REF_DATA_PATH "/benzene_cc-pvdz_ufg_tasks_" + std::to_string(world_size) + "mpi_rank" + std::to_string(world_rank) + - "_pv" + std::to_string(1) + ".bin"; + "_pv" + std::to_string(1) + ".hdf5"; // Points / Weights not stored in reference data to // save space @@ -32,9 +33,7 @@ void gen_ref_lb_data( std::vector& tasks ) { t.weights.clear(); } - std::ofstream of( ref_file, std::ios::binary ); - cereal::BinaryOutputArchive ar(of); - ar( tasks ); + write_xctask_vector(tasks, ref_file); } @@ -45,14 +44,10 @@ void check_lb_data( const std::vector& tasks ) { int world_size = rt.comm_size(); std::string ref_file = GAUXC_REF_DATA_PATH "/benzene_cc-pvdz_ufg_tasks_" + std::to_string(world_size) + "mpi_rank" + std::to_string(world_rank) + - "_pv" + std::to_string(1) + ".bin"; + "_pv" + std::to_string(1) + ".hdf5"; std::vector ref_tasks; - { - std::ifstream ifile( ref_file, std::ios::binary ); - cereal::BinaryInputArchive ar(ifile); - ar( ref_tasks ); - } + read_xctask_vector(ref_tasks, ref_file); REQUIRE( tasks.size() == ref_tasks.size() ); diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv1.bin b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv1.bin deleted file mode 100644 index 49825fb8..00000000 Binary files a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv1.bin and /dev/null differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv1.hdf5 b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv1.hdf5 new file mode 100644 index 00000000..9b963a11 Binary files /dev/null and b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv1.hdf5 differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv32.bin b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv32.bin deleted file mode 100644 index dae417c5..00000000 Binary files a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_1mpi_rank0_pv32.bin and /dev/null differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv1.bin b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv1.bin deleted file mode 100644 index 067b2df8..00000000 Binary files a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv1.bin and /dev/null differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv1.hdf5 b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv1.hdf5 new file mode 100644 index 00000000..e5221be5 Binary files /dev/null and b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv1.hdf5 differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv32.bin b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv32.bin deleted file mode 100644 index c18a3372..00000000 Binary files a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank0_pv32.bin and /dev/null differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv1.bin b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv1.bin deleted file mode 100644 index a342cf5a..00000000 Binary files a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv1.bin and /dev/null differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv1.hdf5 b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv1.hdf5 new file mode 100644 index 00000000..60c9d377 Binary files /dev/null and b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv1.hdf5 differ diff --git a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv32.bin b/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv32.bin deleted file mode 100644 index dadf7a87..00000000 Binary files a/tests/ref_data/benzene_cc-pvdz_ufg_tasks_2mpi_rank1_pv32.bin and /dev/null differ diff --git a/tests/ref_data/benzene_weights_becke.bin b/tests/ref_data/benzene_weights_becke.hdf5 similarity index 93% rename from tests/ref_data/benzene_weights_becke.bin rename to tests/ref_data/benzene_weights_becke.hdf5 index d625ec9b..d1fdfd9b 100644 Binary files a/tests/ref_data/benzene_weights_becke.bin and b/tests/ref_data/benzene_weights_becke.hdf5 differ diff --git a/tests/ref_data/benzene_weights_lko.bin b/tests/ref_data/benzene_weights_lko.hdf5 similarity index 93% rename from tests/ref_data/benzene_weights_lko.bin rename to tests/ref_data/benzene_weights_lko.hdf5 index 014c0f7d..63380787 100644 Binary files a/tests/ref_data/benzene_weights_lko.bin and b/tests/ref_data/benzene_weights_lko.hdf5 differ diff --git a/tests/ref_data/benzene_weights_ssf.bin b/tests/ref_data/benzene_weights_ssf.hdf5 similarity index 93% rename from tests/ref_data/benzene_weights_ssf.bin rename to tests/ref_data/benzene_weights_ssf.hdf5 index 85a6589b..d8d7077e 100644 Binary files a/tests/ref_data/benzene_weights_ssf.bin and b/tests/ref_data/benzene_weights_ssf.hdf5 differ diff --git a/tests/ref_data/water_cc-pVDZ_collocation.bin b/tests/ref_data/water_cc-pVDZ_collocation.hdf5 similarity index 89% rename from tests/ref_data/water_cc-pVDZ_collocation.bin rename to tests/ref_data/water_cc-pVDZ_collocation.hdf5 index e2d7ea60..ef8729d8 100644 Binary files a/tests/ref_data/water_cc-pVDZ_collocation.bin and b/tests/ref_data/water_cc-pVDZ_collocation.hdf5 differ diff --git a/tests/ut_common.hpp.in b/tests/ut_common.hpp.in index 6c0c00a0..f899aeef 100644 --- a/tests/ut_common.hpp.in +++ b/tests/ut_common.hpp.in @@ -16,8 +16,5 @@ #include #include -#include -#include -#include "eigen3_matrix_serialization.hpp" #cmakedefine GAUXC_REF_DATA_PATH "@GAUXC_REF_DATA_PATH@" diff --git a/tests/weights.cxx b/tests/weights.cxx index e9069a52..56882268 100644 --- a/tests/weights.cxx +++ b/tests/weights.cxx @@ -36,53 +36,41 @@ TEST_CASE( "Partition Weights", "[weights]" ) { BasisSet basis = make_631Gd( mol, SphericalType(true) ); for( auto& sh : basis ) sh.set_shell_tolerance( 1e-6 ); - { - std::ofstream ref_data( "benzene_weights_becke.bin", std::ios::binary ); - generate_weights_data( mol, basis, ref_data, XCWeightAlg::Becke ); - } - { - std::ofstream ref_data( "benzene_weights_ssf.bin", std::ios::binary ); - generate_weights_data( mol, basis, ref_data, XCWeightAlg::SSF ); - } - { - std::ofstream ref_data( "benzene_weights_lko.bin", std::ios::binary ); - generate_weights_data( mol, basis, ref_data, XCWeightAlg::LKO ); - } + generate_weights_data( mol, basis, "benzene_weights_becke.hdf5", XCWeightAlg::Becke ); + generate_weights_data( mol, basis, "benzene_weights_ssf.hdf5", XCWeightAlg::SSF ); + generate_weights_data( mol, basis, "benzene_weights_lko.hdf5", XCWeightAlg::LKO ); return; #else #ifdef GAUXC_HAS_HOST SECTION("Becke") { - std::ifstream ref_data( GAUXC_REF_DATA_PATH "/benzene_weights_becke.bin", - std::ios::binary ); - test_host_weights( ref_data, XCWeightAlg::Becke ); + std::string ref_file = GAUXC_REF_DATA_PATH "/benzene_weights_becke.hdf5"; + test_host_weights( ref_file, XCWeightAlg::Becke ); } SECTION("LKO") { - std::ifstream ref_data( GAUXC_REF_DATA_PATH "/benzene_weights_lko.bin", - std::ios::binary ); - test_host_weights( ref_data, XCWeightAlg::LKO ); + std::string ref_file = GAUXC_REF_DATA_PATH "/benzene_weights_lko.hdf5"; + test_host_weights( ref_file, XCWeightAlg::LKO ); } #endif SECTION("SSF") { - std::ifstream ref_data( GAUXC_REF_DATA_PATH "/benzene_weights_ssf.bin", - std::ios::binary ); + std::string ref_file = GAUXC_REF_DATA_PATH "/benzene_weights_ssf.hdf5"; #ifdef GAUXC_HAS_HOST SECTION( "Host Weights" ) { - test_host_weights( ref_data, XCWeightAlg::SSF ); + test_host_weights( ref_file, XCWeightAlg::SSF ); } #endif #ifdef GAUXC_HAS_DEVICE SECTION( "Device Weights" ) { #ifdef GAUXC_HAS_CUDA - test_cuda_weights( ref_data ); + test_cuda_weights( ref_file ); #elif defined(GAUXC_HAS_HIP) - test_hip_weights( ref_data ); + test_hip_weights( ref_file ); #endif } #endif diff --git a/tests/weights_cuda.hpp b/tests/weights_cuda.hpp index 3951cda4..22a2e718 100644 --- a/tests/weights_cuda.hpp +++ b/tests/weights_cuda.hpp @@ -11,7 +11,8 @@ */ #pragma once #include "weights_generate.hpp" -#include +#include "hdf5_test_serialization.hpp" +#include "hdf5_test_serialization_impl.hpp" #include #include @@ -23,13 +24,10 @@ -void test_cuda_weights( std::ifstream& in_file ) { +void test_cuda_weights( const std::string& filename ) { ref_weights_data ref_data; - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_weights_data(ref_data, filename); //std::vector< std::array > points; std::vector< double > points_x, points_y, points_z; diff --git a/tests/weights_generate.hpp b/tests/weights_generate.hpp index 465c0bf8..34788701 100644 --- a/tests/weights_generate.hpp +++ b/tests/weights_generate.hpp @@ -13,33 +13,21 @@ #include #include #include +#include "collocation_common.hpp" // has ref_weights_data +#include "hdf5_test_serialization.hpp" +#include "hdf5_test_serialization_impl.hpp" using namespace GauXC; -struct ref_weights_data { - Molecule mol; - std::shared_ptr meta; - std::vector< XCTask > tasks_unm; - std::vector< XCTask > tasks_mod; // This is only the weights - - template - void load( Archive& ar ) { - ar( mol, tasks_unm, tasks_mod ); - meta = std::make_shared(mol); - } - template - void save( Archive& ar ) const { - ar( mol, tasks_unm, tasks_mod ); - } -}; +// Note: ref_weights_data is defined in collocation_common.hpp #ifdef GAUXC_HAS_HOST #include "host/reference/weights.hpp" void generate_weights_data( const Molecule& mol, const BasisSet& basis, - std::ofstream& out_file, XCWeightAlg weight_alg, + const std::string& filename, XCWeightAlg weight_alg, size_t ntask_save = 15 ) { @@ -98,10 +86,7 @@ void generate_weights_data( const Molecule& mol, const BasisSet& basis, } ref_data.tasks_mod = tasks; - { - cereal::BinaryOutputArchive ar( out_file ); - ar( ref_data ); - } + write_weights_data(ref_data, filename); } #endif diff --git a/tests/weights_hip.hpp b/tests/weights_hip.hpp index 478a7556..39e76bf0 100644 --- a/tests/weights_hip.hpp +++ b/tests/weights_hip.hpp @@ -11,7 +11,8 @@ */ #pragma once #include "weights_generate.hpp" -#include +#include "hdf5_test_serialization.hpp" +#include "hdf5_test_serialization_impl.hpp" #include #include @@ -26,13 +27,10 @@ -void test_hip_weights( std::ifstream& in_file ) { +void test_hip_weights( const std::string& filename ) { ref_weights_data ref_data; - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_weights_data(ref_data, filename); //std::vector< std::array > points; std::vector< double > points_x, points_y, points_z; diff --git a/tests/weights_host.hpp b/tests/weights_host.hpp index f9c51417..821330ae 100644 --- a/tests/weights_host.hpp +++ b/tests/weights_host.hpp @@ -11,20 +11,18 @@ */ #pragma once #include "weights_generate.hpp" -#include +#include "hdf5_test_serialization.hpp" +#include "hdf5_test_serialization_impl.hpp" #include #ifdef GAUXC_HAS_HOST #include "host/reference/weights.hpp" using namespace GauXC; -void test_host_weights( std::ifstream& in_file, XCWeightAlg weight_alg ) { +void test_host_weights( const std::string& filename, XCWeightAlg weight_alg ) { ref_weights_data ref_data; - { - cereal::BinaryInputArchive ar( in_file ); - ar( ref_data ); - } + read_weights_data(ref_data, filename); switch(weight_alg) { case XCWeightAlg::Becke: