Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to nanobind #2820

Merged
merged 171 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 162 commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
1e1b056
First try to use nanobind with dolfinx [skip ci]
chrisrichardson Jun 16, 2023
9cb4aef
Fix pack coefficients [skip ci]
chrisrichardson Jun 16, 2023
1a57091
Disable petsc for now
chrisrichardson Jun 16, 2023
651a5f6
Small fixes [skip ci]
chrisrichardson Jun 16, 2023
ab12153
Get fem.cpp compiling
chrisrichardson Oct 3, 2023
64d15da
Fix graph and geometry
chrisrichardson Oct 3, 2023
1e66ee9
Update to main
chrisrichardson Oct 4, 2023
1b2856b
Get a few tests working
chrisrichardson Oct 4, 2023
9581400
More fixes
chrisrichardson Oct 4, 2023
0670a74
remove duplicate line
chrisrichardson Oct 4, 2023
edf353a
merge
chrisrichardson Oct 4, 2023
e631717
hack dtype
chrisrichardson Oct 6, 2023
f81c8f3
merge
chrisrichardson Oct 14, 2023
d29c9df
updates
chrisrichardson Oct 14, 2023
cb6972b
Merge branch 'main' into nanobind
chrisrichardson Oct 18, 2023
d7597cc
update for numpy_dtype
chrisrichardson Oct 18, 2023
f590494
Install nanobind in CI
chrisrichardson Oct 19, 2023
9dcaf39
Install in right place
chrisrichardson Oct 19, 2023
633f629
Fix one test
chrisrichardson Oct 19, 2023
b392f4e
Fix a few issues
chrisrichardson Oct 19, 2023
09e8def
Fix complex dtype
chrisrichardson Oct 19, 2023
a606e0f
Enable some PETSc
chrisrichardson Oct 19, 2023
9a6ba9c
Some bits and pieces
chrisrichardson Oct 19, 2023
80f7b4f
More fixes
chrisrichardson Oct 20, 2023
56b7c19
Enable more PETSc
chrisrichardson Oct 20, 2023
5b7f81b
Some fixes
garth-wells Oct 20, 2023
ec51dd6
Fix more failing tests
chrisrichardson Oct 20, 2023
ea5f205
Merge branch 'nanobind' of ssh://github.com/fenics/dolfinx into nanobind
chrisrichardson Oct 20, 2023
cc7cd40
Get some cppimport working
chrisrichardson Oct 20, 2023
046ad0b
More fixes
chrisrichardson Oct 20, 2023
5f989a4
Get bindings to compile
garth-wells Oct 20, 2023
8e74e83
Merge branch 'nanobind' of github.com:FEniCS/dolfinx into nanobind
garth-wells Oct 20, 2023
436feae
Change nanobind install
garth-wells Oct 20, 2023
14463f3
CI updates
garth-wells Oct 20, 2023
7777fc8
Updates
garth-wells Oct 20, 2023
f968a6e
Update
garth-wells Oct 20, 2023
be2dac9
Fix cast
garth-wells Oct 20, 2023
f36247f
Get building working
garth-wells Oct 20, 2023
62c9980
Updates
garth-wells Oct 20, 2023
b6162c0
Update
garth-wells Oct 20, 2023
48ddac8
Change linking
garth-wells Oct 20, 2023
08bb833
Get elasticity demo working
garth-wells Oct 20, 2023
e5a3707
Tidy
garth-wells Oct 21, 2023
1970f68
Enable Constant value
chrisrichardson Oct 21, 2023
081f88b
Merge branch 'nanobind' of ssh://github.com/fenics/dolfinx into nanobind
chrisrichardson Oct 21, 2023
9ff87c7
Fix
garth-wells Oct 21, 2023
66900da
Merge branch 'nanobind' of github.com:FEniCS/dolfinx into nanobind
garth-wells Oct 21, 2023
a29cbb2
Constants fix
garth-wells Oct 21, 2023
e3c601e
IO fix
garth-wells Oct 21, 2023
c554c0e
Limit tests
garth-wells Oct 21, 2023
db68887
Disable doc tests
garth-wells Oct 21, 2023
5bf3167
Add missing include
garth-wells Oct 21, 2023
e9f49a8
Fixes
garth-wells Oct 21, 2023
9396cd5
Updates
garth-wells Oct 21, 2023
5b80504
Update demo
garth-wells Oct 21, 2023
07cd174
Comment out part of demo
garth-wells Oct 21, 2023
75a6143
Constrain array
garth-wells Oct 21, 2023
38d59e6
Disable more code
garth-wells Oct 21, 2023
cefe64c
Improvements
garth-wells Oct 21, 2023
21470b6
Disable MPI Python unit tests
garth-wells Oct 21, 2023
4f4a82b
IO update
garth-wells Oct 21, 2023
5062d0d
flake8 fix
garth-wells Oct 21, 2023
0ad6e40
Disable some tests
garth-wells Oct 21, 2023
d677ead
flake8 fixes
garth-wells Oct 21, 2023
90c2980
Syntax fix
garth-wells Oct 21, 2023
ff65a33
range fix
garth-wells Oct 21, 2023
940cfe7
Get bbox working
garth-wells Oct 21, 2023
99dc406
Simplify
garth-wells Oct 21, 2023
a5e6731
Fix test
garth-wells Oct 21, 2023
506077c
Fix numba test
garth-wells Oct 21, 2023
a8a41fd
Fixes
garth-wells Oct 21, 2023
58371a0
Fix
garth-wells Oct 21, 2023
22d4e60
Fix
garth-wells Oct 21, 2023
89d7391
Update demo
garth-wells Oct 21, 2023
4faa2c3
mypy fix
garth-wells Oct 21, 2023
d2f1986
Demo fix
garth-wells Oct 21, 2023
5f9a02b
Disable doc ci
garth-wells Oct 22, 2023
2ccae21
Parallel fix
garth-wells Oct 22, 2023
01bbe6b
reduce output
garth-wells Oct 22, 2023
ca5900c
Relax doc generation
garth-wells Oct 22, 2023
eebf38d
Enable more tests
garth-wells Oct 22, 2023
2ee8a90
Improvements
garth-wells Oct 22, 2023
6b51759
Fix
garth-wells Oct 22, 2023
447c5c5
Improvement
garth-wells Oct 22, 2023
21e2969
Adj list fix
garth-wells Oct 22, 2023
710cdbc
Merge branch 'main' into nanobind
garth-wells Oct 22, 2023
eea3407
Try shared linking
garth-wells Oct 22, 2023
9c9f339
Disable MPI/cppimport test
garth-wells Oct 22, 2023
74ca069
Simplify
garth-wells Oct 22, 2023
15367ae
Small fixes
garth-wells Oct 22, 2023
b5a0f86
Remove shared lib nanobind
garth-wells Oct 22, 2023
1568833
Improve formatting
garth-wells Oct 22, 2023
943687c
Include nanobind complex header
garth-wells Oct 22, 2023
b93f80c
Run CI with complex
garth-wells Oct 22, 2023
9f2936d
Type change
garth-wells Oct 22, 2023
db11fde
Work-around for possible bug in nanobind.
garth-wells Oct 23, 2023
bcc8018
Bug fixes
garth-wells Oct 23, 2023
74c6d3d
Some work-arounds
garth-wells Oct 23, 2023
e727ab7
Disable complex tests
garth-wells Oct 23, 2023
107af59
Disable oneapi tests
garth-wells Oct 23, 2023
c06aca5
flake8 fix
garth-wells Oct 23, 2023
52c2c75
Enable complex test
garth-wells Oct 24, 2023
06271b7
Updates
garth-wells Oct 24, 2023
1d6559f
Real tests only
garth-wells Oct 24, 2023
bac0e01
Switch to writeable arrays
garth-wells Oct 24, 2023
6e2ade6
Enable some tests
garth-wells Oct 24, 2023
0a4695f
Small update
garth-wells Oct 24, 2023
719948d
Logic fix
garth-wells Oct 24, 2023
4524bc2
Fixes
garth-wells Oct 24, 2023
70f64d2
Get complex test passing
garth-wells Oct 24, 2023
cf3b5de
Enable more CI test images
garth-wells Oct 24, 2023
1a8be22
oneAPI parallel tests
garth-wells Oct 25, 2023
55e01b2
Use read-only PETSc Numpy arrays and use nanobind dev version (#2825)
garth-wells Oct 25, 2023
575f80f
Merge branch 'main' into nanobind
garth-wells Oct 25, 2023
e824348
Array improvements (nanobind) (#2827)
garth-wells Oct 26, 2023
c51010a
Revert to static nanobind lib
garth-wells Oct 26, 2023
05c563a
Merge branch 'main' into nanobind
garth-wells Oct 26, 2023
6b6ce65
[nanobind] improve wrapping by ndarray (#2829)
garth-wells Oct 26, 2023
f8d8938
Merge remote-tracking branch 'origin/main' into nanobind
garth-wells Oct 26, 2023
3cd7ac6
flake8 fixes
garth-wells Oct 26, 2023
7a4ba75
Fixes
garth-wells Oct 26, 2023
76f6ca7
Small tidy up
garth-wells Oct 27, 2023
5958516
Improvements (#2830)
garth-wells Oct 27, 2023
84e9d57
[nanobind] array improvements (#2832)
garth-wells Oct 27, 2023
ad0304a
Syntax improvements
garth-wells Oct 27, 2023
7dfb91f
Updates
garth-wells Oct 27, 2023
f778494
Uncomment test body
garth-wells Oct 27, 2023
7230e5d
Uncomment test
garth-wells Oct 27, 2023
19625cd
Disable test
garth-wells Oct 27, 2023
626ba69
Merge branch 'main' into nanobind
garth-wells Oct 27, 2023
ca14bf6
[nanobind] improve casters (#2837)
garth-wells Oct 30, 2023
cf9f5ae
Remove a few more occurences of pybind11 (#2834)
francesco-ballarin Oct 30, 2023
48e352f
Merge remote-tracking branch 'origin/main' into nanobind
garth-wells Oct 30, 2023
98596e1
[nanobind] merge pyproject change from main (#2840)
garth-wells Oct 30, 2023
0e061d3
Small edits
garth-wells Oct 30, 2023
2fbe6e6
Merge remote-tracking branch 'origin/main' into nanobind
garth-wells Oct 30, 2023
c135287
Enable test output
garth-wells Oct 30, 2023
f3300ba
Move nanobind install to top for oneapi
garth-wells Oct 30, 2023
77556b3
oneapi update
garth-wells Oct 30, 2023
c1d5eb3
Install scikit-build-core
garth-wells Oct 31, 2023
1195060
Merge branch 'main' into nanobind
garth-wells Oct 31, 2023
0a6aab2
Move steps in CI
garth-wells Oct 31, 2023
0d119e6
Reduce test size
garth-wells Oct 31, 2023
c3ba57b
[nanobind] set to nanobind dev version in requirements (#2841)
garth-wells Oct 31, 2023
00df985
Merge branch 'main' into nanobind
garth-wells Oct 31, 2023
5232dcd
Revert mesh partition change
garth-wells Nov 1, 2023
24e1086
Remove test that isn't helpful
garth-wells Nov 1, 2023
42c56d4
flake8 fix
garth-wells Nov 1, 2023
7c26d44
Add skip for @entries in nanobind
cnr12 Nov 1, 2023
7fb05ee
Revert
cnr12 Nov 1, 2023
df23a8f
Add back sphinx -W and try new version
chrisrichardson Nov 2, 2023
78232cc
merge
chrisrichardson Nov 2, 2023
a20b3aa
Set nanobind version
garth-wells Nov 2, 2023
dc01244
Merge remote-tracking branch 'origin/main' into nanobind
garth-wells Nov 2, 2023
c9f9607
Re-enable a float32 test
garth-wells Nov 2, 2023
55b427d
Merge remote-tracking branch 'origin/main' into nanobind
garth-wells Nov 2, 2023
7b0a037
Fix CI
garth-wells Nov 2, 2023
1b1470d
Simplify
garth-wells Nov 2, 2023
45f6d07
Undo demo change
garth-wells Nov 2, 2023
f5785fa
Re-enable partiton code. (#2859)
garth-wells Nov 2, 2023
c3545c8
Add missing include
garth-wells Nov 3, 2023
4c3947e
Disable nanobind leak messages in release mode
garth-wells Nov 3, 2023
e13359b
Run all oneAPI tests
garth-wells Nov 3, 2023
029be3b
Misc fixes and tidying
garth-wells Nov 3, 2023
6c75d00
Remove cppimport examples
garth-wells Nov 3, 2023
7120256
Merge branch 'main' into nanobind
garth-wells Nov 3, 2023
937fd44
Replace std::vector with nb::ndarray
garth-wells Nov 3, 2023
9bea2b1
Merge branch 'nanobind' of github.com:FEniCS/dolfinx into nanobind
garth-wells Nov 3, 2023
819afb5
Array cast fix
garth-wells Nov 3, 2023
1e9cb5b
Updates
garth-wells Nov 3, 2023
15667fd
Merge branch 'main' into nanobind
garth-wells Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ regression-tests-cpp-mpi: &regression-tests-cpp-mpi
ctest --verbose -R demo -R mpi_3

build-python-interface: &build-python-interface
name: Build Python/pybind11 interface
name: Build Python/nanobind interface
command: |
export CMAKE_BUILD_PARALLEL_LEVEL=2
cd python
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ jobs:

- name: Build Python interface
run: |
python3 -m pip -v install --check-build-dependencies --no-build-isolation python/
python3 -m pip install -r python/build-requirements.txt # TO REMOVE
python3 -m pip -v install --check-build-dependencies --no-build-isolation --config-settings=cmake.build-type="Debug" python/
- name: Build Python interface documentation
run: |
cd python/doc
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/oneapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
- name: Build DOLFINx Python interface
run: |
. /opt/intel/oneapi/setvars.sh
pip install -r python/build-requirements.txt # TO REMOVE
pip -v install --check-build-dependencies --no-build-isolation python/
- name: Set default DOLFINx JIT options
run: |
Expand All @@ -99,14 +100,12 @@ jobs:
- name: Run DOLFINx demos (Python, MPI (np=2))
run: |
. /opt/intel/oneapi/setvars.sh
pytest -v -m mpi --num-proc=2 python/demo/test.py
pytest -m mpi --num-proc=2 python/demo/test.py
- name: Run DOLFINx Python unit tests (serial)
run: |
. /opt/intel/oneapi/setvars.sh
cd python/test
pytest -n=auto --durations=50 unit/
pytest -vs -n=auto --durations=50 python/test/unit/fem
garth-wells marked this conversation as resolved.
Show resolved Hide resolved
- name: Run DOLFINx Python unit tests (MPI, np=2)
run: |
. /opt/intel/oneapi/setvars.sh
cd python/test
mpiexec -n 2 pytest -vs unit/
mpiexec -n 2 pytest -vs python/test/unit/fem
1 change: 1 addition & 0 deletions .github/workflows/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:

- name: Build Python interface (editable install)
run: |
python3 -m pip install -r python/build-requirements.txt # TO REMOVE
python3 -m pip -v install --check-build-dependencies --no-build-isolation --config-settings=cmake.build-type=Debug --config-settings=build-dir="build" -e python/

- name: Set default DOLFINx JIT options
Expand Down
2 changes: 1 addition & 1 deletion cpp/dolfinx/fem/DofMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DofMap
DofMap(DofMap&& dofmap) = default;

// Destructor
virtual ~DofMap() = default;
~DofMap() = default;

// Copy assignment
DofMap& operator=(const DofMap& dofmap) = delete;
Expand Down
2 changes: 1 addition & 1 deletion cpp/dolfinx/fem/FiniteElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FiniteElement
FiniteElement(FiniteElement&& element) = default;

/// Destructor
virtual ~FiniteElement() = default;
~FiniteElement() = default;

/// Copy assignment
FiniteElement& operator=(const FiniteElement& element) = delete;
Expand Down
27 changes: 14 additions & 13 deletions cpp/dolfinx/geometry/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,16 @@ graph::AdjacencyList<std::int32_t> compute_colliding_cells(
/// @param[in] mesh The mesh
/// @param[in] points Points to check for collision (`shape=(num_points,
/// 3)`). Storage is row-major.
/// @return Quadratuplet (src_owner, dest_owner, dest_points,
/// dest_cells), where src_owner is a list of ranks corresponding to the
/// input points. dest_owner is a list of ranks corresponding to
/// dest_points, the points that this process owns. dest_cells contains
/// the corresponding cell for each entry in dest_points.
/// @return Tuple `(src_owner, dest_owner, dest_points, dest_cells)`,
/// where src_owner is a list of ranks corresponding to the input
/// points. dest_owner is a list of ranks corresponding to dest_points,
/// the points that this process owns. dest_cells contains the
/// corresponding cell for each entry in dest_points.
///
/// @note dest_owner is sorted
/// @note `dest_owner` is sorted
/// @note Returns -1 if no colliding process is found
/// @note dest_points is flattened row-major, shape (dest_owner.size(), 3)
/// @note dest_points is flattened row-major, shape `(dest_owner.size(),
/// 3)`
/// @note Only looks through cells owned by the process
template <std::floating_point T>
std::tuple<std::vector<std::int32_t>, std::vector<std::int32_t>, std::vector<T>,
Expand Down Expand Up @@ -700,8 +701,8 @@ determine_point_ownership(const mesh::Mesh<T>& mesh, std::span<const T> points)
comm, in_ranks.size(), in_ranks.data(), MPI_UNWEIGHTED, out_ranks.size(),
out_ranks.data(), MPI_UNWEIGHTED, MPI_INFO_NULL, false, &forward_comm);

// Compute map from global mpi rank to neighbor rank, "collisions" uses
// global rank
// Compute map from global mpi rank to neighbor rank, "collisions"
// uses global rank
std::map<std::int32_t, std::int32_t> rank_to_neighbor;
for (std::size_t i = 0; i < out_ranks.size(); i++)
rank_to_neighbor[out_ranks[i]] = i;
Expand Down Expand Up @@ -755,8 +756,8 @@ determine_point_ownership(const mesh::Mesh<T>& mesh, std::span<const T> points)
dolfinx::MPI::mpi_type<T>(), received_points.data(), recv_sizes.data(),
recv_offsets.data(), dolfinx::MPI::mpi_type<T>(), forward_comm);

// Each process checks which local cell is closest and computes the squared
// distance to the cell
// Each process checks which local cell is closest and computes the
// squared distance to the cell
const int rank = dolfinx::MPI::rank(comm);
const std::vector<std::int32_t> closest_cells = compute_closest_entity(
bb, midpoint_tree, mesh,
Expand Down Expand Up @@ -804,8 +805,8 @@ determine_point_ownership(const mesh::Mesh<T>& mesh, std::span<const T> points)
for (std::int32_t j = recv_offsets[i]; j < recv_offsets[i + 1]; j++)
{
const std::int32_t pos = unpack_map[j];
// If point has not been found yet distance is negative
// If new received distance smaller than current distance choose owner
// If point has not been found yet distance is negative. If new
// received distance smaller than current distance choose owner.
if (auto d = closest_distance[pos]; d < 0 or d > recv_distances[j])
{
point_owners[pos] = out_ranks[i];
Expand Down
2 changes: 1 addition & 1 deletion cpp/dolfinx/la/MatrixCSR.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace dolfinx::la
{
/// @brief Modes for representing block structured matrices
enum class BlockMode : int
enum class BlockMode
{
compact = 0, /// Each entry in the sparsity pattern of the matrix refers to a
/// block of data of size (bs[0], bs[1]).
Expand Down
4 changes: 2 additions & 2 deletions cpp/dolfinx/la/petsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ std::vector<IS> la::petsc::create_index_sets(
std::int64_t offset = 0;
for (auto& map : maps)
{
const int bs = map.second;
const std::int32_t size
int bs = map.second;
std::int32_t size
garth-wells marked this conversation as resolved.
Show resolved Hide resolved
= map.first.get().size_local() + map.first.get().num_ghosts();
IS _is;
ISCreateStride(PETSC_COMM_SELF, bs * size, offset, 1, &_is);
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.oneapi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ARG HDF5_PATCH=2
ARG HDF5_FIX=
ARG PETSC_VERSION=3.20.0
ARG SLEPC_VERSION=3.20.0
ARG PYBIND11_VERSION=2.11.1
ARG NANOBIND_VERSION=1.8.0
ARG KAHIP_VERSION=3.15

WORKDIR /tmp
Expand Down Expand Up @@ -58,7 +58,7 @@ ENV CC=icx \

# Install Python packages (via pip)
RUN . /opt/intel/oneapi/setvars.sh && \
pip install --no-cache-dir cppimport matplotlib mpi4py pybind11==${PYBIND11_VERSION} pytest pytest-xdist scikit-build-core[pyproject]
pip install --no-cache-dir cppimport matplotlib mpi4py nanobind==${NANOBIND_VERSION} pytest pytest-xdist scikit-build-core[pyproject]

# Install KaHIP
RUN . /opt/intel/oneapi/setvars.sh && \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.redhat
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RUN curl -L -O https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-${HDF5_SERIES

# First set of dependencies for building and running Python DOLFINx
# Second set of dependencies for running DOLFINx tests
RUN python3 -m pip install --no-cache-dir cffi numba mpi4py pybind11 scikit-build-core[pyproject] wheel && \
RUN python3 -m pip install --no-cache-dir cffi numba mpi4py nanobind scikit-build-core[pyproject] wheel && \
python3 -m pip install --no-cache-dir cppimport pytest pytest-xdist scipy matplotlib

# Build PETSc
Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile.test-env
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ARG HDF5_PATCH=2
ARG HDF5_FIX=
ARG KAHIP_VERSION=3.15
ARG NUMPY_VERSION=1.23.2
ARG PYBIND11_VERSION=2.11.1
ARG NANOBIND_VERSION=1.8.0
ARG PETSC_VERSION=3.20.0
ARG SLEPC_VERSION=3.20.0

Expand All @@ -39,7 +39,7 @@ ARG GMSH_VERSION
ARG HDF5_SERIES
ARG HDF5_PATCH
ARG HDF5_FIX
ARG PYBIND11_VERSION
ARG NANOBIND_VERSION
ARG PETSC_VERSION
ARG SLEPC_VERSION
ARG ADIOS2_VERSION
Expand Down Expand Up @@ -153,8 +153,8 @@ RUN if [ "$MPI" = "mpich" ]; then \
# - Second set of packages are recommended and/or required to build
# documentation or run tests.
RUN pip3 install --no-cache-dir --upgrade setuptools pip && \
pip3 install --no-cache-dir cffi mpi4py numba numpy==${NUMPY_VERSION} scikit-build-core[pyproject] && \
pip3 install --no-cache-dir breathe clang-format cppimport cmakelang flake8 isort jupytext matplotlib mypy myst-parser pybind11==${PYBIND11_VERSION} pytest pytest-xdist scipy sphinx==5.0.2 sphinx_rtd_theme types-setuptools
pip3 install -no-cache-dir cffi mpi4py numba numpy==${NUMPY_VERSION} scikit-build-core[pyproject] && \
garth-wells marked this conversation as resolved.
Show resolved Hide resolved
pip3 install --no-cache-dir breathe clang-format cppimport cmakelang flake8 isort jupytext matplotlib mypy myst-parser nanobind==${NANOBIND_VERSION} pytest pytest-xdist scipy sphinx==5.0.2 sphinx_rtd_theme types-setuptools

# Install KaHIP
RUN wget -nc --quiet https://github.com/kahip/kahip/archive/v${KAHIP_VERSION}.tar.gz && \
Expand Down
77 changes: 26 additions & 51 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,26 @@
cmake_minimum_required(VERSION 3.18)

project(fenics-dolfinx)
project(dolfinx_nanobind)

# Set C++ standard before finding pybind11
# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(
Python3
COMPONENTS Interpreter Development.Module
REQUIRED
)
# set(CMAKE_BUILD_TYPE Debug)
garth-wells marked this conversation as resolved.
Show resolved Hide resolved
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# Help cmake find pybind11 installed as Python package
execute_process(
COMMAND "${Python3_EXECUTABLE}" "-c"
"import pybind11; print(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE PYBIND11_CMAKE_DIR
RESULT_VARIABLE PYBIND11_COMMAND_RESULT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_package(Python COMPONENTS Interpreter Development REQUIRED)

if(NOT PYBIND11_COMMAND_RESULT)
message(STATUS "Found pybind11 cmake directory at ${PYBIND11_CMAKE_DIR}")
endif()

find_package(
pybind11
2.9.1
REQUIRED
CONFIG
HINTS
${PYBIND11_CMAKE_DIR}
${PYBIND11_DIR}
${PYBIND11_ROOT}
$ENV{PYBIND11_DIR}
$ENV{PYBIND11_ROOT}
)
# Detect the installed nanobind package and import it into CMake
execute_process(
garth-wells marked this conversation as resolved.
Show resolved Hide resolved
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
find_package(nanobind CONFIG REQUIRED)

execute_process(
COMMAND
Expand All @@ -46,16 +29,16 @@ execute_process(
RESULT_VARIABLE BASIX_PY_COMMAND_RESULT
ERROR_VARIABLE BASIX_ERROR_OUT OUTPUT_STRIP_TRAILING_WHITESPACE
)

find_package(Basix REQUIRED CONFIG HINTS ${BASIX_PY_DIR})

find_package(DOLFINX REQUIRED CONFIG)

# Create the binding library pybind11 handles its own calls to
# Create the binding library nanobind handles its own calls to
# target_link_libraries
pybind11_add_module(
nanobind_add_module(
cpp
MODULE

# NB_SHARED
dolfinx/wrappers/dolfinx.cpp
dolfinx/wrappers/assemble.cpp
dolfinx/wrappers/common.cpp
Expand All @@ -71,26 +54,19 @@ pybind11_add_module(
)

# Add strict compiler flags
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-Wall -Werror -pedantic" HAVE_PEDANTIC)
# include(CheckCXXCompilerFlag)
# check_cxx_compiler_flag("-Wall -Werror -pedantic" HAVE_PEDANTIC)

if(HAVE_PEDANTIC)
target_compile_options(cpp PRIVATE -Wall;-Werror;-pedantic)
endif()

# In Debug mode override pybind11 symbols visibility Symbols must be visible to
# backtrace_symbols() to produce nice logs
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(cpp PRIVATE "-fvisibility=default")
endif()
# if(HAVE_PEDANTIC)
# # target_compile_options(cpp PRIVATE -Wall;-Werror;-pedantic)
# endif()

# Add DOLFINx libraries.
# Add DOLFINx libraries
target_link_libraries(cpp PRIVATE dolfinx)

# Check for petsc4py
execute_process(
COMMAND ${Python3_EXECUTABLE} -c
"import petsc4py; print(petsc4py.get_include())"
COMMAND ${Python_EXECUTABLE} -c "import petsc4py; print(petsc4py.get_include())"
OUTPUT_VARIABLE PETSC4PY_INCLUDE_DIR
RESULT_VARIABLE PETSC4PY_COMMAND_RESULT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -105,8 +81,7 @@ endif()

# Check for mpi4py
execute_process(
COMMAND "${Python3_EXECUTABLE}" "-c"
"import mpi4py; print(mpi4py.get_include())"
COMMAND "${Python_EXECUTABLE}" -c "import mpi4py; print(mpi4py.get_include())"
OUTPUT_VARIABLE MPI4PY_INCLUDE_DIR
RESULT_VARIABLE MPI4PY_COMMAND_RESULT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
Expand Down
2 changes: 1 addition & 1 deletion python/build-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pybind11>=2.9.1
nanobind>=1.8.0
scikit-build-core[pyproject]
petsc4py
mpi4py
6 changes: 3 additions & 3 deletions python/demo/demo_axis/demo_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ def create_eps_mu(pml, rho, eps_bkg, mu_bkg):
print()
print(f"The analytical absorption efficiency is {q_abs_analyt}")
print(f"The numerical absorption efficiency is {q_abs_fenics}")
print(f"The error is {err_abs*100}%")
print(f"The error is {err_abs * 100}%")
print()
print(f"The analytical scattering efficiency is {q_sca_analyt}")
print(f"The numerical scattering efficiency is {q_sca_fenics}")
print(f"The error is {err_sca*100}%")
print(f"The error is {err_sca * 100}%")
print()
print(f"The analytical extinction efficiency is {q_ext_analyt}")
print(f"The numerical extinction efficiency is {q_ext_fenics}")
print(f"The error is {err_ext*100}%")
print(f"The error is {err_ext * 100}%")

# Check whether the geometrical and optical parameters are correct
# assert radius_sph / wl0 == 0.025 / 0.4
Expand Down
2 changes: 1 addition & 1 deletion python/demo/demo_cahn-hilliard.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
while (t < T):
t += dt
r = solver.solve(u)
print(f"Step {int(t/dt)}: num iterations: {r[0]}")
print(f"Step {int(t / dt)}: num iterations: {r[0]}")
u0.x.array[:] = u.x.array
file.write_function(c, t)

Expand Down
6 changes: 3 additions & 3 deletions python/demo/demo_pml/demo_pml.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,15 @@ def create_eps_mu(pml: ufl.tensors.ListTensor,
print()
print(f"The analytical absorption efficiency is {q_abs_analyt}")
print(f"The numerical absorption efficiency is {q_abs_fenics}")
print(f"The error is {err_abs*100}%")
print(f"The error is {err_abs * 100}%")
print()
print(f"The analytical scattering efficiency is {q_sca_analyt}")
print(f"The numerical scattering efficiency is {q_sca_fenics}")
print(f"The error is {err_sca*100}%")
print(f"The error is {err_sca * 100}%")
print()
print(f"The analytical extinction efficiency is {q_ext_analyt}")
print(f"The numerical extinction efficiency is {q_ext_fenics}")
print(f"The error is {err_ext*100}%")
print(f"The error is {err_ext * 100}%")
# -

# Check if errors are smaller than 1%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,12 @@ def curl_2d(f: fem.Function):
print()
print(f"The analytical absorption efficiency is {q_abs_analyt}")
print(f"The numerical absorption efficiency is {q_abs_fenics}")
print(f"The error is {err_abs*100}%")
print(f"The error is {err_abs * 100}%")
print()
print(f"The analytical scattering efficiency is {q_sca_analyt}")
print(f"The numerical scattering efficiency is {q_sca_fenics}")
print(f"The error is {err_sca*100}%")
print(f"The error is {err_sca * 100}%")
print()
print(f"The analytical extinction efficiency is {q_ext_analyt}")
print(f"The numerical extinction efficiency is {q_ext_fenics}")
print(f"The error is {err_ext*100}%")
print(f"The error is {err_ext * 100}%")
Loading