Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve build from source instructions #89

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -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 `openmmtorch` 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 `openmmtorch` 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 `openmmtorch` into `python`.

```
python -c "from openmmtorch import TorchForce"
```
Should complete without error.
37 changes: 1 addition & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,8 @@ 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:
If you need to build from source look at [INSTALL.md](./INSTALL.md).

1. Create a directory in which to build the plugin.

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.

3. Press "Configure". (Do not worry if it produces an error message about not being able to find PyTorch.)

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.

```python
from simtk import openmm
import os
print(os.path.dirname(openmm.version.openmm_library_path))
```

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.

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.

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.

9. Press "Configure" again if necessary, then press "Generate".

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
===============================
Expand Down
18 changes: 18 additions & 0 deletions linux_cpu.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions linux_cuda.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions macOS.yml
Original file line number Diff line number Diff line change
@@ -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