Skip to content

Commit b082cdc

Browse files
michalk8msmdev
andauthored
Feature/petsc real type (#53)
* Check if `PETSc` is compiled with `--with-scalar-type=real`. * Update pre-commits. * Remove `flake8-mock` causing issues with `yesqa`. * Remove outdated additional_dependencies. * Use `codecov` action. * Fix CI badge and tox. * Fix linter. * Ignore vscode config files. Co-authored-by: Bernhard Reuter <bernhard-reuter@gmx.de>
1 parent abc5b40 commit b082cdc

7 files changed

Lines changed: 47 additions & 16 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,6 @@ dmypy.json
134134

135135
# docs
136136
docs/source/api/*rst
137+
138+
# VSCode
139+
.vscode/

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ default_stages:
77
minimum_pre_commit_version: 2.9.0
88
repos:
99
- repo: https://github.com/pre-commit/mirrors-mypy
10-
rev: v0.982
10+
rev: v0.991
1111
hooks:
1212
- id: mypy
1313
additional_dependencies: [numpy==1.20.0, scipy>=1.6.0]
1414
- repo: https://github.com/psf/black
15-
rev: 22.10.0
15+
rev: 22.12.0
1616
hooks:
1717
- id: black
1818
additional_dependencies: [toml]
1919
- repo: https://github.com/timothycrosley/isort
20-
rev: 5.10.1
20+
rev: 5.11.4
2121
hooks:
2222
- id: isort
2323
additional_dependencies: [toml]
@@ -28,12 +28,12 @@ repos:
2828
- id: yesqa
2929
additional_dependencies: [flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-string-format]
3030
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
31-
rev: v2.4.0
31+
rev: v2.5.0
3232
hooks:
3333
- id: pretty-format-yaml
3434
args: [--autofix, --indent, '4', --preserve-quotes]
3535
- repo: https://github.com/pre-commit/pre-commit-hooks
36-
rev: v4.3.0
36+
rev: v4.4.0
3737
hooks:
3838
- id: detect-private-key
3939
- id: check-merge-conflict
@@ -55,13 +55,13 @@ repos:
5555
- id: check-yaml
5656
- id: check-toml
5757
- id: requirements-txt-fixer
58-
- repo: https://gitlab.com/pycqa/flake8
59-
rev: 3.9.2
58+
- repo: https://github.com/pycqa/flake8
59+
rev: 6.0.0
6060
hooks:
6161
- id: flake8
6262
additional_dependencies: [flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-string-format]
6363
- repo: https://github.com/myint/autoflake
64-
rev: v1.7.1
64+
rev: v2.0.0
6565
hooks:
6666
- id: autoflake
6767
args: [--in-place, --remove-all-unused-imports, --remove-unused-variable, --ignore-init-module-imports]
@@ -77,7 +77,7 @@ repos:
7777
- id: blacken-docs
7878
additional_dependencies: [black==22.10.0]
7979
- repo: https://github.com/asottile/pyupgrade
80-
rev: v3.0.0
80+
rev: v3.3.1
8181
hooks:
8282
- id: pyupgrade
8383
args: [--py3-plus, --py37-plus]
@@ -91,6 +91,6 @@ repos:
9191
- id: rst-directive-colons
9292
- id: rst-inline-touching-normal
9393
- repo: https://github.com/PyCQA/doc8
94-
rev: v1.0.0
94+
rev: v1.1.1
9595
hooks:
9696
- id: doc8

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
:target: https://doi.org/10.5281/zenodo.6914001
1717
:alt: Zenodo
1818

19-
.. |CI| image:: https://img.shields.io/github/workflow/status/msmdev/pygpcca/CI/main
19+
.. |CI| image:: https://img.shields.io/github/actions/workflow/status/msmdev/pygpcca/ci.yml?branch=main
2020
:target: https://github.com/msmdev/pygpcca/actions
2121
:alt: CI
2222

docs/source/spelling_wordlist.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ Röblitz
2626
Sikorski
2727
Zuse
2828
mypy
29+
numpy
30+
Zenodo
31+
Konstantin
32+
pre
33+
intersphinx

pygpcca/_sorted_schur.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@
4343
import numpy as np
4444

4545
from pygpcca.utils._docs import d
46+
from pygpcca.utils._checks import assert_petsc_real_scalar_type
4647
from pygpcca._sort_real_schur import sort_real_schur
4748
from pygpcca.utils._constants import EPS, DEFAULT_SCHUR_METHOD, NO_PETSC_SLEPC_FOUND_MSG
4849

4950
try:
5051
import petsc4py
5152
import slepc4py
52-
except ImportError:
53-
petsc4py = None
54-
slepc4py = None
53+
54+
assert_petsc_real_scalar_type()
55+
except (ImportError, TypeError):
56+
petsc4py = slepc4py = None
5557

5658
__all__ = ["sorted_schur"]
5759

pygpcca/utils/_checks.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Tuple, Union, Optional
2+
import logging
23

34
from scipy.sparse import issparse, spmatrix
45
import numpy as np
56

67
from pygpcca.utils._docs import d
78

8-
__all__ = ["ensure_ndarray_or_sparse"]
9+
__all__ = ["ensure_ndarray_or_sparse", "assert_petsc_real_scalar_type"]
910

1011

1112
@d.get_sections(base="assert_array", sections=["Parameters"])
@@ -122,3 +123,23 @@ def ensure_ndarray_or_sparse(
122123
assert_array(A, shape=shape, uniform=uniform, ndim=ndim, size=size, dtype=dtype, kind=kind)
123124

124125
return A
126+
127+
128+
def assert_petsc_real_scalar_type() -> None:
129+
"""Check if PETSc was compiled using `–with-scalar-type=real`."""
130+
try:
131+
from petsc4py import PETSc
132+
133+
if np.isrealobj(PETSc.ScalarType()):
134+
return
135+
else:
136+
raise TypeError(
137+
"PETSc was compiled with complex scalar type. "
138+
"Please recompile PETSc with `--with-scalar-type=real` or "
139+
"provide alternative `PETSC_ARCH=...` with correct scalar type."
140+
)
141+
except Exception as e:
142+
logging.error(
143+
f"Unable to determine PETSc's scalar type. Reason: `{e}`. Assuming true, " # noqa: G004
144+
f"but please ensure that PETSc was compiled using `--with-scalar-type=real`.",
145+
)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ deps =
114114
slepc: petsc4py==3.18.0
115115
slepc: slepc==3.18.0
116116
slepc: slepc4py==3.18.0
117-
passenv = TOXENV CI CODECOV_* GITHUB_ACTIONS PETSC_* SLEPC_*
117+
passenv = TOXENV,CI,CODECOV_*,GITHUB_ACTIONS,PETSC_*,SLEPC_*
118118
usedevelop = true
119119
commands = python -m pytest --cov --cov-append --cov-report=term-missing --cov-config={toxinidir}/tox.ini --ignore docs/ {posargs:-vv}
120120

0 commit comments

Comments
 (0)