Skip to content

Instantly share code, notes, and snippets.

@dliptai
Created August 31, 2023 05:57
Show Gist options
  • Save dliptai/c0826a6421b362c7b46e92ece539bc51 to your computer and use it in GitHub Desktop.
Save dliptai/c0826a6421b362c7b46e92ece539bc51 to your computer and use it in GitHub Desktop.
Building OpenVDB with Python bindings

Building OpenVDB with Python bindings

Locally on a Linux/MacOS machine

Follow one of:

Just make sure to call the cmake command with -DOPENVDB_BUILD_PYTHON_MODULE=ON -DUSE_NUMPY=ON

In a conda/mamba environment (from conda-forge; linux only)

mamba create -n openvdb -c conda-forge openvdb
mamba activate openvdb
python -c 'import pyopenvdb'

On Gadi

Load dependencies

module load gcc/12.2.0 cmake/3.24.2 boost/1.80.0 python3/3.11.0 python3-as-python intel-tbb/2021.10.0

Note: numpy is available in the python3/3.11.0 module.

Create a virtual environment and activate it

python -m venv --system-site-packages venv
source venv/bin/activate

Install pybind11 from PyPI

pip install --upgrade pip wheel pybind11

Clone OpenVDB

git clone https://github.com/AcademySoftwareFoundation/openvdb.git

Make a build directory

cd openvdb
mkdir build

Run CMake: configure, build, and install

cmake .. -DOPENVDB_BUILD_PYTHON_MODULE=ON -DUSE_NUMPY=ON -DOPENVDB_CORE_STATIC=OFF -DUSE_EXPLICIT_INSTANTIATION=OFF -DCMAKE_INSTALL_PREFIX=$HOME/venv/ -DBOOST_LIBRARYDIR=$BOOST_LIBRARYDIR/GNU/ -DBoost_NO_BOOST_CMAKE=ON -Dpybind11_ROOT=$(pybind11-config --cmakedir)
make -j
make install

Note: boost and pybind11 are a bit tricky on Gadi. CMake was having issues with the Boost module, so we manually specify its install path. We also have to manually specify the installation of pybind11 since it was installed via pip and so cmake has no way of finding it.

Now you can import pyopenvdb in a python interpreter, as long as you have activated that venv. i.e. on a future login

module load gcc/12.2.0 cmake/3.24.2 boost/1.80.0 python3/3.11.0 python3-as-python intel-tbb/2021.10.0
source $HOME/venv/bin/activate
python -c 'import pyopenvdb'

On OzSTAR (NT)

Load dependencies

module load gompi/2022a cmake/3.24.3 tbb/2021.5.0 boost/1.79.0 pybind11/2.9.2 blosc/1.21.3 numpy/1.22.3-scipy-bundle-2022.05

Note that blosc is not present in the OS, unlike on Gadi, so we have to load it. Also, pybind11 is available as a module, and we need to load numpy.

Create a virtual environment and activate it

python -m venv --system-site-packages venv
source venv/bin/activate

Clone OpenVDB

git clone https://github.com/AcademySoftwareFoundation/openvdb.git

Make a build directory

cd openvdb
mkdir build

Run CMake: configure, build, and install

cmake .. -DOPENVDB_BUILD_PYTHON_MODULE=ON -DUSE_NUMPY=ON -DOPENVDB_CORE_STATIC=OFF -DUSE_EXPLICIT_INSTANTIATION=OFF -DCMAKE_INSTALL_PREFIX=$HOME/venv/
make -j
make install

On future logins do

module load gompi/2022a cmake/3.24.3 tbb/2021.5.0 boost/1.79.0 pybind11/2.9.2 blosc/1.21.3 numpy/1.22.3-scipy-bundle-2022.05
source $HOME/bin/activate
python -c 'import pyopenvdb'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment