From 11a7d96bb03dff74f9c0f1de2c326f075b96bc58 Mon Sep 17 00:00:00 2001 From: Stephen Farr Date: Fri, 11 Nov 2022 13:28:25 +0000 Subject: [PATCH 1/4] Improve build from source instructions * provide a conda environment * update build instructions in README --- README.md | 101 +++++++++++++++++++++++++++++++++++------------ environment.yaml | 7 ++++ 2 files changed, 83 insertions(+), 25 deletions(-) create mode 100644 environment.yaml diff --git a/README.md b/README.md index 08e752c0..6d588f88 100644 --- a/README.md +++ b/README.md @@ -27,43 +27,94 @@ If you don't have `conda` available, we recommend installing [Miniconda for Pyth Building from source -------------------- -This plugin uses [CMake](https://cmake.org/) as its build system. -Before compiling you must install [LibTorch](https://pytorch.org/cppdocs/installing.html), which is the PyTorch C++ API, by following the instructions at https://pytorch.org. -You can then follow these steps: +### Prerequisites -1. Create a directory in which to build the plugin. +- Minconda https://docs.conda.io/en/latest/miniconda.html#linux-installers +- CUDA Toolkit https://developer.nvidia.com/cuda-downloads +- LibTorch which is the PyTorch C++ API, by following the instructions at https://pytorch.org/cppdocs/installing.html and https://pytorch.org. + - to get a version for CUDA 1.16 used in our build example we use the commands: + ``` + wget https://download.pytorch.org/libtorch/cu116/libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcu116.zip + unzip libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcu116.zip + ``` -2. Run the CMake GUI or `ccmake`, specifying your new directory as the build directory and the top -level directory of this project as the source directory. +### Build & install -3. Press "Configure". (Do not worry if it produces an error message about not being able to find PyTorch.) +1. Get the source code -4. Set `OPENMM_DIR` to point to the directory where OpenMM is installed. This is needed to locate -the OpenMM header files and libraries. If you are unsure of what directory this is, the following -script will print it out. + ``` + git clone https://github.com/openmm/openmm-torch.git + cd openmm-torch + ``` -```python -from simtk import openmm -import os -print(os.path.dirname(openmm.version.openmm_library_path)) +2. Set CUDA_HOME (you may have a different path and version) + + ``` + export CUDA_HOME=/usr/local/cuda-11.6 + ``` + +3. Create and activate a conda environment using the provided environment file + + + ``` + conda env create -n openmm-torch -f environment.yaml + conda activate openmm-torch + ``` + +4. Configure + ``` + mkdir build && cd build + + cmake .. -DPYTORCH_DIR= \ + -DOPENMM_DIR= \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX + ``` + + Where `` is the path of the libtorch you have installed and `` is the path to your openmm installation. + - If you are unsure of what directory your `openmm` is in, the following script will print it out. + ```python + import openmm + import os + print(os.path.dirname(openmm.version.openmm_library_path)) + ``` + + If you get errors in this step you can use `ccmake ..` to view the settings and make corrections. + + +6. Build + ``` + make + make PythonInstall + ``` + +7. Test + ``` + make test + ``` + +8. Install + ``` + make install + ``` + +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. + +``` +python -c "from openmmtorch import TorchForce" ``` +Should complete without error. -5. Set `PYTORCH_DIR` to point to the directory where you installed the LibTorch. -6. Set `CMAKE_INSTALL_PREFIX` to the directory where the plugin should be installed. Usually, -this will be the same as `OPENMM_DIR`, so the plugin will be added to your OpenMM installation. +### Build without CUDA -7. If you plan to build the OpenCL platform, make sure that `OPENCL_INCLUDE_DIR` and -`OPENCL_LIBRARY` are set correctly, and that `NN_BUILD_OPENCL_LIB` is selected. +If you do not have CUDA then you can build using the steps above but with a few differences: +- make sure you download the CPU version of `libtorch` e.g: -8. If you plan to build the CUDA platform, make sure that `CUDA_TOOLKIT_ROOT_DIR` is set correctly -and that `NN_BUILD_CUDA_LIB` is selected. + `wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcpu.zip` -9. Press "Configure" again if necessary, then press "Generate". +- Ingore step 2. +- `cmake` should correctly identify you do not have CUDA and set the variables, if it does not you can use `ccmake ..` to set `NN_BUILD_CUDA_LIB=OFF`. -10. Use the build system you selected to build and install the plugin. For example, if you -selected Unix Makefiles, type `make install` to install the plugin, and `make PythonInstall` to -install the Python wrapper. Using the OpenMM PyTorch plugin =============================== diff --git a/environment.yaml b/environment.yaml new file mode 100644 index 00000000..a1a3fb58 --- /dev/null +++ b/environment.yaml @@ -0,0 +1,7 @@ +channels: + - conda-forge +dependencies: + - cmake + - openmm + - cudnn + - swig=3 \ No newline at end of file From 60df1e040e2d13e354966f7cd33a16f009fe061d Mon Sep 17 00:00:00 2001 From: Stephen Farr Date: Mon, 14 Nov 2022 13:08:02 +0000 Subject: [PATCH 2/4] Update build instructions * Separate instructions for linux, linux with cuda, and MacOS * conda environment files for each build --- README.md | 163 +++++++++++++++++++++++++++++++++++++++---------- linux_cpu.yml | 18 ++++++ linux_cuda.yml | 19 ++++++ macOS.yml | 15 +++++ 4 files changed, 184 insertions(+), 31 deletions(-) create mode 100644 linux_cpu.yml create mode 100644 linux_cuda.yml create mode 100644 macOS.yml diff --git a/README.md b/README.md index 6d588f88..8c83f69f 100644 --- a/README.md +++ b/README.md @@ -27,18 +27,20 @@ If you don't have `conda` available, we recommend installing [Miniconda for Pyth Building from source -------------------- -### Prerequisites +Depending on your environment there are different instructions to follow: + - Linux (NO CUDA): This is for Linux OS when you do have have, or do not want to use CUDA. + - Linux (CUDA): This is for Linux OS when you have CUDA installed and have a CUDA device you want to use. + - MacOS + +### Linux (NO CUDA) + + +#### Prerequisites - Minconda https://docs.conda.io/en/latest/miniconda.html#linux-installers -- CUDA Toolkit https://developer.nvidia.com/cuda-downloads -- LibTorch which is the PyTorch C++ API, by following the instructions at https://pytorch.org/cppdocs/installing.html and https://pytorch.org. - - to get a version for CUDA 1.16 used in our build example we use the commands: - ``` - wget https://download.pytorch.org/libtorch/cu116/libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcu116.zip - unzip libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcu116.zip - ``` -### Build & install + +#### Build & install 1. Get the source code @@ -47,17 +49,12 @@ Building from source cd openmm-torch ``` -2. Set CUDA_HOME (you may have a different path and version) - - ``` - export CUDA_HOME=/usr/local/cuda-11.6 - ``` 3. Create and activate a conda environment using the provided environment file ``` - conda env create -n openmm-torch -f environment.yaml + conda env create -n openmm-torch -f linux_cpu.yaml conda activate openmm-torch ``` @@ -65,21 +62,80 @@ Building from source ``` mkdir build && cd build - cmake .. -DPYTORCH_DIR= \ - -DOPENMM_DIR= \ + # set the Torch_DIR path + export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" + + cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX ``` - Where `` is the path of the libtorch you have installed and `` is the path to your openmm installation. - - If you are unsure of what directory your `openmm` is in, the following script will print it out. - ```python - import openmm - import os - print(os.path.dirname(openmm.version.openmm_library_path)) - ``` +6. Build + ``` + make + make PythonInstall + ``` + +7. Test + ``` + make test + ``` + +8. Install + ``` + make install + ``` + +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. + +``` +python -c "from openmmtorch import TorchForce" +``` +Should complete without error. + + +### Linux (CUDA) + + +#### Prerequisites + +- Minconda https://docs.conda.io/en/latest/miniconda.html#linux-installers +- CUDA Toolkit https://developer.nvidia.com/cuda-downloads + +#### Build & install + +1. Get the source code + + ``` + git clone https://github.com/openmm/openmm-torch.git + cd openmm-torch + ``` + + +2. Make sure your `$CUDA_HOME` path is set correctly to the path of your CUDA installation + + ``` + echo $CUDA_HOME + ``` + +3. Create and activate a conda environment using the provided environment file + + ``` + conda env create -n openmm-torch -f linux_cuda.yaml + conda activate openmm-torch + ``` + + + +4. Configure + ``` + mkdir build && cd build - If you get errors in this step you can use `ccmake ..` to view the settings and make corrections. + # set the Torch_DIR path + export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" + cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX + ``` 6. Build ``` @@ -105,15 +161,60 @@ python -c "from openmmtorch import TorchForce" Should complete without error. -### Build without CUDA +### MacOS + +#### Prerequisites -If you do not have CUDA then you can build using the steps above but with a few differences: -- make sure you download the CPU version of `libtorch` e.g: +- Minconda https://docs.conda.io/en/latest/miniconda.html#macos-installers + + +1. Get the source code - `wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcpu.zip` + ``` + git clone https://github.com/openmm/openmm-torch.git + cd openmm-torch + ``` + +2. Create and activate a conda environment using the provided environment file + + ``` + conda env create -n openmm-torch -f macOS.yaml + conda activate openmm-torch + ``` + +4. Configure + ``` + mkdir build && cd build -- Ingore step 2. -- `cmake` should correctly identify you do not have CUDA and set the variables, if it does not you can use `ccmake ..` to set `NN_BUILD_CUDA_LIB=OFF`. + # set the Torch_DIR path + export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" + + cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX + ``` + +6. Build + ``` + make + make PythonInstall + ``` + +7. Test + ``` + make test + ``` + +8. Install + ``` + make install + ``` + +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. + +``` +python -c "from openmmtorch import TorchForce" +``` +Should complete without error. Using the OpenMM PyTorch plugin diff --git a/linux_cpu.yml b/linux_cpu.yml new file mode 100644 index 00000000..676bd6db --- /dev/null +++ b/linux_cpu.yml @@ -0,0 +1,18 @@ +name: build +channels: + - conda-forge +dependencies: + - cmake + - gxx_linux-64 + - make + #- nnpops + - ocl-icd + - openmm >=7.7 + - pip + - pocl + - pytest + - python + - pytorch-cpu + - swig <4.1 + - sysroot_linux-64 2.17 + - torchani \ No newline at end of file diff --git a/linux_cuda.yml b/linux_cuda.yml new file mode 100644 index 00000000..31ddf50f --- /dev/null +++ b/linux_cuda.yml @@ -0,0 +1,19 @@ +name: build +channels: + - conda-forge +dependencies: + - cmake + - cudatoolkit + - gxx_linux-64 + - make + - nnpops + - ocl-icd + - openmm >=7.7 + - pip + - pocl + - pytest + - python + - pytorch-gpu + - swig <4.1 + - sysroot_linux-64 2.17 + - torchani \ No newline at end of file diff --git a/macOS.yml b/macOS.yml new file mode 100644 index 00000000..63c2c576 --- /dev/null +++ b/macOS.yml @@ -0,0 +1,15 @@ +name: build +channels: + - conda-forge +dependencies: + - cmake + - compilers + - khronos-opencl-icd-loader + - make + - openmm >=7.7 + - pip + - pocl + - pytest + - python + - pytorch-cpu + - swig <4.1 \ No newline at end of file From 72d236684de647552b458f56faf5361598a5f644 Mon Sep 17 00:00:00 2001 From: Stephen Farr Date: Thu, 17 Nov 2022 12:57:48 +0000 Subject: [PATCH 3/4] Move build instructions into install.md --- INSTALL.md | 201 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 189 +------------------------------------------- environment.yaml | 7 -- macOS.yml | 2 +- 4 files changed, 203 insertions(+), 196 deletions(-) create mode 100644 INSTALL.md delete mode 100644 environment.yaml diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 00000000..07c23d69 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,201 @@ +Installing with conda +--------------------- + +We provide [conda](https://docs.conda.io/) packages for Linux and MacOS via [`conda-forge`](https://conda-forge.org/), which can be installed from the [conda-forge channel](https://anaconda.org/conda-forge/openmm-torch): +```bash +conda install -c conda-forge openmm-torch +``` +If you don't have `conda` available, we recommend installing [Miniconda for Python 3](https://docs.conda.io/en/latest/miniconda.html) to provide the `conda` package manager. + + +Building from source +-------------------- + +Depending on your environment there are different instructions to follow: + - Linux (NO CUDA): This is for Linux OS when you do have have, or do not want to use CUDA. + - Linux (CUDA): This is for Linux OS when you have CUDA installed and have a CUDA device you want to use. + - MacOS + +### Linux (NO CUDA) + + +#### Prerequisites + +- Minconda https://docs.conda.io/en/latest/miniconda.html#linux-installers + + +#### Build & install + +1. Get the source code + + ``` + git clone https://github.com/openmm/openmm-torch.git + cd openmm-torch + ``` + + +3. Create and activate a conda environment using the provided environment file + + + ``` + conda env create -n openmm-torch -f linux_cpu.yaml + conda activate openmm-torch + ``` + +4. Configure + ``` + mkdir build && cd build + + # set the Torch_DIR path + export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" + + cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX + ``` + +6. Build + ``` + make + make PythonInstall + ``` + +7. Test + ``` + make test + ``` + +8. Install + ``` + make install + ``` + +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. + +``` +python -c "from openmmtorch import TorchForce" +``` +Should complete without error. + + +### Linux (CUDA) + + +#### Prerequisites + +- Minconda https://docs.conda.io/en/latest/miniconda.html#linux-installers +- CUDA Toolkit https://developer.nvidia.com/cuda-downloads + +#### Build & install + +1. Get the source code + + ``` + git clone https://github.com/openmm/openmm-torch.git + cd openmm-torch + ``` + + +2. Make sure your `$CUDA_HOME` path is set correctly to the path of your CUDA installation + + ``` + echo $CUDA_HOME + ``` + +3. Create and activate a conda environment using the provided environment file + + ``` + conda env create -n openmm-torch -f linux_cuda.yaml + conda activate openmm-torch + ``` + + + +4. Configure + ``` + mkdir build && cd build + + # set the Torch_DIR path + export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" + + cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX + ``` + +6. Build + ``` + make + make PythonInstall + ``` + +7. Test + ``` + make test + ``` + +8. Install + ``` + make install + ``` + +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. + +``` +python -c "from openmmtorch import TorchForce" +``` +Should complete without error. + + +### MacOS + +#### Prerequisites + +- Minconda https://docs.conda.io/en/latest/miniconda.html#macos-installers + + +1. Get the source code + + ``` + git clone https://github.com/openmm/openmm-torch.git + cd openmm-torch + ``` + +2. Create and activate a conda environment using the provided environment file + + ``` + conda env create -n openmm-torch -f macOS.yaml + conda activate openmm-torch + ``` + +4. Configure + ``` + mkdir build && cd build + + # set the Torch_DIR path + export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" + + cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX + ``` + +6. Build + ``` + make + make PythonInstall + ``` + +7. Test + ``` + make test + ``` + +8. Install + ``` + make install + ``` + +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. + +``` +python -c "from openmmtorch import TorchForce" +``` +Should complete without error. diff --git a/README.md b/README.md index 8c83f69f..62e2151f 100644 --- a/README.md +++ b/README.md @@ -27,194 +27,7 @@ If you don't have `conda` available, we recommend installing [Miniconda for Pyth Building from source -------------------- -Depending on your environment there are different instructions to follow: - - Linux (NO CUDA): This is for Linux OS when you do have have, or do not want to use CUDA. - - Linux (CUDA): This is for Linux OS when you have CUDA installed and have a CUDA device you want to use. - - MacOS - -### Linux (NO CUDA) - - -#### Prerequisites - -- Minconda https://docs.conda.io/en/latest/miniconda.html#linux-installers - - -#### Build & install - -1. Get the source code - - ``` - git clone https://github.com/openmm/openmm-torch.git - cd openmm-torch - ``` - - -3. Create and activate a conda environment using the provided environment file - - - ``` - conda env create -n openmm-torch -f linux_cpu.yaml - conda activate openmm-torch - ``` - -4. Configure - ``` - mkdir build && cd build - - # set the Torch_DIR path - export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" - - cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ - -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX - ``` - -6. Build - ``` - make - make PythonInstall - ``` - -7. Test - ``` - make test - ``` - -8. Install - ``` - make install - ``` - -Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. - -``` -python -c "from openmmtorch import TorchForce" -``` -Should complete without error. - - -### Linux (CUDA) - - -#### Prerequisites - -- Minconda https://docs.conda.io/en/latest/miniconda.html#linux-installers -- CUDA Toolkit https://developer.nvidia.com/cuda-downloads - -#### Build & install - -1. Get the source code - - ``` - git clone https://github.com/openmm/openmm-torch.git - cd openmm-torch - ``` - - -2. Make sure your `$CUDA_HOME` path is set correctly to the path of your CUDA installation - - ``` - echo $CUDA_HOME - ``` - -3. Create and activate a conda environment using the provided environment file - - ``` - conda env create -n openmm-torch -f linux_cuda.yaml - conda activate openmm-torch - ``` - - - -4. Configure - ``` - mkdir build && cd build - - # set the Torch_DIR path - export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" - - cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ - -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX - ``` - -6. Build - ``` - make - make PythonInstall - ``` - -7. Test - ``` - make test - ``` - -8. Install - ``` - make install - ``` - -Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. - -``` -python -c "from openmmtorch import TorchForce" -``` -Should complete without error. - - -### MacOS - -#### Prerequisites - -- Minconda https://docs.conda.io/en/latest/miniconda.html#macos-installers - - -1. Get the source code - - ``` - git clone https://github.com/openmm/openmm-torch.git - cd openmm-torch - ``` - -2. Create and activate a conda environment using the provided environment file - - ``` - conda env create -n openmm-torch -f macOS.yaml - conda activate openmm-torch - ``` - -4. Configure - ``` - mkdir build && cd build - - # set the Torch_DIR path - export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" - - cmake .. -DOPENMM_DIR=$CONDA_PREFIX \ - -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX - ``` - -6. Build - ``` - make - make PythonInstall - ``` - -7. Test - ``` - make test - ``` - -8. Install - ``` - make install - ``` - -Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. - -``` -python -c "from openmmtorch import TorchForce" -``` -Should complete without error. +If you need to build from source look at [INSTALL.md](./INSTALL.md). Using the OpenMM PyTorch plugin diff --git a/environment.yaml b/environment.yaml deleted file mode 100644 index a1a3fb58..00000000 --- a/environment.yaml +++ /dev/null @@ -1,7 +0,0 @@ -channels: - - conda-forge -dependencies: - - cmake - - openmm - - cudnn - - swig=3 \ No newline at end of file diff --git a/macOS.yml b/macOS.yml index 63c2c576..493c0551 100644 --- a/macOS.yml +++ b/macOS.yml @@ -12,4 +12,4 @@ dependencies: - pytest - python - pytorch-cpu - - swig <4.1 \ No newline at end of file + - swig <4.1 From 0b62191342ea66a2c0e5acc8f74baff938a190dd Mon Sep 17 00:00:00 2001 From: Stephen Farr Date: Thu, 17 Nov 2022 13:07:48 +0000 Subject: [PATCH 4/4] fix typos --- INSTALL.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 07c23d69..faf22a4c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -69,7 +69,7 @@ Depending on your environment there are different instructions to follow: make install ``` -Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtorch` into `python`. ``` python -c "from openmmtorch import TorchForce" @@ -137,7 +137,7 @@ Should complete without error. make install ``` -Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtorch` into `python`. ``` python -c "from openmmtorch import TorchForce" @@ -193,7 +193,7 @@ Should complete without error. make install ``` -Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtoch` into `python`. +Your built version of openmm-torch will now be available in your conda environment. You can test this by trying to import `openmmtorch` into `python`. ``` python -c "from openmmtorch import TorchForce"