Skip to content

Commit

Permalink
add Einsums to build system (psi4#3050)
Browse files Browse the repository at this point in the history
* einsumsdemo

* leave fnocc alone

* right einsums

* what's wrong

* zlib

* clang

* range

* spell

* finish off

* more

* Update ein_test.cc

---------

Co-authored-by: Justin Turney <justin.turney@gmail.com>
  • Loading branch information
loriab and jturney authored Nov 6, 2023
1 parent cf2c6ad commit dfe7fe8
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .azure-pipelines/azure-pipelines-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ jobs:
set INSTALL_DIR=$(Build.BinariesDirectory)\install
conda build --python %PYTHON_VERSION% ^
conda\win
copy /y C:\tools\miniconda3\conda-bld\win-64\psi4-*.bz2 $(Build.ArtifactStagingDirectory)
copy /y C:\tools\miniforge3\conda-bld\win-64\psi4-*.bz2 $(Build.ArtifactStagingDirectory)
condition: and(succeeded(), or(eq(variables['conda.build'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master'), and(startsWith(variables['Build.SourceBranch'], 'refs/heads/1.'), endsWith(variables['Build.SourceBranch'], '.x'))))
displayName: "Build Psi4 package"
Expand All @@ -290,15 +290,15 @@ jobs:
# * error handling may need tweaking as I don't know if failure to upload for lack of space (`echo $?`=1) will fail the workflow.
- bash: |
set -e
ls -l /c/tools/miniconda3/conda-bld/win-64/*.tar.bz2
ls -l /c/tools/miniforge3/conda-bld/win-64/*.tar.bz2
echo "Using the mapped env var for this task works and is recommended: $(conda.anaconda_org_token)"
anaconda whoami
anaconda \
--verbose \
upload \
--label dev \
--skip \
/c/tools/miniconda3/conda-bld/win-64/*.tar.bz2
/c/tools/miniforge3/conda-bld/win-64/*.tar.bz2
echo $?
env:
ANACONDA_API_TOKEN: $(conda.anaconda_org_token)
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ jobs:

- name: Compare Docs (PR generated vs psi4/psi4docs)
if: ${{ github.repository == 'psi4/psi4' }}
working-directory: ./docs
working-directory: ./docs/sphinxman
id: compare-psi4docs
run: |
cp -pR ../code/objdir/doc/sphinxman/html .
cp -pR ../../code/objdir/doc/sphinxman/html .
rm -rf master
mv html master
echo "::group::Selective Git Diff"
git diff --color-words -I"Last updated on" -I"psi4/tree"
git diff --color-words -I"Last updated on" -I"psi4/tree" -I"documentation_options"
echo "::endgroup::"
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
id: compare-psi4docs
run: |
cp -pR ../../code/objdir/doc/sphinxman/html .
rm -rf ${{ github.ref_name }}
mv html ${{ github.ref_name }}
echo "::group::Selective Git Diff"
git diff --color-words -I"Last updated on" -I"psi4/tree"
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ecosystem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ jobs:
# - psi4/label/dev::ambit
# - psi4/label/dev::chemps2
# - psi4/label/dev::libecpint
- einsums=*=mkl*
- range-v3
- zlib
- dkh
- pygdma
# - psi4/label/dev::pcmsolver
Expand All @@ -161,6 +164,7 @@ jobs:
if [[ "${{ runner.os }}" == "Windows" ]]; then
sed -i "s;- fortran-compiler;;g" build.yaml
sed -i "s;- llvm-openmp;- intel-openmp;g" build.yaml
sed -i "s;- einsums;#- einsums;g" build.yaml
fi
#
# Runtime for single-channel (L, M, W)
Expand Down Expand Up @@ -195,6 +199,7 @@ jobs:
#- psi4/label/dev::chemps2
- dkh
#- psi4/label/dev::libecpint
- einsums=*=mkl*
- pygdma
#- psi4/label/dev::pcmsolver
#- psi4/label/dev::simint
Expand Down Expand Up @@ -250,6 +255,7 @@ jobs:
sed -i "s;- openfermion>=1.0;;g" run.yaml
sed -i "s;- openfermionpsi4;;g" run.yaml
sed -i "s;- memory_profiler;;g" run.yaml
sed -i "s;- einsums;#- einsums;g" run.yaml
# not for py312
sed -i "s;- dftd3-python;;g" run.yaml
sed -i "s;- dftd4-python;;g" run.yaml
Expand Down Expand Up @@ -311,6 +317,8 @@ jobs:
-D CMAKE_INSIST_FIND_PACKAGE_dkh=ON \
-D ENABLE_ecpint=OFF \
-D CMAKE_INSIST_FIND_PACKAGE_ecpint=ON \
-D ENABLE_Einsums=ON \
-D CMAKE_INSIST_FIND_PACKAGE_Einsums=ON \
-D ENABLE_gdma=ON \
-D CMAKE_INSIST_FIND_PACKAGE_gdma=ON \
-D ENABLE_PCMSolver=OFF \
Expand Down Expand Up @@ -352,6 +360,8 @@ jobs:
-D CMAKE_INSIST_FIND_PACKAGE_dkh=ON \
-D ENABLE_ecpint=OFF \
-D CMAKE_INSIST_FIND_PACKAGE_ecpint=ON \
-D ENABLE_Einsums=ON \
-D CMAKE_INSIST_FIND_PACKAGE_Einsums=ON \
-D ENABLE_gdma=ON \
-D CMAKE_INSIST_FIND_PACKAGE_gdma=ON \
-D ENABLE_PCMSolver=OFF \
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ message(STATUS "Building using CMake ${CMAKE_VERSION} Generator ${CMAKE_GENERATO
# - Python_INCLUDE_DIR "Path to the python include files (e.g., /path/to/include/python3.7)"
# - SPHINX_ROOT "Root directory for Sphinx: 'bin/sphinx-build' (or similar) should be in this dir."
#
# For any ${AddOn} of: ambit, CheMPS2, dkh, ecpint, libefp, erd, gau2grid, gdma, Libint2, PCMSolver, pybind11, pylibefp,
# For any ${AddOn} of: ambit, CheMPS2, dkh, ecpint, libefp, Einsums, erd, gau2grid, gdma, Libint2, PCMSolver, pybind11, pylibefp,
# qcelemental, qcengine, optking, simint, Libxc
# - CMAKE_PREFIX_PATH "Set to list of root directories to look for externally built add-ons and dependencies
# (e.g., /path/to/install-libint;/path/to/install-gdma where exists /path/to/install-libint/lib/libderiv.a)"
Expand Down Expand Up @@ -108,6 +108,7 @@ option(ENABLE_ddx "Enables ddx for domain-decomposition contiuum solvation model
option(ENABLE_dkh "Enables DKH integrals (requires Fortran)" OFF)
option(ENABLE_ecpint "Enables libecpint for effective core potentials (ECP)" OFF)
option(ENABLE_libefp "Enables LIBEFP and PylibEFP for fragments" OFF)
option(ENABLE_Einsums "Enables the Einsums tensor library" OFF)
option(ENABLE_erd "Enables use of ERD instead of Libint (requires Fortran)" OFF)
option(ENABLE_simint "Enables use of SIMINT two-electron integral library" OFF)
option(ENABLE_gdma "Enables Stone's GDMA multipole code (requires Fortran; can also be added at runtime)" OFF)
Expand Down Expand Up @@ -231,6 +232,7 @@ ExternalProject_Add(psi4-core
dkh_external
ecpint_external
libefp_external
einsums_external
erd_external
gau2grid_external
gdma_external
Expand Down Expand Up @@ -281,6 +283,7 @@ ExternalProject_Add(psi4-core
-DENABLE_dkh=${ENABLE_dkh}
-DENABLE_ecpint=${ENABLE_ecpint}
-DENABLE_libefp=${ENABLE_libefp}
-DENABLE_Einsums=${ENABLE_Einsums}
-DENABLE_erd=${ENABLE_erd}
-DENABLE_simint=${ENABLE_simint}
-DENABLE_gdma=${ENABLE_gdma}
Expand All @@ -298,6 +301,7 @@ ExternalProject_Add(psi4-core
-Ddkh_DIR=${dkh_DIR}
-Decpint_DIR=${ecpint_DIR}
-Dlibefp_DIR=${libefp_DIR}
-DEinsums_DIR=${Einsums_DIR}
-Derd_DIR=${erd_DIR}
-Dgau2grid_DIR=${gau2grid_DIR}
-Dgdma_DIR=${gdma_DIR}
Expand Down
2 changes: 1 addition & 1 deletion external/common/hdf5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(ENABLE_ambit OR ENABLE_CheMPS2)
if(ENABLE_ambit OR ENABLE_CheMPS2 OR ENABLE_Einsums)
project(TargetHDF5)
set(PN ${PROJECT_NAME})

Expand Down
15 changes: 14 additions & 1 deletion external/common/lapack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ foreach(_l IN LISTS LAPACK_LIBRARIES)
break()
endif()
endforeach()
if(isMKL STREQUAL " MKL")
set(_VENDOR "MKL")
else()
set(_VENDOR "All")
endif()
set_target_properties(
lapack
PROPERTIES
VENDOR ${_VENDOR}
INT_INTERFACE lp64 # Psi4 only works with lp64 afaik
)
set(export_properties "VENDOR;INT_INTERFACE")
set_property(TARGET lapack APPEND PROPERTY EXPORT_PROPERTIES "${export_properties}")

# << Detect OpenMP and modify for BLAS/LAPACK >>
if(NOT TARGET tgt::MathOpenMP)
Expand All @@ -47,7 +60,7 @@ list(GET _ill 0 _ill0)
message(STATUS "${Cyan}Found LAPACK${isMKL}${ColourReset}: ${_ill0};...")

if(NOT (${isMKL} MATCHES "MKL"))
message(WARNING "${Yellow}MKL is the only BLAS/LAPACK distribution thoroughly tested with Psi4. Several others are mostly fine, with problems cropping up in particular modules or when running in threaded mode. When using a non-MKL distribution, please run the test suite in full and also run particular tests in threaded mode, if you plan to run Psi4 threaded. MKL is freely available through conda; see instructions to compile against conda MKL through the 'source' option on the download website page.${ColourReset}")
message(WARNING "${Yellow}MKL is the only BLAS/LAPACK distribution thoroughly tested with Psi4. Several others are mostly fine, with problems cropping up in particular modules or when running in threaded mode. When using a non-MKL distribution, please run the test suite in full and also run particular tests in threaded mode, if you plan to run Psi4 threaded. MKL is freely available through conda; see instructions to compile against conda MKL through the 'source' option on the download website page. OpenBLAS also seems to work, but be sure you're using the OpenMP, not the pthreads, variant.${ColourReset}")
endif()

unset(BLAS_LIBRARIES)
Expand Down
1 change: 1 addition & 0 deletions external/upstream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ foreach(dir
dkh
ecpint
libefp
einsums
erd
gau2grid
gdma
Expand Down
58 changes: 58 additions & 0 deletions external/upstream/einsums/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
if(${ENABLE_Einsums})
find_package(Einsums 0.3 CONFIG)

if(TARGET Einsums::einsums)
get_property(_loc TARGET Einsums::einsums PROPERTY LOCATION)
message(STATUS "${Cyan}Found Einsums${ColourReset}: ${_loc} (found version ${Einsums_VERSION})")
add_library(einsums_external INTERFACE) # dummy

# reset below necessary as find_package clears it. better solution sought
set(TargetHDF5_DIR ${STAGED_INSTALL_PREFIX}/share/cmake/TargetHDF5 CACHE PATH "path to externally detected TargetHDF5Config.cmake" FORCE)
else()
if(${CMAKE_INSIST_FIND_PACKAGE_Einsums})
message(FATAL_ERROR "Suitable Einsums could not be externally located as user insists")
endif()

include(ExternalProject)
message(STATUS "Suitable Einsums could not be located, ${Magenta}Building Einsums${ColourReset} instead.")

if(${BUILD_SHARED_LIBS})
set(_a_only OFF)
else()
set(_a_only ON)
endif()

set(_einsums_dir "share/cmake/Einsums")

ExternalProject_Add(einsums_external
DEPENDS lapack_external
hdf5_external
URL https://github.com/Einsums/Einsums/archive/v0.3.tar.gz
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DEINSUMS_STATIC_BUILD=${_a_only}
-DEXTRA_C_FLAGS=${CMAKE_C_FLAGS}
-DEXTRA_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DEINSUMS_INSTALL_CMAKEDIR=${_einsums_dir}
# -DENABLE_XHOST=${ENABLE_XHOST}
-DEINSUMS_ENABLE_TESTING=OFF
-DEINSUMS_USE_HPTT=ON
# -DOpenMP_LIBRARY_DIRS=${OpenMP_LIBRARY_DIRS}
-DTargetLAPACK_DIR=${TargetLAPACK_DIR}
-DTargetHDF5_DIR=${TargetHDF5_DIR}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
CMAKE_CACHE_ARGS -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DTargetOpenMP_FIND_COMPONENTS:STRING=C;CXX)

set(Einsums_DIR ${STAGED_INSTALL_PREFIX}/${_einsums_dir} CACHE PATH "path to internally built EinsumsConfig.cmake" FORCE)
endif()
else()
add_library(einsums_external INTERFACE) # dummy
endif()
11 changes: 10 additions & 1 deletion psi4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ get_property(_illb TARGET tgt::blas PROPERTY INTERFACE_LINK_LIBRARIES)
list(APPEND _addons ${_ill} ${_illb})
message(STATUS "${Cyan}Using LAPACK${_isMKL}${ColourReset}: ${_ill0};...")

if(ENABLE_ambit OR ENABLE_CheMPS2)
if(ENABLE_ambit OR ENABLE_CheMPS2 OR ENABLE_Einsums)
find_package(TargetHDF5 CONFIG REQUIRED)
get_property(_ill TARGET tgt::hdf5 PROPERTY INTERFACE_LINK_LIBRARIES)
list(GET _ill 0 _ill0)
Expand Down Expand Up @@ -117,6 +117,15 @@ else()
message(STATUS "Disabled libefp")
endif()

if(${ENABLE_Einsums})
find_package(Einsums 0.3 CONFIG REQUIRED)
get_property(_loc TARGET Einsums::einsums PROPERTY LOCATION)
list(APPEND _addons ${_loc})
message(STATUS "${Cyan}Using Einsums${ColourReset}: ${_loc} (version ${Einsums_VERSION})")
else()
message(STATUS "Disabled Einsums")
endif ()

if(${ENABLE_erd})
find_package(erd 3.0.6 CONFIG REQUIRED)
get_property(_loc TARGET erd::erd PROPERTY LOCATION)
Expand Down
1 change: 1 addition & 0 deletions psi4/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def psi4_which(command, *, return_bool: bool = False, raise_error: bool = False,
"psixas": which_import("psixas", return_bool=True),
#"mctc-gcp": psi4_which("mctc-gcp", return_bool=True),
"bse": which_import("basis_set_exchange", return_bool=True),
"einsums": _CMake_to_Py_boolean("@ENABLE_Einsums@"),
}


Expand Down
7 changes: 7 additions & 0 deletions psi4/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ if(TARGET ECPINT::ecpint)
)
endif()

if(TARGET Einsums::einsums)
target_compile_definitions(core
PRIVATE
USING_Einsums
)
endif()

if(TARGET BrianQC::static_wrapper)
target_compile_definitions(core
PRIVATE
Expand Down
16 changes: 16 additions & 0 deletions psi4/src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ SharedWavefunction mcscf(SharedWavefunction, Options&);
namespace psimrcc {
SharedWavefunction psimrcc(SharedWavefunction, Options&);
}
namespace dummy_einsums {
SharedWavefunction dummy_einsums (SharedWavefunction, Options&);
}


// Matrix returns
namespace scfgrad {
Expand Down Expand Up @@ -492,6 +496,17 @@ SharedWavefunction py_psi_psimrcc(SharedWavefunction ref_wfn) {
return psimrcc::psimrcc(ref_wfn, Process::environment.options);
}

#ifdef USING_Einsums
SharedWavefunction py_psi_dummy_einsums(SharedWavefunction ref_wfn) {
py_psi_prepare_options_for_module("EINSUMS");
return dummy_einsums::dummy_einsums(ref_wfn, Process::environment.options);
}
#else
double py_psi_dummy_einsums(SharedWavefunction ref_wfn) {
throw PSIEXCEPTION("Einsums not enabled. Recompile with -DENABLE_Einsums");
}
#endif

void py_psi_clean() { PSIOManager::shared_object()->psiclean(); }

void py_psi_print_options() { Process::environment.options.print(); }
Expand Down Expand Up @@ -1324,6 +1339,7 @@ PYBIND11_MODULE(core, core) {
core.def("cceom", py_psi_cceom, "ref_wfn"_a, "Runs the equation of motion coupled cluster code for excited states.");
core.def("occ", py_psi_occ, "ref_wfn"_a, "Runs the orbital optimized CC codes.");
core.def("dfocc", py_psi_dfocc, "ref_wfn"_a, "Runs the density-fitted orbital optimized CC codes.");
core.def("dummy_einsums", py_psi_dummy_einsums, "ref_wfn"_a, "Runs the einsums placeholder code.");
core.def("get_options", py_psi_get_options, py::return_value_policy::reference, "Get options");
core.def("set_output_file", [](const std::string ofname) {
if (ofname == "stdout") {
Expand Down
1 change: 1 addition & 0 deletions psi4/src/psi4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ foreach(dir_name
psimrcc
sapt
scfgrad
dummy_einsums
)
add_subdirectory(${dir_name})
endforeach ()
29 changes: 29 additions & 0 deletions psi4/src/psi4/dummy_einsums/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
list(APPEND sources
ein_test.cc
)

if(TARGET Einsums::einsums)
psi4_add_module(bin dummy_einsums sources)
target_link_libraries(
dummy_einsums
PRIVATE
Einsums::einsums
)
endif()

if(DEFINED ENV{CONDA_TOOLCHAIN_BUILD})
if(APPLE)
# * possibly these should be exported from Einsums somehow
# * when using conda clang, compiling against an old SDK &
# an openmp symbols is absent
# * afaik, envvar above is defined when `conda activate envvar_w_compilers`.
# There's a CONDA_BACKUP_CONDA_TOOLCHAIN_BUILD envvar when not activated.
# So hopefully, this doesn't interfere with system compilers.
target_compile_definitions(
dummy_einsums
PUBLIC
_LIBCPP_DISABLE_AVAILABILITY
H5CPP_USE_OMP_ALIGNED_ALLOC
)
endif()
endif()
Loading

0 comments on commit dfe7fe8

Please sign in to comment.