Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
corochann committed May 10, 2021
0 parents commit 5a84423
Show file tree
Hide file tree
Showing 39 changed files with 3,464 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .flexci/build_and_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash -uex

IMAGE_BASE="${1:-}"
IMAGE_PUSH=1
if [ "${IMAGE_BASE}" = "" ]; then
IMAGE_BASE="torch-dftd3"
IMAGE_PUSH=0
fi

TEST_PIP_PACKAGES="
flake8 pytest pytest-cov pytest-xdist pytest-benchmark
"

SRC_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/.."; pwd)"

docker_build_and_push() {

IMAGE_TAG="${1}"; shift
IMAGE_NAME="${IMAGE_BASE}:${IMAGE_TAG}"

pushd "$(dirname ${0})"
docker build -f ${SRC_ROOT}/docker/Dockerfile -t "${IMAGE_NAME}" "$@" .
popd

if [ "${IMAGE_PUSH}" = "0" ]; then
echo "Skipping docker push."
else
docker push "${IMAGE_NAME}"
fi
}

WAIT_PIDS=""

# PyTorch 1.5 + Python 3.6
docker_build_and_push torch15 \
--build-arg base_image="nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04" \
--build-arg python_version="3.6.12" \
--build-arg pip_packages="torch==1.5.* torchvision==0.6.* ${TEST_PIP_PACKAGES}" &
WAIT_PIDS="$! ${WAIT_PIDS}"

# Wait until the build complete.
for P in ${WAIT_PIDS}; do
wait ${P}
done
14 changes: 14 additions & 0 deletions .flexci/config.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
configs {
# Project name.
key: "torch-dftd.pytest"
value {
requirement {
cpu: 4
memory: 16
disk: 10
gpu: 1
}
command:
"bash -x .flexci/pytest_script.sh"
}
}
41 changes: 41 additions & 0 deletions .flexci/pytest_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -eu

#IMAGE=pytorch/pytorch:1.5.1-cuda10.1-cudnn7-devel
IMAGE=asia.gcr.io/pfn-public-ci/torch-dftd3-ci:torch15


main() {
SRC_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/../.."; pwd)"

prepare_docker &
wait

# Build and push docker images for unit tests.
# bash -x -c "${SRC_ROOT}/.flexci/build_and_push.sh" \
# "${IMAGE}"

# 1st pytest: when xdist is enabled with `-n $(nproc)`, benchmark is not executed.
# 2nd pytest: only execute pytest-benchmark.
docker run --runtime=nvidia --rm --volume="$(pwd)":/workspace -w /workspace \
${IMAGE} \
bash -x -c "pip install flake8 pytest pytest-cov pytest-xdist pytest-benchmark && \
pip install cupy-cuda102 pytorch-pfn-extras && \
pip install -e . && \
pysen run lint && \
pytest --cov=torch_dftd -n $(nproc) -m 'not slow' tests &&
pytest --benchmark-only tests"
}


# prepare_docker makes docker use tmpfs to speed up.
# CAVEAT: Do not use docker during this is running.
prepare_docker() {
service docker stop
mount -t tmpfs -o size=100% tmpfs /var/lib/docker
service docker start
gcloud auth configure-docker
}


main "$@"
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# PyCharm
.idea/
tests/ase_dftd3.out
tests/ase_dftd3.xyz
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Preferred Networks, Inc.

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.
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# torch-dftd
pytorch implementation of dftd2 [1] & dftd3 [2, 3]

## Install

```bash
git clone https://github.com/pfnet-research/torch-dftd
pip install -e .
```

## Quick start

```python
from ase.build import molecule
from torch_dftd.torch_dftd3_calculator import TorchDFTD3Calculator

atoms = molecule("CH3CH2OCH3")
# device="cuda:0" for fast GPU computation.
calc = TorchDFTD3Calculator(atoms=atoms, device="cpu", damping="bj")

energy = atoms.get_potential_energy()
forces = atoms.get_forces()

print(f"energy {energy} eV")
print(f"forces {forces}")
```

## Dependency

The library is tested under following environment.
- python: 3.6
- CUDA: 10.2
```bash
torch==1.5.1
ase==3.21.1
# Below is only for 3-body term
cupy-cuda102==8.6.0
pytorch-pfn-extras==0.3.2
```

## Development tips
### Formatting & Linting
[pysen](https://github.com/pfnet/pysen) is used to format the python code of this repository.<br/>
You can simply run below to get your code formatted :)
```bash
# Format the code
$ pysen run format
# Check the code format
$ pysen run lint
```

### CUDA Kernel function implementation with cupy
[cupy](https://github.com/cupy/cupy) supports users to implement CUDA kernels within python code,
and it can be easily linked with pytorch tensor calculations.<br/>
Element wise kernel is implemented and used in some pytorch functions to accelerate speed with GPU.

See [document](https://docs.cupy.dev/en/stable/user_guide/kernel.html) for details about user defined kernel.

## Citation

Please always cite original paper of DFT-D2 [1] or DFT-D3 [2, 3], if you used this software for your publication.

DFT-D2:<br/>
[1] S. Grimme, J. Comput. Chem, 27 (2006), 1787-1799.
DOI: [10.1002/jcc.20495](https://doi.org/10.1002/jcc.20495)

DFT-D3:<br/>
[2] S. Grimme, J. Antony, S. Ehrlich and H. Krieg, J. Chem. Phys, 132 (2010), 154104.
DOI: [10.1063/1.3382344](https://doi.org/10.1063/1.3382344)

If BJ-damping is used in DFT-D3:<br/>
[3] S. Grimme, S. Ehrlich and L. Goerigk, J. Comput. Chem, 32 (2011), 1456-1465.
DOI: [10.1002/jcc.21759](https://doi.org/10.1002/jcc.21759)
37 changes: 37 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
ARG base_image
FROM ${base_image}

# Install pyenv requirements.
# https://github.com/pyenv/pyenv/wiki/Common-build-problems#requirements
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -y update && \
apt-get -y install \
build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev git gfortran && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

# Install pyenv.
RUN git clone https://github.com/pyenv/pyenv.git /opt/pyenv
ENV PYENV_ROOT=/opt/pyenv
ENV PATH ${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}

# Install Python.
ARG python_version
RUN pyenv install ${python_version} && \
pyenv global ${python_version}

# Install test dependencies.
ARG pip_packages
RUN pip install -U pip && \
pip install ${pip_packages} && \
pip list

# Install DFTD3
RUN cd /tmp && \
wget https://www.chemie.uni-bonn.de/pctc/mulliken-center/software/dft-d3/dftd3.tgz && \
tar zxvf dftd3.tgz && \
make && \
mv dftd3 /usr/local/bin && \
rm dftd3.tgz
Loading

0 comments on commit 5a84423

Please sign in to comment.