-
-
Notifications
You must be signed in to change notification settings - Fork 239
Extend mypy checks to test/ and demo/
#4135
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
base: main
Are you sure you want to change the base?
Changes from all commits
f82f667
452f4ae
4cb783a
a75f18d
791febb
ce1b911
d9a948d
7cf770b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Note: mypy is currenlty on CI tested without petsc4py! | ||
|
|
||
| PYTHON = python$(py) | ||
|
|
||
| lint-mypy: | ||
| $(PYTHON) -m venv dolfinx-venv-mypy | ||
| . dolfinx-venv-mypy/bin/activate && pip install mypy types-cffi scipy-stubs | ||
| . dolfinx-venv-mypy/bin/activate && mypy -p dolfinx | ||
| . dolfinx-venv-mypy/bin/activate && mypy test | ||
| . dolfinx-venv-mypy/bin/activate && mypy demo | ||
|
|
||
| lint-mypy-clean: | ||
| rm -rf dolfinx-venv-mypy | ||
|
|
||
| lint: lint-mypy | ||
|
|
||
| clean: lint-mypy-clean |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: | |
| solver_type: pyamg solver type, either "ruge_stuben" or | ||
| "smoothed_aggregation" | ||
| """ | ||
| real_type = np.real(dtype(0)).dtype | ||
| real_type = np.real(np.zeros(0, dtype=dtype)).dtype | ||
| mesh = create_box( | ||
| comm=MPI.COMM_WORLD, | ||
| points=[(0.0, 0.0, 0.0), (3.0, 2.0, 1.0)], | ||
|
|
@@ -84,7 +84,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: | |
|
|
||
| dofs = locate_dofs_topological(V=V, entity_dim=fdim, entities=facets) | ||
|
|
||
| bc = dirichletbc(value=dtype(0), dofs=dofs, V=V) | ||
| bc = dirichletbc(value=dtype(0.0), dofs=dofs, V=V) # type: ignore | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this kind of show that the type hint for dirichletbc is wrong?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem arises from the explicit demo/demo_pyamg.py:87: error: "dtype[Any]" not callable [operator]I tried multiple fixes but I am not sure how to correctly create a scalar of a certain type in a typing compliant way. Arrays work fine, but constructor of a dtype seems to be a different case. |
||
|
|
||
| u, v = ufl.TrialFunction(V), ufl.TestFunction(V) | ||
| x = ufl.SpatialCoordinate(mesh) | ||
|
|
@@ -110,14 +110,14 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: | |
| print(ml) | ||
|
|
||
| # Solve linear systems | ||
| print(f"\nSolve Poisson equation: {dtype.__name__}") | ||
| print(f"\nSolve Poisson equation: {dtype!s}") | ||
| res: list[float] = [] | ||
| tol = 1e-10 if real_type == np.float64 else 1e-6 | ||
| uh.x.array[:] = ml.solve(b.array, tol=tol, residuals=res, accel="cg") | ||
| for i, q in enumerate(res): | ||
| print(f"Convergence history: iteration {i}, residual= {q}") | ||
|
|
||
| with io.XDMFFile(mesh.comm, f"out_pyamg/poisson_{dtype.__name__}.xdmf", "w") as file: | ||
| with io.XDMFFile(mesh.comm, f"out_pyamg/poisson_{dtype!s}.xdmf", "w") as file: | ||
| file.write_mesh(mesh) | ||
| file.write_function(uh) | ||
|
|
||
|
|
@@ -126,7 +126,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: | |
|
|
||
|
|
||
| # + | ||
| def nullspace_elasticty(Q: fem.FunctionSpace) -> list[np.ndarray]: | ||
| def nullspace_elasticty(Q: fem.FunctionSpace) -> npt.NDArray: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this then have a type, otherwise I don't see the point of changing it to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this should hold a type, but it needs the generic type of |
||
| """Create the elasticity (near)nulspace. | ||
|
|
||
| Args: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I see the convenience of having this makefile, as it assumes:
pythonexecutable, notpython3.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added optional py variable, following https://gitlab.com/petsc/petsc/-/blob/main/src/binding/petsc4py/makefile?ref_type=heads#L9.
Invoking with
make py=3 lint-mypywill now use thepython3executable. If not provided defaults topython.