py-mkl-pardiso 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_mkl_pardiso-0.0.0/LICENSE +21 -0
- py_mkl_pardiso-0.0.0/PKG-INFO +23 -0
- py_mkl_pardiso-0.0.0/README.md +138 -0
- py_mkl_pardiso-0.0.0/py-mkl-pardiso.cpp +775 -0
- py_mkl_pardiso-0.0.0/py_mkl_pardiso.egg-info/PKG-INFO +23 -0
- py_mkl_pardiso-0.0.0/py_mkl_pardiso.egg-info/SOURCES.txt +13 -0
- py_mkl_pardiso-0.0.0/py_mkl_pardiso.egg-info/dependency_links.txt +1 -0
- py_mkl_pardiso-0.0.0/py_mkl_pardiso.egg-info/requires.txt +5 -0
- py_mkl_pardiso-0.0.0/py_mkl_pardiso.egg-info/top_level.txt +1 -0
- py_mkl_pardiso-0.0.0/pymklpardiso/__init__.py +140 -0
- py_mkl_pardiso-0.0.0/pyproject.toml +38 -0
- py_mkl_pardiso-0.0.0/setup.cfg +4 -0
- py_mkl_pardiso-0.0.0/setup.py +111 -0
- py_mkl_pardiso-0.0.0/tests/test_pardiso.py +1540 -0
- py_mkl_pardiso-0.0.0/tests/test_wrapper.py +422 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Brendan O'Donoghue
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-mkl-pardiso
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Python pybind11 wrapper for Intel oneMKL PARDISO sparse direct solver
|
|
5
|
+
Author: Brendan O'Donoghue
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: C++
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: pytest; extra == "test"
|
|
22
|
+
Requires-Dist: scipy; extra == "test"
|
|
23
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# py-mkl-pardiso
|
|
2
|
+
|
|
3
|
+
[](https://github.com/bodono/py-mkl-pardiso/actions/workflows/test.yml)
|
|
4
|
+
|
|
5
|
+
Python pybind11 wrapper for the Intel oneMKL PARDISO sparse direct solver.
|
|
6
|
+
|
|
7
|
+
`pymklpardiso` exposes the real-valued subset of Intel's
|
|
8
|
+
[PARDISO](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2025-0/onemkl-pardiso-parallel-direct-sparse-solver-iface.html)
|
|
9
|
+
sparse direct solver to Python via [pybind11](https://github.com/pybind/pybind11).
|
|
10
|
+
It works with SciPy sparse matrices in CSR format and NumPy arrays.
|
|
11
|
+
|
|
12
|
+
**Supported platforms:** Linux (x86_64), Windows (AMD64).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install py-mkl-pardiso
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or install from source (requires MKL):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/bodono/py-mkl-pardiso.git
|
|
24
|
+
cd py-mkl-pardiso
|
|
25
|
+
pip install -e ".[test]"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Building from source requires:
|
|
29
|
+
- Intel oneMKL (set `MKLROOT` if not auto-detected)
|
|
30
|
+
- A C++17 compiler
|
|
31
|
+
- Python >= 3.10
|
|
32
|
+
- pybind11 >= 2.12
|
|
33
|
+
|
|
34
|
+
## Quick start
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import numpy as np
|
|
38
|
+
import scipy.sparse as sp
|
|
39
|
+
from pymklpardiso import PardisoSolver, MTYPE_REAL_SYM_POSDEF
|
|
40
|
+
|
|
41
|
+
# Build a symmetric positive-definite matrix (upper triangle, CSR)
|
|
42
|
+
A_full = np.array([
|
|
43
|
+
[4.0, 1.0],
|
|
44
|
+
[1.0, 3.0],
|
|
45
|
+
])
|
|
46
|
+
A_upper = sp.csr_matrix(np.triu(A_full))
|
|
47
|
+
A_upper.sort_indices()
|
|
48
|
+
|
|
49
|
+
# Create solver — analyzes, factors, and is ready to solve
|
|
50
|
+
solver = PardisoSolver(A_upper, MTYPE_REAL_SYM_POSDEF)
|
|
51
|
+
|
|
52
|
+
b = np.array([1.0, 2.0])
|
|
53
|
+
x = solver.solve(b)
|
|
54
|
+
print(x) # [0.09090909 0.63636364]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Refactoring workflow
|
|
58
|
+
|
|
59
|
+
When the sparsity pattern stays the same but values change (e.g., in an
|
|
60
|
+
iterative algorithm), use `refactor()` to skip symbolic analysis:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
solver = PardisoSolver(A_upper, MTYPE_REAL_SYM_POSDEF)
|
|
64
|
+
for new_values in value_generator:
|
|
65
|
+
solver.refactor(new_values)
|
|
66
|
+
x = solver.solve(b)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## API reference
|
|
70
|
+
|
|
71
|
+
### `PardisoSolver(A, mtype, iparms=None, msglvl=0)`
|
|
72
|
+
|
|
73
|
+
Create a PARDISO solver instance. The constructor extracts the CSR sparsity
|
|
74
|
+
pattern from `A`, applies any `iparms` overrides, and runs symbolic analysis
|
|
75
|
+
+ numeric factorization so the solver is ready to call `solve()`.
|
|
76
|
+
|
|
77
|
+
| Parameter | Type | Default | Description |
|
|
78
|
+
|---|---|---|---|
|
|
79
|
+
| `A` | sparse CSR | *(required)* | Sparse matrix (any object with `indptr`, `indices`, `data`, `shape`). For symmetric types, pass only the upper triangle. |
|
|
80
|
+
| `mtype` | `int` | *(required)* | Matrix type (see constants below). |
|
|
81
|
+
| `iparms` | `dict` | `None` | Optional `{index: value}` iparm overrides. |
|
|
82
|
+
| `msglvl` | `int` | `0` | Message level (0 = silent, 1 = print statistics). |
|
|
83
|
+
|
|
84
|
+
### Matrix type constants
|
|
85
|
+
|
|
86
|
+
| Constant | Value | Description |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `MTYPE_REAL_STRUCT_SYM` | 1 | Real structurally symmetric |
|
|
89
|
+
| `MTYPE_REAL_SYM_POSDEF` | 2 | Real symmetric positive definite |
|
|
90
|
+
| `MTYPE_REAL_SYM_INDEF` | -2 | Real symmetric indefinite |
|
|
91
|
+
| `MTYPE_REAL_NONSYM` | 11 | Real nonsymmetric |
|
|
92
|
+
|
|
93
|
+
### Core methods
|
|
94
|
+
|
|
95
|
+
**`solver.solve(b)`**
|
|
96
|
+
Solve `Ax = b`. Accepts 1D `(n,)` or 2D `(n, nrhs)` arrays. Returns the
|
|
97
|
+
solution as a new NumPy array (Fortran-contiguous for 2D).
|
|
98
|
+
|
|
99
|
+
**`solver.solve_into(b, x)`**
|
|
100
|
+
Solve `Ax = b` writing into pre-allocated `x`. For 2D arrays, both `b` and
|
|
101
|
+
`x` must be Fortran-contiguous.
|
|
102
|
+
|
|
103
|
+
**`solver.refactor(values)`**
|
|
104
|
+
Re-factorize with new nonzero values (phase 22 only). Does not re-run
|
|
105
|
+
symbolic analysis. Use `factor()` to re-analyze from scratch.
|
|
106
|
+
|
|
107
|
+
**`solver.factor(values)`**
|
|
108
|
+
Re-analyze and re-factorize with new values (phases 11 + 22). Use this for
|
|
109
|
+
error recovery or when iparm changes require fresh symbolic analysis.
|
|
110
|
+
|
|
111
|
+
### Other methods
|
|
112
|
+
|
|
113
|
+
| Method | Description |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `solver.release()` | Free PARDISO internal memory. |
|
|
116
|
+
| `solver.n` | Matrix dimension (property). |
|
|
117
|
+
| `solver.nnz` | Number of nonzeros (property). |
|
|
118
|
+
| `solver.mtype` | Matrix type (property). |
|
|
119
|
+
| `solver.set_perm(perm)` | Set fill-reducing permutation. |
|
|
120
|
+
| `solver.clear_perm()` | Clear permutation. |
|
|
121
|
+
| `solver.has_perm()` | Whether a permutation is set. |
|
|
122
|
+
| `solver.set_iparm(idx, value)` | Set a single iparm entry. |
|
|
123
|
+
| `solver.get_iparm()` | Get all 64 iparm values. |
|
|
124
|
+
| `solver.get_iparm_value(idx)` | Get a single iparm value. |
|
|
125
|
+
| `solver.set_iparm_all(iparm)` | Set all 64 iparm values. |
|
|
126
|
+
| `solver.set_msglvl(msglvl)` | Change message level. |
|
|
127
|
+
| `solver.run_phase(phase)` | Run an arbitrary PARDISO phase. |
|
|
128
|
+
| `solver.run_phase_into(phase, b, x)` | Run a phase with RHS/output arrays. |
|
|
129
|
+
|
|
130
|
+
### iparm notes
|
|
131
|
+
|
|
132
|
+
- `iparm[0]` is locked to `1` (user-supplied parameters).
|
|
133
|
+
- `iparm[34]` is locked to `1` (zero-based indexing).
|
|
134
|
+
- See the [MKL PARDISO iparm documentation](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2025-0/pardiso-iparm-parameter.html) for all parameters.
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|