Skip to content

Commit

Permalink
Typing cleanup + docker cleanup and numpy upgrade (#129)
Browse files Browse the repository at this point in the history
* Typing cleanup + docker cleanup and numpy upgrade

* Ignore complaint
  • Loading branch information
jorgensd authored Sep 14, 2024
1 parent 02338e6 commit c7df86a
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
cmake --install build-dir
- name: Install DOLFINx-MPC (Python)
run: python3 -m pip -v install --break-system-packages --config-settings=cmake.build-type="Release" --no-build-isolation ./python/[docs]
run: python3 -m pip -v install --config-settings=cmake.build-type="Release" --no-build-isolation ./python/[docs]

- name: Build docs
run: jupyter book build .
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test_mpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ jobs:
apt-get install -y clang
- name: upgrade pip
run: python3 -m pip install --break-system-packages --upgrade setuptools pip
run: python3 -m pip install --upgrade setuptools pip

- name: Check formatting
run: |
python3 -m pip install --break-system-packages ruff
python3 -m pip install ruff
ruff check
ruff format
- name: Check typing
run: |
python3 -m pip install --break-system-packages mypy
python3 -m pip install mypy
cd python
python3 -m mypy . --exclude=build
- name: Install h5py
run: |
python3 -m pip install --no-build-isolation --break-system-packages --no-cache-dir --no-binary=h5py h5py
python3 -m pip install --no-build-isolation --no-cache-dir --no-binary=h5py h5py
- name: Install DOLFINx
uses: jorgensd/actions/[email protected]
Expand All @@ -103,7 +103,7 @@ jobs:
cmake --install build-dir
- name: Install DOLFINx-MPC (Python)
run: python3 -m pip -v install --break-system-packages --config-settings=cmake.build-type=${MPC_BUILD_MODE} --no-build-isolation -e python/[test]
run: python3 -m pip -v install --config-settings=cmake.build-type=${MPC_BUILD_MODE} --no-build-isolation -e python/[test]

- name: Run tests (serial)
run: coverage run --rcfile=.coveragerc -m mpi4py -m pytest python/tests/ -vs
Expand Down
18 changes: 9 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ ARG PYTHON_VERSION=3.12
ENV HDF5_MPI="ON" \
HDF5_DIR="/usr/local"

RUN python3 -m pip install --break-system-packages -U pip setuptools
RUN python3 -m pip install -U pip setuptools

# Install h5py https://github.com/h5py/h5py/issues/2222
RUN python3 -m pip install --break-system-packages --no-cache-dir --no-binary=h5py git+https://github.com/h5py/h5py.git
RUN python3 -m pip install --break-system-packages meshio
RUN python3 -m pip install --no-cache-dir --no-binary=h5py git+https://github.com/h5py/h5py.git
RUN python3 -m pip install meshio

# Copy DOLFINX_MPC source dir
COPY . dolfinx_mpc

# Install real mode
RUN . /usr/local/bin/dolfinx-real-mode && \
. /usr/local/dolfinx-real/lib/dolfinx/dolfinx.conf && \
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local/dolfinx-real -DCMAKE_BUILD_TYPE=Developer -B build-dir-real dolfinx_mpc/cpp/ && \
ninja install -j4 -C build-dir-real && \
python3 -m pip install -v --break-system-packages --no-build-isolation --check-build-dependencies \
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local/dolfinx-real -DCMAKE_BUILD_TYPE=Developer -B build-dir-real dolfinx_mpc/cpp/ && \
ninja install -j4 -C build-dir-real && \
python3 -m pip install -v --no-build-isolation --check-build-dependencies \
--target /usr/local/dolfinx-real/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir ./dolfinx_mpc/python

# Clean repo to remove build dir from pip
Expand All @@ -32,9 +32,9 @@ RUN rm -rf dolfinx_mpc/python/build
# Install complex mode
RUN . /usr/local/bin/dolfinx-complex-mode && \
. /usr/local/dolfinx-complex/lib/dolfinx/dolfinx.conf && \
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local/dolfinx-complex -DCMAKE_BUILD_TYPE=Developer -B build-dir-complex dolfinx_mpc/cpp/ && \
ninja install -j4 -C build-dir-complex && \
python3 -m pip install --break-system-packages -v --no-build-isolation --check-build-dependencies \
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local/dolfinx-complex -DCMAKE_BUILD_TYPE=Developer -B build-dir-complex dolfinx_mpc/cpp/ && \
ninja install -j4 -C build-dir-complex && \
python3 -m pip install -v --no-build-isolation --check-build-dependencies \
--target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir ./dolfinx_mpc/python

WORKDIR /root
2 changes: 1 addition & 1 deletion python/benchmarks/bench_elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def l2b(li):
h5f.create_dataset("num_dofs", (N,), dtype=np.int32)
sd = h5f.create_dataset("solve_time", (N, MPI.COMM_WORLD.size), dtype=np.float64)
solver = "BoomerAMG" if args.boomeramg else "GAMG"
sd.attrs["solver"] = np.string_(solver)
sd.attrs["solver"] = np.bytes_(solver)

# Loop over refinement levels
for i in range(N):
Expand Down
6 changes: 3 additions & 3 deletions python/benchmarks/bench_elasticity_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def sigma(v):
sd = h5f.create_dataset("solve_time", (N, MPI.COMM_WORLD.size), dtype=np.float64)
solver = "BoomerAMG" if args.boomeramg else "GAMG"
ct = "Tet" if args.tetra else "Hex"
sd.attrs["solver"] = np.string_(solver)
sd.attrs["degree"] = np.string_(str(int(args.degree)))
sd.attrs["ct"] = np.string_(ct)
sd.attrs["solver"] = np.bytes_(solver)
sd.attrs["degree"] = np.bytes_(str(int(args.degree)))
sd.attrs["ct"] = np.bytes_(ct)

for i in range(N):
log_info(f"Run {i} in progress")
Expand Down
6 changes: 3 additions & 3 deletions python/benchmarks/bench_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ def periodic_relation(x):
sd = h5f.create_dataset("solve_time", (N, MPI.COMM_WORLD.size), dtype=np.float64)
solver = "BoomerAMG" if args.boomeramg else "GAMG"
ct = "Tet" if args.tetra else "Hex"
sd.attrs["solver"] = np.string_(solver)
sd.attrs["degree"] = np.string_(str(int(args.degree)))
sd.attrs["ct"] = np.string_(ct)
sd.attrs["solver"] = np.bytes_(solver)
sd.attrs["degree"] = np.bytes_(str(int(args.degree)))
sd.attrs["ct"] = np.bytes_(ct)

# Loop over refinements
for i in range(N):
Expand Down
6 changes: 3 additions & 3 deletions python/benchmarks/ref_elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def sigma(v):
sd = h5f.create_dataset("solve_time", (N, MPI.COMM_WORLD.size), dtype=np.float64)
solver = "BoomerAMG" if args.boomeramg else "GAMG"
ct = "Tet" if args.tetra else "Hex"
sd.attrs["solver"] = np.string_(solver)
sd.attrs["degree"] = np.string_(str(int(args.degree)))
sd.attrs["ct"] = np.string_(ct)
sd.attrs["solver"] = np.bytes_(solver)
sd.attrs["degree"] = np.bytes_(str(int(args.degree)))
sd.attrs["ct"] = np.bytes_(ct)

# Loop over refinement levels
for i in range(N):
Expand Down
6 changes: 3 additions & 3 deletions python/benchmarks/ref_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ def dirichletboundary(x):
sd = h5f.create_dataset("solve_time", (N, MPI.COMM_WORLD.size), dtype=np.float64)
solver = "BoomerAMG" if args.boomeramg else "GAMG"
ct = "Tet" if args.tetra else "Hex"
sd.attrs["solver"] = np.string_(solver)
sd.attrs["degree"] = np.string_(str(int(args.degree)))
sd.attrs["ct"] = np.string_(ct)
sd.attrs["solver"] = np.bytes_(solver)
sd.attrs["degree"] = np.bytes_(str(int(args.degree)))
sd.attrs["ct"] = np.bytes_(ct)
for i in range(N):
if MPI.COMM_WORLD.rank == 0:
set_log_level(LogLevel.INFO)
Expand Down
4 changes: 2 additions & 2 deletions python/demos/demo_elasticity_disconnect_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ def gather_dof_coordinates(V: FunctionSpace, dofs: np.ndarray):
coords = x[local_dofs]
num_nodes = len(coords)
glob_num_nodes = MPI.COMM_WORLD.allreduce(num_nodes, op=MPI.SUM)
recvbuf = None
recvbuf = np.empty(0, dtype=V.mesh.geometry.x.dtype)
if MPI.COMM_WORLD.rank == 0:
recvbuf = np.zeros(3 * glob_num_nodes, dtype=V.mesh.geometry.x.dtype)
sendbuf = coords.reshape(-1)
sendcounts = np.array(MPI.COMM_WORLD.gather(len(sendbuf), 0))
MPI.COMM_WORLD.Gatherv(sendbuf, (recvbuf, sendcounts), root=0)
MPI.COMM_WORLD.Gatherv(sendbuf, (recvbuf, sendcounts), root=0) # type: ignore
glob_coords = MPI.COMM_WORLD.bcast(recvbuf, root=0).reshape((-1, 3))
return glob_coords

Expand Down
2 changes: 1 addition & 1 deletion python/dolfinx_mpc/utils/mpc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def rigid_motions_nullspace(V: _fem.FunctionSpace):
b.scatter_forward()

_la.orthonormalize(nullspace_basis)
assert _la.is_orthonormal(nullspace_basis, np.finfo(_x.x.array.dtype).eps)
assert _la.is_orthonormal(nullspace_basis, float(np.finfo(_x.x.array.dtype).eps))
local_size = V.dofmap.index_map.size_local * V.dofmap.index_map_bs
basis_petsc = [
PETSc.Vec().createWithArray(x[:local_size], bsize=gdim, comm=V.mesh.comm) # type: ignore
Expand Down

0 comments on commit c7df86a

Please sign in to comment.