From 123c316c335ddab8fd05510358bcd9424555e4ef Mon Sep 17 00:00:00 2001 From: Qiming Sun Date: Sat, 27 Apr 2024 15:39:51 -0700 Subject: [PATCH] Skip compiling SMD by default --- .github/workflows/ci_macos/deps_apt.sh | 2 +- .github/workflows/publish.yml | 9 +++++---- pyscf/lib/CMakeLists.txt | 6 +++++- pyscf/solvent/__init__.py | 2 +- pyscf/solvent/smd.py | 7 ++++++- pyscf/solvent/test/test_smd.py | 6 +++++- pyscf/solvent/test/test_smd_grad.py | 6 +++++- pyscf/solvent/test/test_smd_hessian.py | 6 +++++- 8 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci_macos/deps_apt.sh b/.github/workflows/ci_macos/deps_apt.sh index 9e0e1d76b2..a399aa5427 100755 --- a/.github/workflows/ci_macos/deps_apt.sh +++ b/.github/workflows/ci_macos/deps_apt.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -brew reinstall gcc \ No newline at end of file +#brew reinstall gcc diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5f26d085da..2e7799c48c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,7 +17,7 @@ jobs: - name: Build wheels run: | docker run --rm -v ${{ github.workspace }}:/src/pyscf \ - -e CMAKE_BUILD_PARALLEL_LEVEL=4 \ + -e CMAKE_BUILD_PARALLEL_LEVEL=4 -e CMAKE_CONFIGURE_ARGS="-DENABLE_SMD=ON" \ pyscf/pyscf-pypa-env:latest \ bash /src/pyscf/docker/pypa-env/build-wheels.sh - name: List available wheels @@ -58,7 +58,7 @@ jobs: yum install -y openblas-devel gcc && \ export src=${GITHUB_WORKSPACE:-/src/pyscf} && \ export dst=${GITHUB_WORKSPACE:-/src/pyscf}/linux-wheels && \ - export CMAKE_CONFIGURE_ARGS="-DWITH_F12=OFF" && \ + export CMAKE_CONFIGURE_ARGS="-DWITH_F12=OFF -DENABLE_SMD=ON" && \ export CMAKE_BUILD_PARALLEL_LEVEL=4 && \ mkdir -p /root/wheelhouse $src/linux-wheels && \ sed -i "/ if basename(fn) not in needed_libs:/s/basename.*libs/1/" /opt/_internal/pipx/venvs/auditwheel/lib/python*/site-packages/auditwheel/wheel_abi.py && \ @@ -111,7 +111,7 @@ jobs: env: CIBW_BUILD: cp311-macosx_x86_64 CIBW_BUILD_VERBOSITY: "1" - CMAKE_CONFIGURE_ARGS: "-DWITH_F12=OFF" + CMAKE_CONFIGURE_ARGS: "-DWITH_F12=OFF -DENABLE_SMD=ON" CMAKE_BUILD_PARALLEL_LEVEL: "4" with: output-dir: mac-wheels @@ -137,7 +137,7 @@ jobs: CIBW_BUILD_VERBOSITY: "1" # Cross-platform build for arm64 wheels on x86 platform CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" - CMAKE_CONFIGURE_ARGS: "-DWITH_F12=OFF" + CMAKE_CONFIGURE_ARGS: "-DWITH_F12=OFF -DENABLE_SMD=OFF" CMAKE_BUILD_PARALLEL_LEVEL: "4" CMAKE_OSX_ARCHITECTURES: arm64 with: @@ -168,6 +168,7 @@ jobs: - name: Publish to conda run: | export CMAKE_BUILD_PARALLEL_LEVEL=4 + export CMAKE_CONFIGURE_ARGS="-DENABLE_SMD=ON" export ANACONDA_API_TOKEN=${{ secrets.ANACONDA_TOKEN }} conda install -y anaconda-client conda-build conda config --set anaconda_upload yes diff --git a/pyscf/lib/CMakeLists.txt b/pyscf/lib/CMakeLists.txt index eb138e1e1f..c41dcc2b35 100644 --- a/pyscf/lib/CMakeLists.txt +++ b/pyscf/lib/CMakeLists.txt @@ -149,7 +149,11 @@ add_subdirectory(ri) #add_subdirectory(localizer) add_subdirectory(pbc) add_subdirectory(agf2) -add_subdirectory(solvent) + +option(ENABLE_SMD "Compiling SMD Fortran code" OFF) +if(ENABLE_SMD) + add_subdirectory(solvent) +endif(ENABLE_SMD) # Overwrite CMAKE_C_CREATE_SHARED_LIBRARY in Modules/CMakeCInformation.cmake # to remove the SONAME flag in the so file. The soname information causes diff --git a/pyscf/solvent/__init__.py b/pyscf/solvent/__init__.py index 0eb81f9aac..40cdc46106 100644 --- a/pyscf/solvent/__init__.py +++ b/pyscf/solvent/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pyscf.solvent import ddcosmo, pcm, smd +from pyscf.solvent import ddcosmo, pcm def ddCOSMO(method_or_mol, solvent_obj=None, dm=None): '''Initialize ddCOSMO model. diff --git a/pyscf/solvent/smd.py b/pyscf/solvent/smd.py index 8a32c87812..032e9c3957 100644 --- a/pyscf/solvent/smd.py +++ b/pyscf/solvent/smd.py @@ -252,7 +252,12 @@ def smd_radii(alpha): import ctypes from pyscf.lib import load_library -libsolvent = load_library('libsolvent') +try: + libsolvent = load_library('libsolvent') +except NameError: + # SMD module was not compiled + libsolvent = None + def get_cds_legacy(smdobj): mol = smdobj.mol natm = mol.natm diff --git a/pyscf/solvent/test/test_smd.py b/pyscf/solvent/test/test_smd.py index 3dc75286e2..1b93b486ca 100644 --- a/pyscf/solvent/test/test_smd.py +++ b/pyscf/solvent/test/test_smd.py @@ -52,6 +52,10 @@ def _check_smd(atom, e_ref, solvent='water'): assert numpy.abs(e_cds - e_ref) < 1e-3 class KnownValues(unittest.TestCase): + def setUp(self): + if smd.libsolvent is None: + raise self.SkipTest('SMD Fortran library not compiled') + def test_cds_solvent(self): smdobj = smd.SMD(mol) smdobj.sasa_ng = 590 @@ -227,4 +231,4 @@ def test_Cl(self): if __name__ == "__main__": print("Full Tests for SMDs") - unittest.main() \ No newline at end of file + unittest.main() diff --git a/pyscf/solvent/test/test_smd_grad.py b/pyscf/solvent/test/test_smd_grad.py index abbb47336f..41a779a7eb 100644 --- a/pyscf/solvent/test/test_smd_grad.py +++ b/pyscf/solvent/test/test_smd_grad.py @@ -75,6 +75,10 @@ def _check_grad(atom, solvent='water'): assert numpy.linalg.norm(fd_cds - grad_cds) < 1e-8 class KnownValues(unittest.TestCase): + def setUp(self): + if smd.libsolvent is None: + raise self.SkipTest('SMD Fortran library not compiled') + def test_grad_water(self): mf = dft.rks.RKS(mol, xc='b3lyp').SMD() mf.grids.atom_grid = (99,590) @@ -235,4 +239,4 @@ def test_Br(self): if __name__ == "__main__": print("Full Tests for Gradient of SMD") - unittest.main() \ No newline at end of file + unittest.main() diff --git a/pyscf/solvent/test/test_smd_hessian.py b/pyscf/solvent/test/test_smd_hessian.py index 82a61b3017..0d4cf715a3 100644 --- a/pyscf/solvent/test/test_smd_hessian.py +++ b/pyscf/solvent/test/test_smd_hessian.py @@ -67,6 +67,10 @@ def _check_hess(atom, solvent='water'): assert(numpy.linalg.norm(hess_cds[0,:,0,:] - h_fd) < 1e-3) class KnownValues(unittest.TestCase): + def setUp(self): + if smd.libsolvent is None: + raise self.SkipTest('SMD Fortran library not compiled') + def test_h2o(self): h2o = gto.Mole() h2o.atom = ''' @@ -210,4 +214,4 @@ def test_Br(self): if __name__ == "__main__": print("Full Tests for Hessian of SMD") - unittest.main() \ No newline at end of file + unittest.main()