Skip to content
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

[EXTENDED] PR 26 Parallelized multiple right-hand side support, fully typed tools #27

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
96f67f6
pkg: made `.venv` in `.gitignore` more general
MothNik May 25, 2024
3deb05c
wip: [11] refactored algorithm 1 to handle multiple right-hand sides
MothNik Jun 7, 2024
328d9c9
feat: [11] added doctest runs to `pytest`
MothNik Jun 7, 2024
90bdeb1
tests: [11] replaced single tools test by scalable parametrized tools…
MothNik Jun 7, 2024
5080641
tests: [11] removed version from coverage
MothNik Jun 7, 2024
2f57609
lint: [11] fixed block comment lint error
MothNik Jun 7, 2024
8db6ba4
style: [11] improved headlines
MothNik Jun 8, 2024
1cdd525
wip: [11] formatted
MothNik Jun 8, 2024
ae656cf
test: [11] created conditioned banded matrix creator for testing purp…
MothNik Jun 8, 2024
26752f2
tests: [11] add doctested reference solver; made ill-conditioning mor…
MothNik Jun 8, 2024
a0c8849
feat: [11] made error messages informative
MothNik Jun 8, 2024
ee6943a
fix: [23] disabled cdivision to fix error handling on Python side
MothNik Jun 8, 2024
0284843
feat/refactor: [11] enabled multipe right-hand sides for solver I; im…
MothNik Jun 8, 2024
c32bec2
tests: [11] added shape check to doctest
MothNik Jun 8, 2024
e7d92c8
tests: [11] added extensive parametrized tests for solver I that also…
MothNik Jun 8, 2024
647012f
tests: [11] added more intermediate sizes for tests
MothNik Jun 8, 2024
8ab514f
feat/fix: [11] added cython annotations to build process; fixed wrong…
MothNik Jun 8, 2024
5086959
refactor/doc: fixed missing variable declarations; added clarifying c…
MothNik Jun 8, 2024
f062b88
style: [11] made - signs better readable
MothNik Jun 8, 2024
15c787e
doc/refactor: [11] improved docs and comments of algorithm I; removed…
MothNik Jun 8, 2024
ef7ec51
wip: [11] restructured chaotic alias comparisons
MothNik Jun 8, 2024
94d110c
feat: [11] finalized multiple right-hand side support (serial) on Cyt…
MothNik Jun 8, 2024
ba5945f
tests: [11] unified test for both pentapy algorithms, made tests a lo…
MothNik Jun 8, 2024
026e8ea
tests: [11] removed superficial unittest
MothNik Jun 8, 2024
f6fa4cb
misc: [11] fixed typos
MothNik Jun 8, 2024
9b3e122
style/refactor: [11] made core code readable to humans and not only a…
MothNik Jun 8, 2024
92abbbd
feat/refactor: [11] ensured all solvers behave the same in terms of o…
MothNik Jun 8, 2024
fb0cf2a
fix: [11] fixed coverage typo
MothNik Jun 8, 2024
c2e8032
lint: [11] linted cython files
MothNik Jun 8, 2024
b4190f8
package: [11] made requirements file-based and dynamic to make facili…
MothNik Jun 8, 2024
4c1e3a0
feat: [11] updated chagelog
MothNik Jun 8, 2024
b4f79e5
fix: [11] fixed wrong coverage exclude
MothNik Jun 8, 2024
a2edcb4
doc: [11] improved wording for preserving shape
MothNik Jun 8, 2024
007bc5a
fix: [11] fixed changelog
MothNik Jun 8, 2024
997d372
feat: [11] enable multi-threaded parallelism for multiple right-hand …
MothNik Jun 9, 2024
0cf9890
tests: [11] renamed tests for serial mode
MothNik Jun 9, 2024
9040bb7
test: [11] reduced load on tests; transitioned to template-based appr…
MothNik Jun 9, 2024
a0b3388
doc/style: [11] fully typed `tools`; improved documentation
MothNik Jun 9, 2024
b93102b
package: [11] included build information for parallelized solvers
MothNik Jun 9, 2024
3b015dc
tests: [11] finalised parallel solver tests
MothNik Jun 9, 2024
5e86a34
tests/fix: [11] fixed inter-os-incompatibility of doctests
MothNik Jun 9, 2024
712b0c7
test/fix: [11] ? really fixed the inter-os-problems ?
MothNik Jun 9, 2024
6fd57d4
feat: [11] updated changelog
MothNik Jun 9, 2024
88e30e6
fix/doc: [11] reverted change that caused overwrite of `mat`; added a…
MothNik Jun 9, 2024
b4ce4a2
docs: [11] removed doubled defaults from docstrings
MothNik Jun 9, 2024
e71ff9d
docs: [11] fixed docstring and spelling inconsistencies
MothNik Jun 9, 2024
aef7d0f
feat: [11] enabled future possible validation of the quality of the s…
MothNik Jun 10, 2024
86ebf88
refactor: [11] made internal `workers`-handling safer
MothNik Jun 10, 2024
b5f8b95
docs: [11] updated outdated `README`
MothNik Jun 10, 2024
87264d7
refactor: [11] removed `validate` and leveraged `info`; reduced test …
MothNik Jun 10, 2024
8db881f
doc: [11] updated outdated index
MothNik Jun 10, 2024
37c2fbc
refactor: [11] made Cython structure smarter for algorithm I
MothNik Jun 11, 2024
896b1cc
wip: [11] made use of Enums for checks; prepared for unifying solver …
MothNik Jun 11, 2024
2a6daf4
refactor/tests: [11] fully unified Cython implementations of the solv…
MothNik Jun 11, 2024
549422d
refactor/tests: [11] split up cluttered ptrans-solving into dedicated…
MothNik Jun 11, 2024
a31fe71
fix: [11] fixed broken coverage of unknown error (was not skipped by …
MothNik Jun 11, 2024
ac5759b
refactor: [11] made mu occupy the central column of the factorized ma…
MothNik Jun 12, 2024
0945501
fix:
MothNik Jul 21, 2024
d1433f9
refactor:
MothNik Jul 23, 2024
edb4f33
refactor:
MothNik Jul 23, 2024
5b42428
doc:
MothNik Jul 23, 2024
743549b
refactor:
MothNik Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ celerybeat-schedule
.env

# virtualenv
.venv
.venv*
venv/
ENV/

Expand Down
60 changes: 51 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,146 @@

All notable changes to **pentapy** will be documented in this file.

## [2.0.0] - 2024-06

See [#27](https://github.com/GeoStat-Framework/pentapy/pull/27)

### Breaking Changes

- fully parallelized the Cython implementation of PTRANS-I and PTRANS-II for single and multiple right-hand sides support that can now be enabled via the new `num_threads` parameter in `pentapy.solve` (default: 1)
- updated the **Cython low level interfaces** to PTRANS-I and PTRANS-II to **only accept C-contiguous arrays** (not backwards compatible)
MothNik marked this conversation as resolved.
Show resolved Hide resolved

### Enhancements

- improved error handling and added debug information to error messages

### Changes

- refactored and documented the Cython implementation of PTRANS-I and PTRANS-II for single and multiple right-hand sides support
- fully typed the `pentapy.tools` module and the function ``pentapy.solve`
- made internal solver alias handling of `pentapy.solve` smarter, more robust, and removed all duplicate code
- gave all solvers a consistent interface
- made code in ``pentapy.core` `more maintainable
- fixed typos in documentation

### Bugfixes

- fixed error handling in case of zero-division to trigger dead error handling branch (see [Issue 23](https://github.com/GeoStat-Framework/pentapy/issues/23))
- fixed edge case error for row/column count of 3 (see [Issue 24](https://github.com/GeoStat-Framework/pentapy/issues/24))

### Tests

- transitioned from `unittest`-based testing to fully `pytest`-based testing with parametrized and parallelized exhaustive testing (see [Issue 25](https://github.com/GeoStat-Framework/pentapy/issues/25))
- made actual tests more meaningful by comparing them to LAPACK as reference standard (see [Issue 25](https://github.com/GeoStat-Framework/pentapy/issues/25))
- included external solver bindings accessible via `pentapy.solve` as part of the test suite
- increased true coverage (not line-hit coverage) close to 100%

## [1.3.0] - 2024-04

See [#21](https://github.com/GeoStat-Framework/pentapy/pull/21)

### Enhancements

- added support for python 3.12
- added support for numpy 2
- build extensions with numpy 2 and cython 3

### Changes

- dropped python 3.7 support
- dropped 32bit builds
- linted cython files
- increase maximal line length to 88 (black default)


## [1.2.0] - 2023-04

See [#19](https://github.com/GeoStat-Framework/pentapy/pull/19)

### Enhancements

- added support for python 3.10 and 3.11
- add wheels for arm64 systems
- created `solver.pxd` file to be able to cimport the solver module
- added a `CITATION.bib` file

### Changes

- move to `src/` based package structure
- dropped python 3.6 support
- move meta-data to pyproject.toml
- simplified documentation

### Bugfixes

- determine correct version when installing from archive

## [1.1.2] - 2021-07

### Changes

- new package structure with `pyproject.toml` ([#15](https://github.com/GeoStat-Framework/pentapy/pull/15))
- Sphinx-Gallery for Examples
- Repository restructuring: use a single `main` branch
- use `np.asarray` in `solve` to speed up computation ([#17](https://github.com/GeoStat-Framework/pentapy/pull/17))


## [1.1.1] - 2021-02

### Enhancements

- Python 3.9 support

### Changes
- GitHub Actions for CI

- GitHub Actions for CI

## [1.1.0] - 2020-03-22

### Enhancements

- Python 3.8 support

### Changes

- python only builds are no longer available
- Python 2.7 and 3.4 support dropped


## [1.0.3] - 2019-11-10

### Enhancements

- the algorithms `PTRANS-I` and `PTRANS-II` now raise a warning when they can not solve the given system
- there are now switches to install scipy and umf solvers as extra requirements

### Bugfixes
- multiple minor bugfixes

- multiple minor bugfixes

## [1.0.0] - 2019-09-18

### Enhancements
- the second algorithm `PTRANS-II` from *Askar et al. 2015* is now implemented and can be used by `solver=2`

- the second algorithm `PTRANS-II` from _Askar et al. 2015_ is now implemented and can be used by `solver=2`
- the package is now tested and a coverage is calculated
- there are now pre-built binaries for Python 3.7
- the documentation is now available under https://geostat-framework.readthedocs.io/projects/pentapy

### Changes
- pentapy is now licensed under the MIT license

- pentapy is now licensed under the MIT license

## [0.1.1] - 2019-03-08

### Bugfixes
- MANIFEST.in was missing in the 0.1.0 version

- MANIFEST.in was missing in the 0.1.0 version

## [0.1.0] - 2019-03-07

This is the first release of pentapy, a python toolbox for solving pentadiagonal linear equation systems.
The solver is implemented in cython, which makes it really fast.


[2.0.0]: https://github.com/GeoStat-Framework/pentapy/compare/v1.4.0...v2.0.0
[1.4.0]: https://github.com/GeoStat-Framework/pentapy/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/GeoStat-Framework/pentapy/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/GeoStat-Framework/pentapy/compare/v1.1.2...v1.2.0
[1.1.2]: https://github.com/GeoStat-Framework/pentapy/compare/v1.1.1...v1.1.2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Have a look at the script: [``examples/03_perform_simple.py``](https://github.co

## Requirements:

- [NumPy >= 1.14.5](https://www.numpy.org)
- [NumPy >= 1.20.0](https://www.numpy.org)

### Optional

Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The performance plot was created with ``perfplot`` (`link <https://github.com/ns
Requirements
============

- `Numpy >= 1.14.5 <http://www.numpy.org>`_
- `Numpy >= 1.20.0 <http://www.numpy.org>`_

Optional
--------
Expand Down
4 changes: 2 additions & 2 deletions examples/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ If M is a full matrix, you call the following:

X = pp.solve(M, Y)

If M is flattend in row-wise order you have to set the keyword argument ``is_flat=True``:
If M is flattened in row-wise order you have to set the keyword argument ``is_flat=True``:

.. code-block:: python

Expand All @@ -99,7 +99,7 @@ If M is flattend in row-wise order you have to set the keyword argument ``is_fla

X = pp.solve(M, Y, is_flat=True)

If you got a col-wise flattend matrix you have to set ``index_row_wise=False``:
If you got a col-wise flattened matrix you have to set ``index_row_wise=False``:

.. code-block:: python

Expand Down
6 changes: 3 additions & 3 deletions paper/paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ $$

Here, $d_i$ are the diagonal entries and $d_i^{(j)}$ represent the $j$-th minor diagonal.

Recently, @askar presented two algorithms to
solve the linear systems of equations for $X$, ``PTRANS-I`` and ``PTRANS-II``,
Recently, @askar presented two algorithms to
solve the linear systems of equations for $X$, ``PTRANS-I`` and ``PTRANS-II``,
applying first transformation to a triangular matrix and then, respectively, backward and forward substitution.
``pentapy`` provides Cython [@cython] implementations of these
algorithms and a set of tools to convert matrices to row-wise or
Expand All @@ -73,7 +73,7 @@ The linear algebra solver of NumPy [@numpy] served as a standard reference, whic
``pentapy`` is designed to provide a fast solver for the special case of a
pentadiagonal linear system. To the best of the author's knowledge,
this package outperforms the current algorithms for solving pentadiagonal systems in Python.
The solver can handle different input formats of the coefficient matrix, i.e., a flattend matrix or a
The solver can handle different input formats of the coefficient matrix, i.e., a flattened matrix or a
quadratic matrix.


Expand Down
30 changes: 20 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ requires = [
"setuptools_scm>=7",
"numpy>=2.0.0rc1,<2.3; python_version >= '3.9'",
"oldest-supported-numpy; python_version < '3.9'",
"extension-helpers>=1",
"Cython>=3.0.10,<3.1.0",
]
build-backend = "setuptools.build_meta"
Expand Down Expand Up @@ -35,15 +36,14 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Topic :: Utilities",
]
dependencies = ["numpy>=1.20.0"]
dependencies = [
"numpy>=1.20.0",
]

[project.optional-dependencies]
scipy = ["scipy"]
umfpack = ["scikit-umfpack"]
all = [
"scipy",
"scikit-umfpack",
]
all = ["scipy", "scikit-umfpack"]
doc = [
"m2r2>=0.2.8",
"scipy>=1.1.0",
Expand All @@ -54,12 +54,17 @@ doc = [
"sphinx-gallery>=0.8",
"sphinx-rtd-theme>=2",
]
test = ["pytest-cov>=3"]
test = [
"pytest>=8",
"pytest-cov>=3",
"pytest-xdist>=3",
"scipy>=1.1.0",
]
check = [
"black>=24,<25",
"isort[colors]",
"pylint",
"cython-lint",
"black>=24,<25",
"isort[colors]",
"pylint",
"cython-lint",
]

[project.urls]
Expand Down Expand Up @@ -103,6 +108,8 @@ max-line-length = 120
"*examples*",
"*tests*",
"*paper*",
"src/pentapy/_version.py",
"src/pentapy/__init__.py",
]

[tool.coverage.report]
Expand Down Expand Up @@ -136,6 +143,9 @@ max-line-length = 120
max-attributes = 25
max-public-methods = 75

[tool.pytest.ini_options]
addopts = "--doctest-modules"

[tool.cibuildwheel]
# Switch to using build
build-frontend = "build"
Expand Down
41 changes: 38 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,58 @@
"""pentapy: A toolbox for pentadiagonal matrizes."""
"""pentapy: A toolbox for pentadiagonal matrices."""

# === Imports ===

import os

import numpy as np
from Cython.Build import cythonize
from extension_helpers import add_openmp_flags_if_available
from setuptools import Extension, setup

# === Constants ===

# the environment variable key for the build of the serial/parallel version
PENTAPY_BUILD_PARALLEL = "PENTAPY_BUILD_PARALLEL"
# the compiler flags for the OpenMP parallelization
OPENMP = "OPENMP"
# the number of threads for the Cython build
CYTHON_BUILD_NUM_THREADS = 1

# === Setup ===

# cython extensions
CY_MODULES = [
Extension(
name=f"pentapy.solver",
name="pentapy.solver",
sources=[os.path.join("src", "pentapy", "solver.pyx")],
include_dirs=[np.get_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]

# the OpenMP link is added if available/requested
# the environment variables can be PENTAPY_BUILD_PARALLEL = 0 (builds serial version) or
# PENTAPY_BUILD_PARALLEL != 0 (builds parallel version)
with_open_mp = False
if int(os.environ.get(PENTAPY_BUILD_PARALLEL, "0")):
openmp_added = [add_openmp_flags_if_available(mod) for mod in CY_MODULES]
with_open_mp = any(openmp_added)
if with_open_mp:
open_mp_str = "linking OpenMP (parallel version)"
else:
open_mp_str = "not linking OpenMP (serial version)"

print(f"PENTAPY SETUP - {open_mp_str}")

else:
print("PENTAPY SETUP - OpenMP not requested (serial version)")

setup(
ext_modules=cythonize(CY_MODULES),
ext_modules=cythonize(
CY_MODULES,
nthreads=CYTHON_BUILD_NUM_THREADS,
compile_time_env={OPENMP: with_open_mp},
),
package_data={"pentapy": ["*.pxd"]}, # include pxd files
include_package_data=False, # ignore other files
zip_safe=False,
Expand Down
2 changes: 2 additions & 0 deletions src/pentapy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Cython html files
*.html
2 changes: 1 addition & 1 deletion src/pentapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

try:
from pentapy._version import __version__
except ImportError: # pragma: nocover
except ImportError: # pragma: no cover
MothNik marked this conversation as resolved.
Show resolved Hide resolved
# package is not installed
__version__ = "0.0.0.dev0"

Expand Down
Loading