Using uv for Python and C++ MPI applications
(contributed by Timo Heister)
Introduction
Based on the first article, that described coupling an MPI Python application with an MPI C++ application, today we will talk about an easy way to set up and install necessary dependencies. A relatively new project in the Python ecosystem is uv. We are going to use uv to install Python and necessaryt dependencies to run a coupled Landlab+ASPECT simulation.
1. Installing uv
The first step is to install uv for example by following the uv installation instructions.
2. Downloading the source
git clone --recurse-submodules https://github.com/landlab-aspect/aspect
or if you forgot to clone with the Landlab submodule, run git submodule init; git submodule update.
3. Setting up the project
Create and enable an environment with a modern Python version:
uv venv --python 3.12
. .venv/bin/activate
Then we can install the dependencies:
uv sync
That's it! Under the hood, uv will download Python if necessary, install all dependencies (including the dependencies that Landlab needs), and set up a working environment. Note that Landlab is not installed from a binary package but built from source (the specific version in the git submodule ./landlab/).
Running a first example
We now need to configure and building ASPECT with -D ASPECT_WITH_PYTHON=ON. Make sure that the correct Python version is showing up during the configuration. It might be necessary to specify -D Python3_EXECUTABLE and setting it to whatever which python returns (the path should be pointing inside the virtual env folder we created above starting with .venv).
Now we can run a first example:
cd cookbooks/landlab/coupled1
mpirun -n 2 ../../../build/aspect-debug test.prm