Skip to content

Commit

Permalink
Begin using Mac runners (#3881)
Browse files Browse the repository at this point in the history
* Add GitHub actions for macOS using `firedrake-install` and `pip install firedrake`. These will only run on PRs labelled "macOS" (or on pushes to master).
* Fixups to pyproject.toml

---------

Co-authored-by: Josh Hope-Collins <[email protected]>
Co-authored-by: David A. Ham <[email protected]>
  • Loading branch information
3 people authored Dec 6, 2024
1 parent ded8f14 commit fdfc908
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 20 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/build-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Install and test Firedrake (macOS)

on:
push:
branches:
- master
pull_request:
# By default this workflow is run on the "opened", "synchronize" and
# "reopened" events. We add "labelled" so it will run if the PR is given a label.
types: [opened, synchronize, reopened, labeled]

concurrency:
# Cancels jobs running if new commits are pushed
group: >
${{ github.workflow }}-
${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build Firedrake (macOS)
runs-on: [self-hosted, macOS]
# Only run this action if we are pushing to master or the PR is labelled "macOS"
if: ${{ (github.ref == 'refs/heads/master') || contains(github.event.pull_request.labels.*.name, 'macOS') }}
env:
FIREDRAKE_CI_TESTS: 1 # needed to symlink the checked out branch into the venv
OMP_NUM_THREADS: 1
OPENBLAS_NUM_THREADS: 1
steps:
- name: Add homebrew to PATH
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#adding-a-system-path
run: echo "/opt/homebrew/bin" >> "$GITHUB_PATH"
- uses: actions/checkout@v4
- name: Pre-run cleanup
if: ${{ always() }}
run: |
cd ..
rm -rf firedrake_venv
- name: Install Python
run: brew install python python-setuptools
- name: Build Firedrake
run: |
cd ..
"$(brew --prefix)/bin/python3" \
firedrake/scripts/firedrake-install \
--venv-name firedrake_venv \
--disable-ssh \
|| (cat firedrake-install.log && /bin/false)
- name: Run smoke tests
run: |
. ../firedrake_venv/bin/activate
python -m pytest -v tests/firedrake/regression/ -k "poisson_strong or stokes_mini or dg_advection"
timeout-minutes: 30
- name: Post-run cleanup
if: ${{ always() }}
run: |
cd ..
rm -rf firedrake_venv
127 changes: 127 additions & 0 deletions .github/workflows/pip-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Pip install Firedrake (macOS)

on:
push:
branches:
- master
pull_request:
# By default this workflow is run on the "opened", "synchronize" and
# "reopened" events. We add "labelled" so it will run if the PR is given a label.
types: [opened, synchronize, reopened, labeled]

concurrency:
# Cancels jobs running if new commits are pushed
group: >
${{ github.workflow }}-
${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
name: "Build Firedrake using pip (macOS)"
runs-on: [self-hosted, macOS]
# Only run this action if we are pushing to master or the PR is labelled "macOS"
if: ${{ (github.ref == 'refs/heads/master') || contains(github.event.pull_request.labels.*.name, 'macOS') }}
env:
OMP_NUM_THREADS: 1
OPENBLAS_NUM_THREADS: 1
steps:
- name: Add homebrew to PATH
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#adding-a-system-path
run: echo "/opt/homebrew/bin" >> "$GITHUB_PATH"

- name: Install homebrew packages
run: brew install gcc autoconf pkg-config make automake cmake ninja libtool boost openblas python python-setuptools mpich

- name: Cleanup (pre)
if: ${{ always() }}
run: |
rm -rf pip_venv
"$(brew --prefix)/bin/python3" -m pip cache purge
- name: Create a virtual environment
run: |
"$(brew --prefix)/bin/python3" -m venv pip_venv
mkdir pip_venv/src
- name: Install PETSc
run: |
cd pip_venv/src
git clone https://github.com/firedrakeproject/petsc.git
cd petsc
./configure PETSC_DIR="$PWD" PETSC_ARCH=default \
--with-shared-libraries=1 \
--with-mpi-dir=/opt/homebrew \
--with-zlib \
--download-bison \
--download-hdf5 \
--download-hwloc \
--download-hypre \
--download-metis \
--download-mumps \
--download-netcdf \
--download-pastix \
--download-pnetcdf \
--download-ptscotch \
--download-scalapack \
--download-suitesparse \
--download-superlu_dist
make
- name: Install libsupermesh
run: |
source pip_venv/bin/activate
python -m pip install 'rtree>=1.2'
cd pip_venv/src
git clone https://github.com/firedrakeproject/libsupermesh.git
mkdir -p libsupermesh/build
cd libsupermesh/build
cmake .. \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX="$VIRTUAL_ENV" \
-DMPI_C_COMPILER=/opt/homebrew/bin/mpicc \
-DMPI_CXX_COMPILER=/opt/homebrew/bin/mpicxx \
-DMPI_Fortran_COMPILER=/opt/homebrew/bin/mpif90 \
-DCMAKE_Fortran_COMPILER=/opt/homebrew/bin/mpif90 \
-DMPIEXEC_EXECUTABLE=/opt/homebrew/bin/mpiexec
make
make install
- uses: actions/checkout@v4
with:
path: pip_venv/src/firedrake

- name: Pip install
run: |
export PETSC_DIR="$PWD/pip_venv/src/petsc"
export PETSC_ARCH=default
export HDF5_DIR="$PETSC_DIR/$PETSC_ARCH"
export HDF5_MPI=ON
export CC=/opt/homebrew/bin/mpicc
export CXX=/opt/homebrew/bin/mpicxx
export MPICC="$CC"
source pip_venv/bin/activate
cd pip_venv/src
python -m pip install \
--log=firedrake-install.log \
--no-binary h5py \
-v -e './firedrake[test]'
- name: Install CI-specific test dependencies
run: |
source pip_venv/bin/activate
python -m pip install -U pytest-timeout
- name: Run Firedrake smoke tests
run: |
source pip_venv/bin/activate
cd pip_venv/src/firedrake
python -m pytest --timeout=1800 -v tests/firedrake/regression \
-k "poisson_strong or stokes_mini or dg_advection"
timeout-minutes: 30

- name: Cleanup (post)
if: ${{ always() }}
run: |
rm -rf pip_venv
"$(brew --prefix)/bin/python3" -m pip cache purge
5 changes: 4 additions & 1 deletion .github/workflows/pyop2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ jobs:
working-directory: PyOP2
run: |
source ../venv/bin/activate
python -m pip install -v ".[test]"
export CC=mpicc
export HDF5_DIR="$PETSC_DIR/$PETSC_ARCH"
export HDF5_MPI=ON
python -m pip install --no-binary h5py -v ".[test]"
- name: Run tests
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions docs/source/download.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ type::

You should now be able to run ``firedrake-update``.

Installing Firedrake with pip (experimental, Linux only)
Installing Firedrake with pip (experimental)
--------------------------------------------------------

Firedrake has experimental support for installing using ``pip``, avoiding the need for the ``firedrake-install`` script. At present only Linux is tested using this install method.
Firedrake has experimental support for installing using ``pip``, avoiding the need for the ``firedrake-install`` script.

Requirements
~~~~~~~~~~~~
Expand Down
12 changes: 9 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ requires-python = ">=3.10"
dependencies = [
"cachetools",
"decorator<=4.4.2",
"mpi4py",
"h5py",
"mpi4py>3; python_version >= '3.13'",
"mpi4py; python_version < '3.13'",
# TODO: We are only using our fork here because the most recent PyPI release
# does not yet work with build isolation for Python 3.13. Once a version
# newer than 3.12.1 is released we can revert to simply using "h5py".
"h5py @ git+https://github.com/firedrakeproject/h5py.git ; python_version >= '3.13'",
"h5py; python_version < '3.13'",
"petsc4py",
"numpy",
"packaging",
Expand Down Expand Up @@ -91,7 +96,8 @@ requires = [
"pybind11",
"pkgconfig",
"numpy",
"mpi4py",
"mpi4py>3; python_version >= '3.13'",
"mpi4py; python_version < '3.13'",
"petsc4py",
"rtree>=1.2",
]
Expand Down
21 changes: 14 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from dataclasses import dataclass, field
from setuptools import setup, find_packages, Extension
from glob import glob
from pathlib import Path
from Cython.Build import cythonize
import os
import platform
import sys
import site
import numpy as np
import pybind11
import petsc4py
import rtree
import pkgconfig
from dataclasses import dataclass, field
from setuptools import setup, find_packages, Extension
from glob import glob
from pathlib import Path
from Cython.Build import cythonize

# Define the compilers to use if not already set
if "CC" not in os.environ:
Expand Down Expand Up @@ -87,7 +88,14 @@ def __getitem__(self, key):
# Pybind11
# example:
# gcc -I/pyind11/include ...
pybind11_ = ExternalDependency(include_dirs=[pybind11.get_include()])
pybind11_extra_compile_args = []
if platform.uname().system == "Darwin":
# Clang needs to specify at least C++11
pybind11_extra_compile_args.append("-std=c++11")
pybind11_ = ExternalDependency(
include_dirs=[pybind11.get_include()],
extra_compile_args=pybind11_extra_compile_args,
)

# numpy
# example:
Expand Down Expand Up @@ -225,7 +233,6 @@ def extensions():
## PYBIND11 EXTENSIONS
pybind11_list = []
# tinyasm/tinyasm.cpp: petsc, pybind11
# tinyasm/tinyasm.cpp: petsc, pybind11
pybind11_list.append(Extension(
name="tinyasm._tinyasm",
language="c++",
Expand Down
12 changes: 10 additions & 2 deletions tests/firedrake/regression/test_dg_advection.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ def run_test(mesh):
t = 0.0
T = 10*dt

problem = LinearVariationalProblem(a_mass, action(arhs, D1), dD1)
solver = LinearVariationalSolver(problem, solver_parameters={'ksp_type': 'cg'})
problem = LinearVariationalProblem(a_mass, action(arhs, D1), dD1,
constant_jacobian=True)
solver = LinearVariationalSolver(
problem,
solver_parameters={
'ksp_type': 'preonly',
'pc_type': 'bjacobi',
'sub_pc_type': 'ilu'
}
)

L2_0 = norm(D)
Dbar_0 = assemble(D*dx)
Expand Down
10 changes: 5 additions & 5 deletions tests/firedrake/regression/test_poisson_strong_bcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from firedrake import *


def run_test(r, degree, parameters={}, quadrilateral=False):
def run_test(r, degree, parameters, quadrilateral=False):
# Create mesh and define function space
mesh = UnitSquareMesh(2 ** r, 2 ** r, quadrilateral=quadrilateral)
x = SpatialCoordinate(mesh)
Expand All @@ -41,7 +41,7 @@ def run_test(r, degree, parameters={}, quadrilateral=False):
return sqrt(assemble(inner(u - f, u - f) * dx))


def run_test_linear(r, degree, parameters={}, quadrilateral=False):
def run_test_linear(r, degree, parameters, quadrilateral=False):
# Create mesh and define function space
mesh = UnitSquareMesh(2 ** r, 2 ** r, quadrilateral=quadrilateral)
x = SpatialCoordinate(mesh)
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_poisson_analytic_linear(params, degree, quadrilateral):

@pytest.mark.parallel(nprocs=2)
def test_poisson_analytic_linear_parallel():
from mpi4py import MPI
error = run_test_linear(1, 1)
print('[%d]' % MPI.COMM_WORLD.rank, 'error:', error)
# specify superlu_dist as MUMPS fails in parallel on MacOS
solver_parameters = {'pc_factor_mat_solver_type': 'superlu_dist'}
error = run_test_linear(1, 1, solver_parameters)
assert error < 5e-6

0 comments on commit fdfc908

Please sign in to comment.