Skip to content

Set Up python

Jacob Austin edited this page Mar 29, 2020 · 3 revisions

Installation:

Below are installation instructions for Windows and Linux. Troubleshooting details can be found below.

Windows Quick Installation:

This quick installation guide assumes you already have a C++ compiler installed, like Microsoft Visual Studio 2015/2017. We will:

  • Install the NVIDIA CUDA Toolkit
  • Install the Microsoft vcpkg package manager
  • Install Titan's Dependencies
  • Donload Titan and copy the pythonTitan module or build the module yourself

1. Install the NVIDIA CUDA Toolkit

Download the NVIDIA CUDA Toolkit from this link and follow the quick install instructions. If the installation fails, try again using the advanced installation tab after unchecking Visual Studio Integration. This is a known CUDA big caused by incompatibilities with some Visual Studio versions.

2. Install vcpkg

We will be using the vcpkg utility to handle dependencies for this project. The library optionally supports graphics rendering of the mass spring simulation using OpenGL, with utilities provided by the GLM, GLEW, and GLFW libraries. These libraries can be installed in any fashion, but the Microsoft vcpkg package manager provides a convenient method. To use vcpkg,

  1. Go to the vcpkg GitHub and clone the repository into your user account (ideally in C:/vcpkg or C:/Users/.../Documents) using the following:
cd C:/
git clone https://github.com/Microsoft/vcpkg.git
  1. Then follow the installation/setup instructions provided in the GitHub (reproduced here) to build vcpkg
cd vcpkg
./bootstrap-vcpkg.bat
./vcpkg integrate install
./vcpkg --triplet x64-windows install glfw3 GLEW glm
./vcpkg install pybind11:x64-windows

This will install all the necessary dependencies.

3. Download and compile Titan

To download and compile Titan's python module start by dowloading the github repository to a folder on your computer using

git clone -b pythonTitan https://github.com/jacobaustin123/Titan.git

Inside the newly downloaded Titan directory, navigate to Titan/python_module and copy the "titan.lib" module file to your preferred lib directory. Any location where python can find and import the module will work. You may also copy the module file to your project's root directory, as this will ensure that python can import the module iregardless of the computer your project is ran on (as long as said computer has the dependencies installed).

Alternatively you may chose to build the module yourself. This is the method that should be used to build the module where you to want to modify Titan's functionality itself (i.e customize the graphics rendering options, modify the simulation engine, etc).

In the Titan repository folder do:

mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake # this should be the path to your vcpkg installation
make 

After the compilation is finished the build directory will contain Titan's build files. Among this you will find the "titan.lib" file which can be imported using python. You may move this module to your preferred python include directory or your project's root and import it using python's import command.

Everything is now installed, and you can use it to build a sample project. See the next page for a quick example on how to get started using the python module.

Linux Quick Installation:

Linux installation is very similar to Windows.

1. Install the NVIDIA CUDA Toolkit

Download the NVIDIA CUDA Toolkit from this link and follow the quick install instructions. If the installation fails, try again using the advanced installation tab after unchecking Visual Studio Integration. This is a known CUDA big caused by incompatibilities with some Visual Studio versions.

2. Install vcpkg

We will be using the vcpkg utility to handle dependencies for this project. The library optionally supports graphics rendering of the mass spring simulation using OpenGL, with utilities provided by the GLM, GLEW, and GLFW libraries. These libraries can be installed in any fashion, but the Microsoft vcpkg package manager provides a convenient method. To use vcpkg,

  1. Go to the vcpkg GitHub and clone the repository into your user account (ideally in /Users/.../Documents or /Users/.../Downloads) using the following:
cd ~/Documents
git clone https://github.com/Microsoft/vcpkg.git
  1. Follow the installation/setup instructions provided in the GitHub (reproduced here) to build vcpkg
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install

The last command will output a path to the vcpkg cmake file which you will need to include in future projects to use the Titan library. Save this output, for example: "-DCMAKE_TOOLCHAIN_FILE=/Users/username/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake"

Now install the necessary dependencies using:

./vcpkg --triplet x64-windows install glfw3 GLEW glm
./vcpkg install pybind11:x64-windows

3. Download and Install Titan

To install the library using vcpkg, clone the github repository to a folder on your computer using

git clone -b pythonTitan https://github.com/jacobaustin123/Titan.git

Inside the newly downloaded Titan directory, navigate to Titan/python_module and copy the "titan.lib" module file to your preferred lib directory. Any location where python can find and import the module will work. You may also copy the module file to your project's root directory, as this will ensure that python can import the module iregardless of the computer your project is ran on (as long as said computer has the dependencies installed).

Alternatively you may chose to build the module yourself. This is the method that should be used to build the module where you to want to modify Titan's functionality itself (i.e customize the graphics rendering options, modify the simulation engine, etc).

In the Titan repository folder do:

mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake # this should be the path to your vcpkg installation
make 

After the compilation is finished the build directory will contain Titan's build files. Among this you will find the "titan.lib" file which can be imported using python. You may move this module to your preferred python include directory or your project's root and import it using python's import command.

Everything is now installed, and you can use it to build a sample project. See the next page for a quick example on how to get started using the python module.

Troubleshooting and Uninstallation

Vcpkg known issues

If vcpkg fails to find CUDA, try running export CUDA_PATH=/usr/local/cuda, or whatever the path is to your CUDA installation. You can copy that line into your .bashrc file to avoid having to run it every time. At the moment, due to an issue with CUDA and CMake, you will need to include the line

project(myproject LANGUAGES CXX CUDA)

at the beginning of whatever project uses the Titan library, with the myproject variable replaced by the name of your project. This is because certain environment variables which are needed by the library are not being set properly. In some cases, if CMake cannot find CUDA, you will need to manually set

set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)

or whatever the path to the CUDA nvcc compiler is.

Using an IDE with the Titan library and vcpkg

Vcpkg is a convenient cross-platform dependency management system developed by Microsoft, designed to work seamlessly with CMake. In any of the installation instructions above, you saved a command like "-DCMAKE_TOOLCHAIN_FILE=/Users/username/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake". This is the command that must be passed to CMake to build a project using dependencies installed by vcpkg. This can be passed directly to vcpkg on the command-line, and for IDEs it can be included as directed below:

Using Visual Studio with Titan

To make Visual Studio compatible with Titan and CUDA, you may need to make the following changes:

  1. In Visual Studio, go to CMake/CMake Settings and generate a CMakeSettings.json file for your project. In this file, under the x64-debug and x64-release targets, you may need to add the variables section of the following example.
{
      "name": "x64-Release",
      ...,
      "variables": [
             {
               "name": "CMAKE_TOOLCHAIN_FILE",
               "value": "${env.VCPKG_DIR}"
             }
     ]
}

If this fails, change env.VCPKG_DIR to the actual path to the vcpkg directory.

  1. To work with CUDA, you may need to:

Open C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\include\crt\host_config.h Find the line #if _MSC_VER < 1600 || _MSC_VER > 1913 and replace it with just #if _MSC_VER < 1600

  1. If you are unable to get Visual Studio 2017 to work, use Visual Studio 2015, but manually copy the Titan.dll dynamic library from the vcpkg/installed directory into your project directory. Then you should be able to include the headers found in the vcpkg/installed directory and link to the library file.

Using Microsoft Visual Studio 2015 with Titan

To install and use Microsoft Visual Studio Community 2015 with Titan, download Visual Studio Community 2015 (with Update 3) from the provided link and follow the installer instructions to install the Visual C++ compiler and v140 toolkit. You do not need to install the Visual Studio IDE or any other tools (only Visual C++ tools). You may need to subscribe for free to My Visual Studio to access older versions.

Using Microsoft Visual Studio 2017 with Titan

To install and use Microsoft Visual Studio Community 2017 with Titan, download Microsoft Visual Studio Community 2017 from Microsoft (link) and follow the installer instructions to install the Visual C++ compiler and v140 toolkit. You do not need to install the Visual Studio IDE or any other tools (only Visual C++ tools), although you may want to install the IDE if you prefer to develop in Visual Studio over CLion.

Once Visual Studio 2017 is installed, you will have to make a few changes to let it interface with CUDA. For some reason, CUDA is made incompatible with newer versions of Visual Studio, but disabling this has no adverse effects. To do this, you may need to

  • Open C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\include\crt\host_config.h
  • Find the line #if _MSC_VER < 1600 || _MSC_VER > 1913 and replace it with just #if _MSC_VER < 1600

Using CLion with Titan

CLion is a cross-platform IDE developed by IntelliJ, the creators of PyCharm and IDEA. The IDE uses CMake by default, so it is ideal for including our CMake project. To build and run your project with CLion, several settings changes need to be made.

  1. First, in Settings/Build, Execution, Deployment/CMake, make sure CMake Options includes the command
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake

where the path points to the vcpkg folder. The above is an example for Windows. On Unix systems it will look like "-DCMAKE_TOOLCHAIN_FILE=/Users/username/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake". If you have vcpkg installed in a different directory, use that path instead. This is the path you saved earlier in the process.

  1. Make sure the compiler in Settings/Build, Execution, Deployment/Toolchains is set to Visual Studio 2015 or 2017 (14.0), and the architecture is set to 64-bit (amd64 on Windows). Do not use amd64_arm or any other compiler option.
  • Note that there is sometimes a bug in CLion with CUDA support that causes it to run the wrong executable - if CLion is unable to run an executable, manually run the executable found in the project directory (it will be found in the cmake-build-debug or cmake-build-release folder depending on your settings).

  • Note that CLion will sometimes find the library installed in the wrong directory, not the vcpkg version. If CLion is unable to find the library, or seems to have found the wrong version, try navigating to Program Files and Program Files (x86) and deleting any folder called "Titan". Then reload the CMake project (using File/Reload CMake Project). Sometimes you will also need to delete the cmake-build-debug folder, close CLion, and then reopen it and run File/Reload CMake Project.

Uninstalling

To remove the titan module on Windows, simply delete the python module from your python directory or your project's root.

Clone this wiki locally