Skip to content

Commit

Permalink
update for release
Browse files Browse the repository at this point in the history
  • Loading branch information
fishjojo committed Mar 5, 2024
1 parent 29084da commit 31f5ec2
Show file tree
Hide file tree
Showing 94 changed files with 27,967 additions and 213 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2023 Xing Zhang
Copyright (c) 2021-2024 Xing Zhang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 2 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
include MANIFEST.in
include README.md setup.py LICENSE

prune pyscfad/lib/build
include pyscfad/geomopt/log.ini

include pyscfad/lib/*.so
include pyscfad/lib/*.dylib

recursive-include pyscfad/lib *.c *.h
global-exclude *.py[cod]
50 changes: 3 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,11 @@ Installation
---
* To install the latest release, use the following commands:
```
# install cmake
pip install cmake
# install OpenMP runtime used with clang
# On Linux:
sudo apt update
sudo apt install libomp-dev
# On OSX:
brew install libomp
# install pyscf
pip install 'pyscf @ git+https://github.com/fishjojo/pyscf.git@ad#egg=pyscf'
pip install 'pyscf-properties @ git+https://github.com/fishjojo/properties.git@ad'
# install pyscfad
pip install pyscfad
# install pyscfadlib, optional
pip install pyscfadlib
```

---
Expand All @@ -36,32 +24,6 @@ pip install pyscfad
pip install git+https://github.com/fishjojo/pyscfad.git
```

* The dependencies can be installed via a predefined conda environment
```
conda env create -f environment.yml
conda activate pyscfad_env
```

* Alternatively, the dependencies can be installed from source
```
pip install numpy scipy h5py
pip install jax jaxlib jaxopt
# install pyscf
cd $HOME; git clone https://github.com/fishjojo/pyscf.git
cd pyscf; git checkout ad
cd pyscf/lib; mkdir build
cd build; cmake ..; make
export PYTHONPATH=$HOME/pyscf:$PYTHONPATH
```

---
* One can also run PySCFAD inside a docker container:
```
docker pull fishjojo/pyscfad:latest
docker run -rm -t -i fishjojo/pyscfad:latest /bin/bash
```

Running examples
----------------
Expand All @@ -71,10 +33,4 @@ the following lines need to be added to
the PySCF configure file($HOME/.pyscf\_conf.py)
```
pyscfad = True
pyscf_numpy_backend = 'jax'
pyscf_scipy_linalg_backend = 'pyscfad'
pyscf_scipy_backend = 'jax'
# The followings are optional
pyscfad_scf_implicit_diff = True
pyscfad_ccsd_implicit_diff = True
```
13 changes: 10 additions & 3 deletions examples/cc/00-simple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import jax
from pyscfad import gto, scf, cc
'''
Reference nuclear gradient
[[0.0, 0.0, -1.15101379e-01]
Expand All @@ -8,10 +6,19 @@
Note that without implicit differentiation turned on,
the gradient will be initial guess dependent.
'''
import jax
from pyscfad import gto, scf, cc
from pyscfad import config

# implicit differentiation of SCF iterations
config.update('pyscfad_scf_implicit_diff', True)
# implicit differentiation of CC iterations
config.update('pyscfad_ccsd_implicit_diff', True)

mol = gto.Mole()
mol.atom = 'H 0. 0. 0.; F 0. 0. 1.1'
mol.basis = 'ccpvdz'
mol.verbose = 3
mol.verbose = 4
mol.incore_anyway = True
mol.build()

Expand Down
21 changes: 12 additions & 9 deletions examples/gw/01-rpa.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import jax
from pyscf import df as pyscf_df
from pyscfad import gto, dft, scf, df
from pyscfad.gw import rpa
from pyscfad import config

config.update('pyscfad_scf_implicit_diff', True)
config.update('pyscfad_moleintor_opt', True)

'''
RPA e_tot, e_hf, e_corr = -76.26428191794197 -75.95645187758402 -0.30783004035795963
Expand Down Expand Up @@ -39,6 +30,18 @@
'''

import jax
from pyscf import df as pyscf_df
from pyscfad import gto, dft, scf, df
from pyscfad.gw import rpa
from pyscfad import config

config.update('pyscfad_scf_implicit_diff', True)
# Using optimized C implementation for gradients calculations.
# This requires the `pyscfadlib` package, which can be installed with
# `pip install pyscfadlib`
#config.update('pyscfad_moleintor_opt', True)

mol = gto.Mole()
mol.verbose = 4
mol.atom = [
Expand Down
13 changes: 8 additions & 5 deletions examples/mp/00-simple.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""
Analytic nuclear gradient for MP2 computed by auto-differentiation
"""
import jax
import pyscf
from pyscfad import gto, scf, mp
from pyscfad import config

"""
Analytic nuclear gradient for MP2 computed by auto-differentiation
"""
# implicit differentiation of SCF iterations
config.update('pyscfad_scf_implicit_diff', True)

mol = gto.Mole()
mol.atom = 'H 0 0 0; H 0 0 0.74' # in Angstrom
mol.atom = 'H 0 0 0; H 0 0 0.74'
mol.basis = '631g'
mol.verbose=5
mol.verbose=4
mol.build()

def mp2(mol, dm0=None):
Expand Down
2 changes: 1 addition & 1 deletion pyscfad/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.2"
__version__ = "0.1.4"
21 changes: 21 additions & 0 deletions pyscfadlib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-2024 Xing Zhang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions pyscfadlib/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include MANIFEST.in
include README.md setup.py LICENSE

recursive-include pyscfadlib/thirdparty *.so
include pyscfadlib/*.so pyscfadlib/config.h.in

# macos dynamic libraries
include pyscfadlib/*.dylib
include pyscfadlib/thirdparty/lib*/*.dylib

# source code
recursive-include pyscfadlib *.c *.h CMakeLists.txt

global-exclude *.py[cod]
prune pyscfadlib/build
2 changes: 2 additions & 0 deletions pyscfadlib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyscfadlib is the support library for PySCFAD.
It contains most of the C optimized code for derivative calculations.
14 changes: 14 additions & 0 deletions pyscfadlib/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.cibuildwheel]
build-verbosity = 1
container-engine = "docker"
manylinux-x86_64-image = "manylinux2014"
skip = ["pp*", "*musllinux*"]

[tool.cibuildwheel.linux]
archs = ["x86_64"]
before-all = [
"ulimit -n 1024",
"ln -s libquadmath.so.0 /usr/lib64/libquadmath.so",
"yum install -y openblas-devel.x86_64",
]
repair-wheel-command = "auditwheel -v repair -w {dest_dir} {wheel}"
1 change: 0 additions & 1 deletion pyscfadlib/pyscf.patch

This file was deleted.

38 changes: 0 additions & 38 deletions pyscfadlib/pyscf.patch.2.3

This file was deleted.

49 changes: 18 additions & 31 deletions pyscfadlib/CMakeLists.txt → pyscfadlib/pyscfadlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.18)
cmake_minimum_required (VERSION 3.5)
project (pyscfadlib)

if (NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -39,6 +39,18 @@ endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)

if (NOT BLAS_LIBRARIES)
#enable_language(Fortran)
find_package(BLAS)
check_function_exists(ffsll HAVE_FFS)
endif()

if (NOT BLAS_LIBRARIES)
message(FATAL_ERROR "A required library with BLAS API not found.")
else()
message(STATUS "BLAS libraries: ${BLAS_LIBRARIES}")
endif()

option(ENABLE_OPENMP "Compiling C extensions with openmp" ON)
set(OPENMP_C_PROPERTIES "")
if(ENABLE_OPENMP)
Expand Down Expand Up @@ -72,6 +84,9 @@ else ()
set(CMAKE_INSTALL_RPATH "\$ORIGIN:\$ORIGIN/thirdparty/lib:\$ORIGIN/thirdparty/lib64")
endif()

add_subdirectory(np_helper)
add_subdirectory(gto)
add_subdirectory(vhf)
add_subdirectory(vjp)

set(C_LINK_TEMPLATE "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
Expand Down Expand Up @@ -101,37 +116,9 @@ if(BUILD_LIBCINT)
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_LIBDIR:PATH=lib
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DBLAS_LIBRARIES:STRING=${BLAS_LIBRARIES}
-DCMAKE_C_CREATE_SHARED_LIBRARY:STRING=${C_LINK_TEMPLATE}
-DBUILD_MARCH_NATIVE:STRING=${BUILD_MARCH_NATIVE}
)
add_dependencies(cgto_vjp libcint)
endif()

option(BUILD_PYSCF_LIB "Building PySCF library" ON)

set(patch_pyscf ${PROJECT_SOURCE_DIR}/apply_patch.sh pyscf.patch)

if(BUILD_PYSCF_LIB)
ExternalProject_Add(pyscf
GIT_REPOSITORY https://github.com/pyscf/pyscf.git
GIT_TAG v2.3.0
PATCH_COMMAND ${patch_pyscf}
SOURCE_SUBDIR "pyscf/lib"
PREFIX ${PROJECT_BINARY_DIR}/thirdparty
INSTALL_DIR ${PROJECT_SOURCE_DIR}/thirdparty
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_INSTALL_LIBDIR:PATH=lib
-DCMAKE_INSTALL_INCLUDEDIR:PATH=include/pyscf
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DBLA_VENDOR:STRING=${BLA_VENDOR}
-DENABLE_LIBXC:STRING=OFF
-DENABLE_XCFUN:STRING=OFF
#-DBUILD_LIBCINT:STRING=OFF
)
add_dependencies(cgto_vjp pyscf)
add_dependencies(np_helper_vjp pyscf)
add_dependencies(ao2mo_vjp pyscf)
add_dependencies(cvhf_vjp pyscf)
add_dependencies(cc_vjp pyscf)
add_dependencies(cgto libcint)
endif()
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions pyscfadlib/pyscfadlib/copy_pyscf_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

git clone https://github.com/pyscf/pyscf.git
cd pyscf
git checkout 'v2.3.0'

cp -rf pyscf/lib/vhf ../vhf
cp -rf pyscf/lib/gto ../gto
cp -rf pyscf/lib/np_helper ../np_helper
26 changes: 26 additions & 0 deletions pyscfadlib/pyscfadlib/gto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2014-2018 The PySCF Developers. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_library(cgto SHARED
fill_int2c.c fill_nr_3c.c fill_r_3c.c fill_int2e.c fill_r_4c.c
ft_ao.c ft_ao_deriv.c fill_grids_int2c.c
grid_ao_drv.c deriv1.c deriv2.c nr_ecp.c nr_ecp_deriv.c
autocode/auto_eval1.c)
add_dependencies(cgto np_helper)

set_target_properties(cgto PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})

target_link_libraries(cgto cintad np_helper ${BLAS_LIBRARIES} ${OPENMP_C_PROPERTIES})

Loading

0 comments on commit 31f5ec2

Please sign in to comment.