Skip to content

Commit

Permalink
Fix using .A instead of .toarray() (#61)
Browse files Browse the repository at this point in the history
* Fix using `.A` instead of `.toarray()`

* Fix typos

* Fix class template in the docs

* Use BLAS/LAPACK from conda

* Update GA's versions

* Update pre-commits

* Fix `pyproject.toml`

* Switch to `myst-nb`

* Use amsmath

* Remove `enviroment.yaml`

* Drop `tox-conda`

* Use conda in CI

* Remove `tox` from CI

* Don't skip on `mpi4py`

* Install petsc/slepc

* Specify correct shell

* Change env name

* Fix conda CI

* Update codecov action

* Update coverage

* Add codecov token to CI
  • Loading branch information
michalk8 authored Dec 2, 2024
1 parent 0ce99c3 commit 773c463
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 103 deletions.
29 changes: 18 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,36 @@ jobs:
slepc: 'slepc'

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Conda
uses: conda-incubator/setup-[email protected]
with:
python-version: ${{ matrix.python }}
auto-update-conda: true
channels: conda-forge,defaults

- name: Install pip dependencies
shell: bash -el {0}
run: |
python -m pip install --upgrade pip
pip install tox codecov
pip install '.[test]'
- name: Install conda dependencies
if: ${{ matrix.slepc == 'slepc' }}
shell: bash -el {0}
run: |
conda install petsc slepc petsc4py slepc4py mpi4py
- name: Test
shell: bash -el {0}
run: |
tox -e py${{ matrix.python }}-${{ matrix.slepc }} -vv
env:
PLATFORM: ${{ matrix.os }}
python -m pytest --cov --cov-config=tox.ini --no-cov-on-fail --cov-report=xml --cov-report=term-missing:skip-covered -vv
- name: Upload coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
files: ./coverage.xml
flags: unittests
name: ${{ matrix.os }}-${{ matrix.python }}-${{ matrix.slepc }}
env_vars: OS,PYTHON
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Cache pre-commit
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ env.pythonLocation }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand Down
25 changes: 12 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,41 @@ default_language_version:
default_stages:
- commit
- push
minimum_pre_commit_version: 2.9.0
minimum_pre_commit_version: 3.0.0
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies: [numpy>=1.20.0, scipy>=1.6.0]
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.10.0
hooks:
- id: black
additional_dependencies: [toml]
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
additional_dependencies: [toml]
args: [--order-by-type]
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
rev: v1.5.0
hooks:
- id: yesqa
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]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.9.0
rev: v2.14.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '4', --preserve-quotes]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: detect-private-key
- id: check-merge-conflict
- id: check-ast
- id: check-symlinks
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: fix-encoding-pragma
args: [--remove]
Expand All @@ -56,12 +55,12 @@ repos:
- id: check-toml
- id: requirements-txt-fixer
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 7.1.1
hooks:
- id: flake8
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]
- repo: https://github.com/myint/autoflake
rev: v2.1.1
rev: v2.3.1
hooks:
- id: autoflake
args: [--in-place, --remove-all-unused-imports, --remove-unused-variable, --ignore-init-module-imports]
Expand All @@ -72,12 +71,12 @@ repos:
name: Check executable files use .sh extension
types: [shell, executable]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies: [black==23.1.0]
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py3-plus, --py37-plus]
Expand All @@ -91,6 +90,6 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/PyCQA/doc8
rev: v1.1.1
rev: v1.1.2
hooks:
- id: doc8
8 changes: 3 additions & 5 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
-r ../requirements.txt
nbsphinx>=0.8
sphinx>=5
sphinx-autodoc-annotation
sphinx-autodoc-typehints>=1.10.3
myst-nb
sphinx>=8
sphinx-copybutton
sphinx_last_updated_by_git
sphinx_autodoc_typehints
sphinx_rtd_theme
sphinxcontrib-spelling
48 changes: 23 additions & 25 deletions docs/source/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
:github_url: {{ fullname }}

{{ fullname | escape | underline}}
{{ fullname | escape | underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
{% block methods %}
{%- if methods %}
.. rubric:: {{ _('Methods') }}

{% block methods %}
{% if methods %}
.. rubric:: Methods
.. autosummary::
:toctree: .
{% for item in methods %}
{%- if item not in ['__init__', 'tree_flatten', 'tree_unflatten', 'bind', 'tabulate', 'module_paths'] %}
~{{ name }}.{{ item }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endblock %}
{% block attributes %}
{%- if attributes %}
.. rubric:: {{ _('Attributes') }}

.. autosummary::
:toctree: .
{% for item in methods %}
{%- if item != '__init__' %}
~{{ fullname }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: Attributes

.. autosummary::
:toctree: .
{% for item in attributes %}
~{{ fullname }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
.. autosummary::
:toctree: .
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{%- endif %}
{% endblock %}
29 changes: 11 additions & 18 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"sphinx_autodoc_typehints",
"sphinx_copybutton",
"typed_returns",
"nbsphinx",
"myst_nb",
]
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
Expand All @@ -63,7 +63,7 @@
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["build", "**.ipynb_checkpoints"]

source_suffix = ".rst"
source_suffix = {".rst": "restructuredtext", ".ipynb": "myst-nb"}
add_function_parentheses = True

# -- Options for HTML output -------------------------------------------------
Expand All @@ -86,29 +86,21 @@
napoleon_use_admonition_for_references = False
todo_include_todos = False

# binder
nbsphinx_highlight_language = "python3"
nbsphinx_execute_arguments = [
"--InlineBackend.figure_formats={'png', 'pdf'}", # correct figure resize
"--InlineBackend.rc={'figure.dpi': 96}",
# myst-nb
myst_heading_anchors = 2
nb_execution_mode = "off"
nb_mime_priority_overrides = [("spelling", "text/plain", 0)]
myst_enable_extensions = [
"colon_fence",
"amsmath",
"dollarmath",
]
nbsphinx_prolog = r"""
{% set docname = 'docs/source/' + env.doc2path(env.docname, base=None) %}
.. raw:: html
<div class="note">
Interactive version
<a href="https://mybinder.org/v2/gh/msmdev/pygpcca/{{ env.config.release|e }}?filepath={{ docname|e }}"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg" style="vertical-align:text-bottom">
</a>
</div>
""" # noqa: E501

# spelling
spelling_lang = "en_US"
spelling_warning = True
spelling_word_list_filename = "spelling_wordlist.txt"
spelling_add_pypi_package_names = True
spelling_show_suggestions = True
# see: https://pyenchant.github.io/pyenchant/api/enchant.tokenize.html
spelling_filters = ["enchant.tokenize.URLFilter", "enchant.tokenize.EmailFilter"]

Expand All @@ -119,6 +111,7 @@
"https://pubs.acs.org/doi/abs/10.1021/acs.jctc.8b00079",
"https://doi.org/10.1063/1.5064530",
]
linkcheck_report_timeouts_as_broken = False

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
6 changes: 0 additions & 6 deletions environment.yml

This file was deleted.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[build-system]
requires = ['setuptools', 'setuptools_scm', 'wheel']
build-backend = 'setuptools.build_meta'
requires = ["setuptools>=61", "setuptools-scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

[tool.black]
line-length = 120
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"slepc4py>=3.18.0",
],
dev=["pre-commit>=2.9.0", "bump2version"],
test=["tox>=3.20.1"],
test=["pytest", "pytest-cov", "pytest-mock", "codecov"],
docs=[
line.strip()
for line in (Path("docs") / "requirements.txt").read_text("utf-8").splitlines()
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def bdc(q: np.ndarray, p: np.ndarray, sparse: bool = True) -> Tuple[np.ndarray,
mu[0] = 1.0
mu[1:] = np.cumprod(p[:-1] / q[1:])

return (P if sparse else P.A), mu / np.sum(mu)
return (P if sparse else P.toarray()), mu / np.sum(mu)


def mu(mu: int):
Expand Down Expand Up @@ -98,7 +98,6 @@ def _session_setup():

def _skip_if_no_petsc_slepc() -> bool:
try:
import mpi4py # noqa: F401
import petsc4py # noqa: F401
import slepc4py # noqa: F401

Expand Down
9 changes: 3 additions & 6 deletions tests/test_gpcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import pytest

from scipy.linalg import lu, pinv, eigvals, hilbert, subspace_angles
from scipy.linalg import lu, pinv, hilbert, subspace_angles
from scipy.sparse import issparse, csr_matrix
import numpy as np

Expand Down Expand Up @@ -543,8 +543,8 @@ def sort_evals(e: np.ndarray, take: int = 4) -> np.ndarray:
)
assert_allclose(EA, 1.0, atol=5)

l1 = sort_evals(eigvals(R_i))
l2 = sort_evals(eigvals(RR))
l1 = sort_evals(np.linalg.eigvals(R_i))
l2 = sort_evals(np.linalg.eigvals(RR))

EL = np.true_divide(np.abs(l1 - l2), eps * np.abs(l1))
assert_allclose(EL, 1.0, atol=5)
Expand Down Expand Up @@ -792,7 +792,6 @@ class TestCustom:
@pytest.mark.parametrize("method", ["krylov", "brandts"])
def test_P_i(self, P_i: np.ndarray, method: str):
if method == "krylov":
pytest.importorskip("mpi4py")
pytest.importorskip("petsc4py")
pytest.importorskip("slepc4py")

Expand Down Expand Up @@ -827,7 +826,6 @@ def test_P_2_LM(
method: str,
):
if method == "krylov":
pytest.importorskip("mpi4py")
pytest.importorskip("petsc4py")
pytest.importorskip("slepc4py")

Expand Down Expand Up @@ -912,7 +910,6 @@ def test_P_2_LR(
method: str,
):
if method == "krylov":
pytest.importorskip("mpi4py")
pytest.importorskip("petsc4py")
pytest.importorskip("slepc4py")

Expand Down
Loading

0 comments on commit 773c463

Please sign in to comment.