Skip to content

Commit

Permalink
adopt scikit-build-core
Browse files Browse the repository at this point in the history
- remove setup.py
- requires `--no-build-isolation` to pip install (previously added by default due to lack of pyproject.toml)
  • Loading branch information
minrk committed Jun 5, 2023
1 parent d9f8e7d commit e09fe8a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 108 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/test_mpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
# '*' is a special character in YAML, so string must be quoted
- cron: "0 8 * * *"

env:
global:
CMAKE_BUILD_PARALLEL_LEVEL: "3"

jobs:
build:
Expand All @@ -25,7 +28,7 @@ jobs:
# Due to: https://gitlab.com/petsc/petsc/-/issues/1288
CXX: [c++]
#, clang++]
CC: [cc]
CC: [cc]
#, clang]
# exclude:
# - CC: cc
Expand Down Expand Up @@ -80,7 +83,7 @@ jobs:
python3 -m pip install mpi4py cython numpy
python3 -m pip install --no-cache-dir --no-binary=h5py h5py --no-build-isolation
- name: Install DOLFINx
uses: ./.github/actions/install-dolfinx
with:
Expand All @@ -90,14 +93,20 @@ jobs:
ffcx: ${{ env.FFCX_BRANCH }}
petsc_arch: ${{ env.PETSC_ARCH }}

- name: set $CXXFLAGS
run:
echo "CXXFLAGS=${MPC_CMAKE_CXX_FLAGS}" >> $GITHUB_ENV

- name: Install DOLFINx-MPC (C++)
run: |
cmake -G Ninja -B build-dir -DCMAKE_BUILD_TYPE=${MPC_BUILD_MODE} -DCMAKE_CXX_FLAGS="${MPC_CMAKE_CXX_FLAGS}" -S cpp/
cmake -G Ninja -B build-dir -DCMAKE_BUILD_TYPE=${MPC_BUILD_MODE} -S cpp/
cmake --build build-dir --parallel 3
cmake --install build-dir
- name: Install DOLFINx-MPC (Python)
run: CXX_FLAGS="${MPC_CMAKE_CXX_FLAGS}" python3 -m pip -v install python/[test]
run: |
python3 -m pip install sckikit-build-core[pyproject]
python3 -m pip install --no-build-isolation ./python[test]

- name: Run tests (serial)
run: coverage run --rcfile=.coveragerc -m mpi4py -m pytest python/tests/
Expand Down Expand Up @@ -178,7 +187,7 @@ jobs:
mpirun -n 2 coverage run --rcfile=.coveragerc -m mpi4py python/demos/demo_contact_3D.py --gmsh --no-slip --theta 1.05 --timing
mpirun -n 2 coverage run --rcfile=.coveragerc -m mpi4py python/demos/demo_contact_3D.py --gmsh --no-slip --hex --theta 0 --timing
mpirun -n 2 coverage run --rcfile=.coveragerc -m mpi4py python/demos/demo_contact_3D.py --gmsh --no-slip --hex --theta 1.05 --timing
- name: Combine coverage reports
run: |
coverage combine
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ CMakeFiles
**/html/**
**/_build/**
.coverage
.coverage.*
.coverage.*

python/dist
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
Author: Jørgen S. Dokken

This library contains an add-on to FEniCSx enabling the possibilities
of enforce multi-point constraints, such as
of enforce multi-point constraints, such as

$$u_i =\sum_{j=0,i \neq j}^n \alpha_j u_j, i\in I_N,$$

where $I_N$ is the set of degrees of freedom to constrain.

This can be used to for instance enforce slip conditions strongly.

Consider a linear system of the form
$Au=b$, with the additional constraints written on the form $K\hat u=u$, where $K$ is a prolongation matrix, $\hat u$ is the vector of unknowns excluding the $I_N$ entries.
Consider a linear system of the form
$Au=b$, with the additional constraints written on the form $K\hat u=u$, where $K$ is a prolongation matrix, $\hat u$ is the vector of unknowns excluding the $I_N$ entries.

We then solve the system
We then solve the system
$K^T A K \hat u = K^T b$, where $K^T A K$ is symmetric if $A$ was symmetric.
(For complex numbers, we use the Hermitian transpose and solve the system $\overline{K^T} A K \hat u = \overline{K^T} b$, where $\overline{K^T}$ is the complex conjugate of $K^T$, and $\overline{K^T} A K$ is Hermitian if $A$ was Hermitian.)

If we include boundary conditions on the form $u=g$, we
If we include boundary conditions on the form $u=g$, we
assemble the system
$K^TAK\hat u = K^T(b-A\hat g)$ where $A\hat g$ is an extension of the boundary condition $g$ to all degrees of freedom.

Expand Down Expand Up @@ -58,8 +58,12 @@ Easiest way to install DOLFINx is to use docker. The DOLFINx docker images goes
Remember to use an appropriate tag to get the correct version of DOLFINx, i.e. (`:nightly` or `:vx.y.z`).

To install the `dolfinx_mpc`-library run the following code from this directory:

```bash
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -B build-dir cpp/
ninja -j3 install -C build-dir
python3 -m pip install python/. --upgrade
```
python3 -m pip install sckikit-build-core[pyproject]
python3 -m pip install --no-build-isolation ./python --upgrade
```

Note: `--no-build-isolation` is required for `dolfinx_mpc` to find petsc4py, etc.
6 changes: 5 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.19)

PROJECT(dolfinx_mpc_pybind11)

# We can use newer FindPython because scikit-build-core backports it
set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 REQUIRED CONFIG HINTS ${PYBIND11_DIR} ${PYBIND11_ROOT}
$ENV{PYBIND11_DIR} $ENV{PYBIND11_ROOT})

Expand All @@ -19,6 +21,7 @@ pybind11_add_module(cpp SHARED
dolfinx_mpc/mpc.cpp
dolfinx_mpc/dolfinx_mpc.cpp)

target_compile_definitions(cpp PRIVATE VERSION_INFO=${SKBUILD_PROJECT_VERSION})
target_link_libraries(cpp PRIVATE pybind11::module)
target_link_libraries(cpp PUBLIC dolfinx_mpc)

Expand All @@ -40,7 +43,6 @@ if (HAVE_PEDANTIC)
target_compile_options(cpp PRIVATE -Wall;-Werror;-pedantic)
endif()


# Find petsc4py through python
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import petsc4py; print(petsc4py.get_include())"
Expand All @@ -50,3 +52,5 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)
target_include_directories(cpp PRIVATE ${PETSC4PY_INCLUDE_DIR})

install(TARGETS cpp LIBRARY DESTINATION "dolfinx_mpc")
28 changes: 28 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[build-system]
requires = ["scikit-build-core[pyproject]", "pybind11"]
build-backend = "scikit_build_core.build"

[project]
name = "dolfinx-mpc"
version = "0.7.0"
readme = "README.md"
# license = {file = "../LICENSE"}
requires-python = ">=3.8"
description = 'Python interface for multipointconstraints in dolfinx'
authors = [
{name = "Jørgen S. Dokken", email = "jorgensd@simula.no"},
]
dependencies = [
"numpy>=1.21",
"fenics-dolfinx>0.6.0.dev0"
]

[project.optional-dependencies]
docs = ["jupyter-book"]
test = ["pytest", "coverage"]

[tool.scikit-build]
# see https://scikit-build-core.readthedocs.io/en/latest/configuration.html for options
logging.level = "INFO"
cmake.verbose = true
cmake.minimum-version = "3.19"
94 changes: 0 additions & 94 deletions python/setup.py

This file was deleted.

0 comments on commit e09fe8a

Please sign in to comment.