How to install Underworld on Mac OSX (Apple Silicon M1)

The new generation of Apple Mac comes with the new Apple Silicon (M1) chip which has an Arm architecture (as opposed to the older generation that had i386 Intel processor). This brings all manner of troubles and requirements for the development of codes.

How to install Underworld on Mac OSX (Apple Silicon M1)


The new generation of Apple Mac comes with the new Apple Silicon (M1) chip which has an Arm architecture (as opposed to the older generation that had i386 Intel processor). This brings all manner of troubles and requirements for the development of codes. Here I detail how to install Underworld on Mac OSX Big Sur 11.5.2 (Apple Silicon) using Python 3.9

Important Note: The following guide uses the CMake branch of Underworld.

Install Python

I installed Python 3 (3.9.7) using Homebrew:

brew install python3

Install PETSc

I also installed PETSc (3.15.4) using Homebrew. The default comes with hdf5, open-mpi.

brew install petsc

Create a python virtual environment

python3 -m venv uw2_virtualenv

Activate the environment

source uw2_virtualenv/bin/activate

Install H5py

H5py is notoriously difficult to get right... Here is how I do it.

# Install dependencies
pip3 install numpy cython pkgconfig mpi4py
HDF5_DIR=/opt/homebrew/Cellar/hdf/1.12.1 pip3 install h5py --no-build-isolation --no-binary :all:

At the time I am writing this post, the version of HDF5 that comes with PETSc is 1.12.1. This will change in the future so you will have to update that line.
The no-build-isolation option forces pip to skip creating a build environment and to rely on the dependencies being already available (Numpy, pkgconfig, cython, mpi4py).

Install Underworld 2

First you will probably need to have  CMake and Swig if you don't have them already.

brew install cmake swig

Now get Underworld from GitHub and switch to the cmake branch

git clone https://github.com/underworldcode/underworld2.git
cd underworld2
git checkout cmake
cd ..

Finally install Underworld

pip3 install underworld2/

Note the / is important.

Test your installation

python3 -c "import underworld as uw"