From 01b426f0517a6ce1f576b0078ca4975dc3de46b9 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Mon, 3 Aug 2026 16:04:41 +0200 Subject: [PATCH 1/3] Trigger CI From f3c448ef1b0a8efc94bb47f913b1ff312e753831 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Mon, 3 Aug 2026 16:55:56 +0200 Subject: [PATCH 2/3] Fix mypy issues --- src/dolfinx_adjoint/blocks/_vector.py | 29 +++++++++++++++++++++++++-- src/dolfinx_adjoint/types/function.py | 2 +- tests/test_poisson_mother.py | 4 ++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/dolfinx_adjoint/blocks/_vector.py b/src/dolfinx_adjoint/blocks/_vector.py index d7e9177..e44c7ce 100644 --- a/src/dolfinx_adjoint/blocks/_vector.py +++ b/src/dolfinx_adjoint/blocks/_vector.py @@ -1,12 +1,28 @@ +from typing import Generic, TypeVar + import dolfinx import numpy as np import numpy.typing as npt +_T = TypeVar("_T", np.float32, np.float64, np.complex64, np.complex128, np.int8, np.int32, np.int64) + -class _SpecialVector(dolfinx.la.Vector): +class _SpecialVector(dolfinx.la.Vector, Generic[_T]): """Workaround adding __iadd__ to `dolfinx.la.Vector`.""" - def __init__(self, x, function_space: dolfinx.fem.FunctionSpace): + def __init__( + self, + x: ( + dolfinx.cpp.la.Vector_float32 + | dolfinx.cpp.la.Vector_float64 + | dolfinx.cpp.la.Vector_complex64 + | dolfinx.cpp.la.Vector_complex128 + | dolfinx.cpp.la.Vector_int8 + | dolfinx.cpp.la.Vector_int32 + | dolfinx.cpp.la.Vector_int64 + ), + function_space: dolfinx.fem.FunctionSpace, + ): super().__init__(x) self._function_space = function_space @@ -41,6 +57,15 @@ def _vector( Returns: A distributed vector. """ + vtype: ( + type[dolfinx.cpp.la.Vector_float32] + | type[dolfinx.cpp.la.Vector_float64] + | type[dolfinx.cpp.la.Vector_complex64] + | type[dolfinx.cpp.la.Vector_complex128] + | type[dolfinx.cpp.la.Vector_int8] + | type[dolfinx.cpp.la.Vector_int32] + | type[dolfinx.cpp.la.Vector_int64] + ) if np.issubdtype(dtype, np.float32): vtype = dolfinx.cpp.la.Vector_float32 elif np.issubdtype(dtype, np.float64): diff --git a/src/dolfinx_adjoint/types/function.py b/src/dolfinx_adjoint/types/function.py index 15b0d7e..8168012 100644 --- a/src/dolfinx_adjoint/types/function.py +++ b/src/dolfinx_adjoint/types/function.py @@ -89,7 +89,7 @@ def _ad_dot(self, other: typing.Self, options: typing.Optional[dict] = None): options = {} if options is None else options riesz_representation = options.get("riesz_representation", "l2") if riesz_representation == "l2": - return dolfinx.cpp.la.inner_product(self.x._cpp_object, other.x._cpp_object) + return dolfinx.cpp.la.inner_product(self.x._cpp_object, other.x._cpp_object) # type: ignore[arg-type] elif riesz_representation == "L2": form_compiler_options = options.get("form_compiler_options", None) jit_options = options.get("jit_options", None) diff --git a/tests/test_poisson_mother.py b/tests/test_poisson_mother.py index ee465f4..6aa0892 100644 --- a/tests/test_poisson_mother.py +++ b/tests/test_poisson_mother.py @@ -136,8 +136,8 @@ def reference_solution( J_org = mesh.comm.allreduce(dolfinx.fem.assemble_scalar(dolfinx.fem.form(J_compiled)), op=MPI.SUM) steps = [step_length * (1 / 2) ** i for i in range(num_steps)] - dJac_dm = dolfinx.cpp.la.inner_product(Jac_vec._cpp_object, dm.x._cpp_object) - Hm_dm = dolfinx.cpp.la.inner_product(Hm_vec._cpp_object, dm.x._cpp_object) + dJac_dm = dolfinx.cpp.la.inner_product(Jac_vec._cpp_object, dm.x._cpp_object) # type: ignore[arg-type] + Hm_dm = dolfinx.cpp.la.inner_product(Hm_vec._cpp_object, dm.x._cpp_object) # type: ignore[arg-type] errors = [] errors_der = [] From e4e8b75f2870a2a577631b11dec009c1a9e8ee4a Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Tue, 4 Aug 2026 14:40:51 +0200 Subject: [PATCH 3/3] Remove unneeccsary typing --- src/dolfinx_adjoint/blocks/_vector.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/dolfinx_adjoint/blocks/_vector.py b/src/dolfinx_adjoint/blocks/_vector.py index e44c7ce..e9645c4 100644 --- a/src/dolfinx_adjoint/blocks/_vector.py +++ b/src/dolfinx_adjoint/blocks/_vector.py @@ -1,28 +1,12 @@ -from typing import Generic, TypeVar - import dolfinx import numpy as np import numpy.typing as npt -_T = TypeVar("_T", np.float32, np.float64, np.complex64, np.complex128, np.int8, np.int32, np.int64) - -class _SpecialVector(dolfinx.la.Vector, Generic[_T]): +class _SpecialVector(dolfinx.la.Vector): """Workaround adding __iadd__ to `dolfinx.la.Vector`.""" - def __init__( - self, - x: ( - dolfinx.cpp.la.Vector_float32 - | dolfinx.cpp.la.Vector_float64 - | dolfinx.cpp.la.Vector_complex64 - | dolfinx.cpp.la.Vector_complex128 - | dolfinx.cpp.la.Vector_int8 - | dolfinx.cpp.la.Vector_int32 - | dolfinx.cpp.la.Vector_int64 - ), - function_space: dolfinx.fem.FunctionSpace, - ): + def __init__(self, x, function_space: dolfinx.fem.FunctionSpace): super().__init__(x) self._function_space = function_space