schurilu 0.1.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.
- schurilu-0.1.0/LICENSE +21 -0
- schurilu-0.1.0/MANIFEST.in +10 -0
- schurilu-0.1.0/PKG-INFO +276 -0
- schurilu-0.1.0/README.md +243 -0
- schurilu-0.1.0/pyproject.toml +78 -0
- schurilu-0.1.0/setup.cfg +4 -0
- schurilu-0.1.0/src/schurilu/__init__.py +37 -0
- schurilu-0.1.0/src/schurilu/krylov/__init__.py +10 -0
- schurilu-0.1.0/src/schurilu/krylov/fgmres.py +212 -0
- schurilu-0.1.0/src/schurilu/krylov/fgmrez.py +218 -0
- schurilu-0.1.0/src/schurilu/krylov/pcg.py +146 -0
- schurilu-0.1.0/src/schurilu/krylov/planczos.py +142 -0
- schurilu-0.1.0/src/schurilu/preconditioners/__init__.py +12 -0
- schurilu-0.1.0/src/schurilu/preconditioners/_base.py +325 -0
- schurilu-0.1.0/src/schurilu/preconditioners/gemslr.py +566 -0
- schurilu-0.1.0/src/schurilu/preconditioners/ilu0.py +392 -0
- schurilu-0.1.0/src/schurilu/preconditioners/iluk.py +549 -0
- schurilu-0.1.0/src/schurilu/preconditioners/ilut.py +518 -0
- schurilu-0.1.0/src/schurilu/reordering/__init__.py +20 -0
- schurilu-0.1.0/src/schurilu/reordering/spectral.py +411 -0
- schurilu-0.1.0/src/schurilu/utils/__init__.py +12 -0
- schurilu-0.1.0/src/schurilu/utils/_helpers.py +212 -0
- schurilu-0.1.0/src/schurilu.egg-info/PKG-INFO +276 -0
- schurilu-0.1.0/src/schurilu.egg-info/SOURCES.txt +32 -0
- schurilu-0.1.0/src/schurilu.egg-info/dependency_links.txt +1 -0
- schurilu-0.1.0/src/schurilu.egg-info/requires.txt +9 -0
- schurilu-0.1.0/src/schurilu.egg-info/top_level.txt +1 -0
- schurilu-0.1.0/tests/__init__.py +1 -0
- schurilu-0.1.0/tests/conftest.py +48 -0
- schurilu-0.1.0/tests/test_gemslr.py +457 -0
- schurilu-0.1.0/tests/test_ilu.py +652 -0
- schurilu-0.1.0/tests/test_krylov.py +342 -0
- schurilu-0.1.0/tests/test_reordering.py +178 -0
- schurilu-0.1.0/tests/test_utils.py +170 -0
schurilu-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tianshi Xu
|
|
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.
|
schurilu-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: schurilu
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: NumPy/SciPy ILU and Schur-complement preconditioners for fair, reproducible Krylov baselines.
|
|
5
|
+
Author-email: Tianshi Xu <txu41@emory.edu>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Hitenze/SchurILU
|
|
8
|
+
Project-URL: Repository, https://github.com/Hitenze/SchurILU
|
|
9
|
+
Project-URL: Issues, https://github.com/Hitenze/SchurILU/issues
|
|
10
|
+
Keywords: linear-algebra,sparse-matrix,ilu,preconditioner,krylov,gmres,conjugate-gradient,schur-complement
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=1.20.0
|
|
26
|
+
Requires-Dist: scipy>=1.6.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
30
|
+
Provides-Extra: examples
|
|
31
|
+
Requires-Dist: matplotlib>=3.5.0; extra == "examples"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# SchurILU
|
|
35
|
+
|
|
36
|
+
A NumPy/SciPy-based library for **incomplete LU preconditioners with explicit Schur complement support**, designed to provide a clean, reproducible ILU baseline for research in iterative solvers and learning-based preconditioning.
|
|
37
|
+
|
|
38
|
+
## Overview
|
|
39
|
+
|
|
40
|
+
SchurILU focuses on:
|
|
41
|
+
|
|
42
|
+
- Well-defined **ILU(0) / ILU(k) / ILUT** implementations
|
|
43
|
+
- **Partial / two-level ILU** on block-partitioned systems
|
|
44
|
+
- **GeMSLR**: General Multilevel Schur Low-Rank preconditioner
|
|
45
|
+
- Work with SciPy's Krylov solvers
|
|
46
|
+
|
|
47
|
+
This library is intended as a transparent, research-friendly reference implementation in pure Python. It is not designed to compete with production C/C++ libraries such as hypre or parGeMSLR, but rather to offer an accessible platform for algorithmic experimentation and prototyping.
|
|
48
|
+
|
|
49
|
+
> **Status: Alpha (v0.1.x)**
|
|
50
|
+
>
|
|
51
|
+
> This is early-stage research code. APIs may change between minor versions.
|
|
52
|
+
> Tested primarily on real SPD and general non-singular matrices.
|
|
53
|
+
> Bug reports and PRs are welcome -- see [Issues](https://github.com/Hitenze/SchurILU/issues).
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install schurilu
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or install from source:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/Hitenze/SchurILU.git
|
|
65
|
+
cd SchurILU
|
|
66
|
+
pip install -e .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For development (includes pytest):
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install -e ".[dev]"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Features
|
|
76
|
+
|
|
77
|
+
### ILU Factorizations
|
|
78
|
+
|
|
79
|
+
- **ilu0**: ILU(0) with no fill-in
|
|
80
|
+
- **iluk**: ILU(k) with level-based fill
|
|
81
|
+
- **ilut**: ILUT with threshold-based dropping
|
|
82
|
+
|
|
83
|
+
All factorizations support:
|
|
84
|
+
- Schur complement computation (partial factorization)
|
|
85
|
+
- float32, float64, complex64, complex128
|
|
86
|
+
- CSR sparse matrix input
|
|
87
|
+
|
|
88
|
+
### GeMSLR Preconditioner
|
|
89
|
+
|
|
90
|
+
- **GeMSLR**: General Multilevel Schur Low-Rank preconditioner
|
|
91
|
+
- Multilevel domain decomposition via spectral graph partitioning
|
|
92
|
+
- ILU factorization on interior blocks
|
|
93
|
+
- Low-rank correction for Schur complement approximation
|
|
94
|
+
- Arnoldi-based eigenvalue computation for optimal correction
|
|
95
|
+
|
|
96
|
+
> **Note on parallelism**: The GeMSLR algorithm is designed for parallel execution -- the interior blocks at each level are independent and can be factored/solved in parallel. This pure-Python implementation is sequential; for production HPC use, see [parGeMSLR](https://github.com/Hitenze/pargemslr).
|
|
97
|
+
|
|
98
|
+
### Reordering
|
|
99
|
+
|
|
100
|
+
- **multilevel_partition**: Spectral k-way partitioning for multilevel ordering
|
|
101
|
+
- **spectral_kway**: Recursive spectral bisection using Fiedler vector
|
|
102
|
+
- **unweighted_laplacian**: Graph Laplacian construction
|
|
103
|
+
- **connected_components**: Graph connectivity analysis
|
|
104
|
+
|
|
105
|
+
> **Note**: The built-in spectral partitioner is a naive implementation for research/prototyping. For better partition quality, consider using METIS and passing a custom permutation to `GeMSLR(A, p=your_perm, lev_ptr=your_lev_ptr)`.
|
|
106
|
+
|
|
107
|
+
### Krylov Solvers
|
|
108
|
+
|
|
109
|
+
- **fgmres**: Flexible GMRES (real)
|
|
110
|
+
- **fgmrez**: Flexible GMRES (complex)
|
|
111
|
+
- **pcg**: Preconditioned Conjugate Gradient
|
|
112
|
+
- **planczos**: Preconditioned Lanczos for eigenvalue estimation
|
|
113
|
+
|
|
114
|
+
## Usage
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import numpy as np
|
|
118
|
+
from schurilu import ilu0, iluk, ilut, fgmres, pcg
|
|
119
|
+
from schurilu.utils import fd3d
|
|
120
|
+
|
|
121
|
+
# Create a 3D Laplacian matrix (10x10x10 grid)
|
|
122
|
+
A = fd3d(10, 10, 10)
|
|
123
|
+
|
|
124
|
+
# ILU factorization
|
|
125
|
+
ilu = ilu0(A)
|
|
126
|
+
|
|
127
|
+
# Solve with preconditioned GMRES
|
|
128
|
+
b = np.ones(A.shape[0])
|
|
129
|
+
x, info = fgmres(A, b, M=ilu, tol=1e-10)
|
|
130
|
+
|
|
131
|
+
# Solve with preconditioned CG (for SPD matrices)
|
|
132
|
+
x, info = pcg(A, b, M=ilu, tol=1e-10)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Schur Complement
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# Partial factorization with Schur complement
|
|
139
|
+
nB = 50 # Size of B block
|
|
140
|
+
result = ilu0(A, nB=nB)
|
|
141
|
+
|
|
142
|
+
# Access Schur complement
|
|
143
|
+
S = result.S # Schur complement matrix
|
|
144
|
+
E = result.E # Transformed lower-left block (E_orig * U_B^{-1})
|
|
145
|
+
F = result.F # Transformed upper-right block (L_B^{-1} * F_orig)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### ILU with Fill-in Control
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
# Level-based fill
|
|
152
|
+
result = iluk(A, lfil=2) # Allow fill up to level 2
|
|
153
|
+
|
|
154
|
+
# Threshold-based dropping
|
|
155
|
+
result = ilut(A, droptol=1e-4, lfil=20)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### GeMSLR Preconditioner
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from schurilu import GeMSLR, fgmres
|
|
162
|
+
|
|
163
|
+
# Create GeMSLR preconditioner with automatic spectral partitioning
|
|
164
|
+
pre = GeMSLR(A, nlev=3, k=4, droptol=1e-3, rank_k=10)
|
|
165
|
+
|
|
166
|
+
# Solve with FGMRES
|
|
167
|
+
x, info = fgmres(A, b, M=pre, tol=1e-10)
|
|
168
|
+
|
|
169
|
+
# For exact factorization (rapid convergence with full rank)
|
|
170
|
+
pre_exact = GeMSLR(A, nlev=2, k=2, droptol=0.0, rank_k=50,
|
|
171
|
+
arnoldi_tol=1e-14, arnoldi_maxiter=100)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Key parameters:
|
|
175
|
+
- `nlev`: Number of levels in the multilevel hierarchy
|
|
176
|
+
- `k`: Number of partitions per level (must be power of 2)
|
|
177
|
+
- `droptol`: Drop tolerance for ILU (0 = exact)
|
|
178
|
+
- `rank_k`: Target rank for low-rank correction
|
|
179
|
+
- `theta`: Spectrum shift parameter (default 0)
|
|
180
|
+
|
|
181
|
+
## API Reference
|
|
182
|
+
|
|
183
|
+
### ILUResult
|
|
184
|
+
|
|
185
|
+
All ILU functions return an `ILUResult` object with:
|
|
186
|
+
|
|
187
|
+
**Attributes:**
|
|
188
|
+
- `L`: Lower triangular factor (n x n sparse matrix, unit diagonal not stored)
|
|
189
|
+
- `D`: Diagonal stored as inverse (1/d_ii). For partial factorization, only `D[:nB]` is valid.
|
|
190
|
+
- `U`: Upper triangular factor (n x n sparse matrix, diagonal not stored)
|
|
191
|
+
- `E`, `F`, `S`: Schur complement parts (only present if `nB < n`). Note: `E` stores `E_orig * U_B^{-1}` and `F` stores `L_B^{-1} * F_orig`, not the original blocks.
|
|
192
|
+
- `n`: Matrix dimension
|
|
193
|
+
- `nB`: Size of B block (`nB == n` for full factorization)
|
|
194
|
+
|
|
195
|
+
**Methods:**
|
|
196
|
+
- `solve(b)`: Apply preconditioner. For partial factorization, solves only the B-block; the C-block is passed through unchanged.
|
|
197
|
+
- `to_linear_operator()`: Convert to scipy LinearOperator (n x n).
|
|
198
|
+
- `to_complete()`: Returns `(L_complete, U_complete)` with diagonals restored. Returns (nB x nB) matrices containing only the B-block factors.
|
|
199
|
+
|
|
200
|
+
### GeMSLR
|
|
201
|
+
|
|
202
|
+
The `GeMSLR` class provides a multilevel Schur low-rank preconditioner:
|
|
203
|
+
|
|
204
|
+
**Attributes:**
|
|
205
|
+
- `n`: Matrix dimension
|
|
206
|
+
- `nlev`: Number of levels in hierarchy
|
|
207
|
+
- `p`: Permutation array
|
|
208
|
+
- `lev_ptr`: Level pointers
|
|
209
|
+
|
|
210
|
+
**Methods:**
|
|
211
|
+
- `solve(b)`: Apply preconditioner
|
|
212
|
+
- `to_linear_operator()`: Convert to scipy LinearOperator
|
|
213
|
+
|
|
214
|
+
**Properties:**
|
|
215
|
+
- `nnz`: Total nonzeros in preconditioner
|
|
216
|
+
- `nnz_ilu`: Nonzeros in ILU factors
|
|
217
|
+
- `nnz_lowrank`: Nonzeros in low-rank corrections
|
|
218
|
+
- `fill_factor()`: Ratio of preconditioner nnz to original matrix nnz
|
|
219
|
+
|
|
220
|
+
### arnoldi
|
|
221
|
+
|
|
222
|
+
Low-level Arnoldi iteration for computing dominant eigenvalues:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
V, H, m, iters = arnoldi(matvec, n, neig=5, tol=1e-12, maxiter=600)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Parameters:**
|
|
229
|
+
- `matvec`: Callable for matrix-vector product
|
|
230
|
+
- `n`: Matrix dimension
|
|
231
|
+
- `neig`: Target number of eigenvalues
|
|
232
|
+
- `tol`: Convergence tolerance
|
|
233
|
+
- `maxiter`: Maximum iterations
|
|
234
|
+
|
|
235
|
+
**Returns:**
|
|
236
|
+
- `V`: Ritz vectors (n x m)
|
|
237
|
+
- `H`: Upper triangular Schur form (m x m)
|
|
238
|
+
- `m`: Number of converged eigenvalues
|
|
239
|
+
- `iters`: Total iterations performed
|
|
240
|
+
|
|
241
|
+
## Testing
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
pytest tests/ -v
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Examples
|
|
248
|
+
|
|
249
|
+
The `examples/` directory contains runnable scripts:
|
|
250
|
+
|
|
251
|
+
| Example | Description |
|
|
252
|
+
|---------|-------------|
|
|
253
|
+
| `01_ilu_basics.py` | ILU factorizations and sparsity visualization |
|
|
254
|
+
| `02_preconditioned_gmres.py` | FGMRES convergence with ILU preconditioners |
|
|
255
|
+
| `03_gemslr_preconditioner.py` | GeMSLR multilevel preconditioner comparison |
|
|
256
|
+
|
|
257
|
+
Run with:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
pip install matplotlib # for visualization
|
|
261
|
+
python examples/01_ilu_basics.py
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Related Publications
|
|
265
|
+
|
|
266
|
+
The design of SchurILU is informed by the following works:
|
|
267
|
+
|
|
268
|
+
- T. Xu, R. Li, and D. Osei-Kuffuor, "A Two-level GPU-Accelerated Incomplete LU Preconditioner for General Sparse Linear Systems," *International Journal of High Performance Computing Applications*, 39(3):424-442, 2025.
|
|
269
|
+
|
|
270
|
+
- T. Xu, V. Kalantzis, R. Li, Y. Xi, G. Dillon, and Y. Saad, "parGeMSLR: A Parallel Multilevel Schur Complement Low-Rank Preconditioning and Solution Package for General Sparse Matrices," *Parallel Computing*, 113:102956, 2022.
|
|
271
|
+
|
|
272
|
+
If you use SchurILU in academic work, please consider citing the relevant papers above. An official SchurILU citation will be provided once available.
|
|
273
|
+
|
|
274
|
+
## License
|
|
275
|
+
|
|
276
|
+
MIT License
|
schurilu-0.1.0/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# SchurILU
|
|
2
|
+
|
|
3
|
+
A NumPy/SciPy-based library for **incomplete LU preconditioners with explicit Schur complement support**, designed to provide a clean, reproducible ILU baseline for research in iterative solvers and learning-based preconditioning.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
SchurILU focuses on:
|
|
8
|
+
|
|
9
|
+
- Well-defined **ILU(0) / ILU(k) / ILUT** implementations
|
|
10
|
+
- **Partial / two-level ILU** on block-partitioned systems
|
|
11
|
+
- **GeMSLR**: General Multilevel Schur Low-Rank preconditioner
|
|
12
|
+
- Work with SciPy's Krylov solvers
|
|
13
|
+
|
|
14
|
+
This library is intended as a transparent, research-friendly reference implementation in pure Python. It is not designed to compete with production C/C++ libraries such as hypre or parGeMSLR, but rather to offer an accessible platform for algorithmic experimentation and prototyping.
|
|
15
|
+
|
|
16
|
+
> **Status: Alpha (v0.1.x)**
|
|
17
|
+
>
|
|
18
|
+
> This is early-stage research code. APIs may change between minor versions.
|
|
19
|
+
> Tested primarily on real SPD and general non-singular matrices.
|
|
20
|
+
> Bug reports and PRs are welcome -- see [Issues](https://github.com/Hitenze/SchurILU/issues).
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install schurilu
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or install from source:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
git clone https://github.com/Hitenze/SchurILU.git
|
|
32
|
+
cd SchurILU
|
|
33
|
+
pip install -e .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For development (includes pytest):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -e ".[dev]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
### ILU Factorizations
|
|
45
|
+
|
|
46
|
+
- **ilu0**: ILU(0) with no fill-in
|
|
47
|
+
- **iluk**: ILU(k) with level-based fill
|
|
48
|
+
- **ilut**: ILUT with threshold-based dropping
|
|
49
|
+
|
|
50
|
+
All factorizations support:
|
|
51
|
+
- Schur complement computation (partial factorization)
|
|
52
|
+
- float32, float64, complex64, complex128
|
|
53
|
+
- CSR sparse matrix input
|
|
54
|
+
|
|
55
|
+
### GeMSLR Preconditioner
|
|
56
|
+
|
|
57
|
+
- **GeMSLR**: General Multilevel Schur Low-Rank preconditioner
|
|
58
|
+
- Multilevel domain decomposition via spectral graph partitioning
|
|
59
|
+
- ILU factorization on interior blocks
|
|
60
|
+
- Low-rank correction for Schur complement approximation
|
|
61
|
+
- Arnoldi-based eigenvalue computation for optimal correction
|
|
62
|
+
|
|
63
|
+
> **Note on parallelism**: The GeMSLR algorithm is designed for parallel execution -- the interior blocks at each level are independent and can be factored/solved in parallel. This pure-Python implementation is sequential; for production HPC use, see [parGeMSLR](https://github.com/Hitenze/pargemslr).
|
|
64
|
+
|
|
65
|
+
### Reordering
|
|
66
|
+
|
|
67
|
+
- **multilevel_partition**: Spectral k-way partitioning for multilevel ordering
|
|
68
|
+
- **spectral_kway**: Recursive spectral bisection using Fiedler vector
|
|
69
|
+
- **unweighted_laplacian**: Graph Laplacian construction
|
|
70
|
+
- **connected_components**: Graph connectivity analysis
|
|
71
|
+
|
|
72
|
+
> **Note**: The built-in spectral partitioner is a naive implementation for research/prototyping. For better partition quality, consider using METIS and passing a custom permutation to `GeMSLR(A, p=your_perm, lev_ptr=your_lev_ptr)`.
|
|
73
|
+
|
|
74
|
+
### Krylov Solvers
|
|
75
|
+
|
|
76
|
+
- **fgmres**: Flexible GMRES (real)
|
|
77
|
+
- **fgmrez**: Flexible GMRES (complex)
|
|
78
|
+
- **pcg**: Preconditioned Conjugate Gradient
|
|
79
|
+
- **planczos**: Preconditioned Lanczos for eigenvalue estimation
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import numpy as np
|
|
85
|
+
from schurilu import ilu0, iluk, ilut, fgmres, pcg
|
|
86
|
+
from schurilu.utils import fd3d
|
|
87
|
+
|
|
88
|
+
# Create a 3D Laplacian matrix (10x10x10 grid)
|
|
89
|
+
A = fd3d(10, 10, 10)
|
|
90
|
+
|
|
91
|
+
# ILU factorization
|
|
92
|
+
ilu = ilu0(A)
|
|
93
|
+
|
|
94
|
+
# Solve with preconditioned GMRES
|
|
95
|
+
b = np.ones(A.shape[0])
|
|
96
|
+
x, info = fgmres(A, b, M=ilu, tol=1e-10)
|
|
97
|
+
|
|
98
|
+
# Solve with preconditioned CG (for SPD matrices)
|
|
99
|
+
x, info = pcg(A, b, M=ilu, tol=1e-10)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Schur Complement
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
# Partial factorization with Schur complement
|
|
106
|
+
nB = 50 # Size of B block
|
|
107
|
+
result = ilu0(A, nB=nB)
|
|
108
|
+
|
|
109
|
+
# Access Schur complement
|
|
110
|
+
S = result.S # Schur complement matrix
|
|
111
|
+
E = result.E # Transformed lower-left block (E_orig * U_B^{-1})
|
|
112
|
+
F = result.F # Transformed upper-right block (L_B^{-1} * F_orig)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### ILU with Fill-in Control
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
# Level-based fill
|
|
119
|
+
result = iluk(A, lfil=2) # Allow fill up to level 2
|
|
120
|
+
|
|
121
|
+
# Threshold-based dropping
|
|
122
|
+
result = ilut(A, droptol=1e-4, lfil=20)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### GeMSLR Preconditioner
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from schurilu import GeMSLR, fgmres
|
|
129
|
+
|
|
130
|
+
# Create GeMSLR preconditioner with automatic spectral partitioning
|
|
131
|
+
pre = GeMSLR(A, nlev=3, k=4, droptol=1e-3, rank_k=10)
|
|
132
|
+
|
|
133
|
+
# Solve with FGMRES
|
|
134
|
+
x, info = fgmres(A, b, M=pre, tol=1e-10)
|
|
135
|
+
|
|
136
|
+
# For exact factorization (rapid convergence with full rank)
|
|
137
|
+
pre_exact = GeMSLR(A, nlev=2, k=2, droptol=0.0, rank_k=50,
|
|
138
|
+
arnoldi_tol=1e-14, arnoldi_maxiter=100)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Key parameters:
|
|
142
|
+
- `nlev`: Number of levels in the multilevel hierarchy
|
|
143
|
+
- `k`: Number of partitions per level (must be power of 2)
|
|
144
|
+
- `droptol`: Drop tolerance for ILU (0 = exact)
|
|
145
|
+
- `rank_k`: Target rank for low-rank correction
|
|
146
|
+
- `theta`: Spectrum shift parameter (default 0)
|
|
147
|
+
|
|
148
|
+
## API Reference
|
|
149
|
+
|
|
150
|
+
### ILUResult
|
|
151
|
+
|
|
152
|
+
All ILU functions return an `ILUResult` object with:
|
|
153
|
+
|
|
154
|
+
**Attributes:**
|
|
155
|
+
- `L`: Lower triangular factor (n x n sparse matrix, unit diagonal not stored)
|
|
156
|
+
- `D`: Diagonal stored as inverse (1/d_ii). For partial factorization, only `D[:nB]` is valid.
|
|
157
|
+
- `U`: Upper triangular factor (n x n sparse matrix, diagonal not stored)
|
|
158
|
+
- `E`, `F`, `S`: Schur complement parts (only present if `nB < n`). Note: `E` stores `E_orig * U_B^{-1}` and `F` stores `L_B^{-1} * F_orig`, not the original blocks.
|
|
159
|
+
- `n`: Matrix dimension
|
|
160
|
+
- `nB`: Size of B block (`nB == n` for full factorization)
|
|
161
|
+
|
|
162
|
+
**Methods:**
|
|
163
|
+
- `solve(b)`: Apply preconditioner. For partial factorization, solves only the B-block; the C-block is passed through unchanged.
|
|
164
|
+
- `to_linear_operator()`: Convert to scipy LinearOperator (n x n).
|
|
165
|
+
- `to_complete()`: Returns `(L_complete, U_complete)` with diagonals restored. Returns (nB x nB) matrices containing only the B-block factors.
|
|
166
|
+
|
|
167
|
+
### GeMSLR
|
|
168
|
+
|
|
169
|
+
The `GeMSLR` class provides a multilevel Schur low-rank preconditioner:
|
|
170
|
+
|
|
171
|
+
**Attributes:**
|
|
172
|
+
- `n`: Matrix dimension
|
|
173
|
+
- `nlev`: Number of levels in hierarchy
|
|
174
|
+
- `p`: Permutation array
|
|
175
|
+
- `lev_ptr`: Level pointers
|
|
176
|
+
|
|
177
|
+
**Methods:**
|
|
178
|
+
- `solve(b)`: Apply preconditioner
|
|
179
|
+
- `to_linear_operator()`: Convert to scipy LinearOperator
|
|
180
|
+
|
|
181
|
+
**Properties:**
|
|
182
|
+
- `nnz`: Total nonzeros in preconditioner
|
|
183
|
+
- `nnz_ilu`: Nonzeros in ILU factors
|
|
184
|
+
- `nnz_lowrank`: Nonzeros in low-rank corrections
|
|
185
|
+
- `fill_factor()`: Ratio of preconditioner nnz to original matrix nnz
|
|
186
|
+
|
|
187
|
+
### arnoldi
|
|
188
|
+
|
|
189
|
+
Low-level Arnoldi iteration for computing dominant eigenvalues:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
V, H, m, iters = arnoldi(matvec, n, neig=5, tol=1e-12, maxiter=600)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Parameters:**
|
|
196
|
+
- `matvec`: Callable for matrix-vector product
|
|
197
|
+
- `n`: Matrix dimension
|
|
198
|
+
- `neig`: Target number of eigenvalues
|
|
199
|
+
- `tol`: Convergence tolerance
|
|
200
|
+
- `maxiter`: Maximum iterations
|
|
201
|
+
|
|
202
|
+
**Returns:**
|
|
203
|
+
- `V`: Ritz vectors (n x m)
|
|
204
|
+
- `H`: Upper triangular Schur form (m x m)
|
|
205
|
+
- `m`: Number of converged eigenvalues
|
|
206
|
+
- `iters`: Total iterations performed
|
|
207
|
+
|
|
208
|
+
## Testing
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
pytest tests/ -v
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Examples
|
|
215
|
+
|
|
216
|
+
The `examples/` directory contains runnable scripts:
|
|
217
|
+
|
|
218
|
+
| Example | Description |
|
|
219
|
+
|---------|-------------|
|
|
220
|
+
| `01_ilu_basics.py` | ILU factorizations and sparsity visualization |
|
|
221
|
+
| `02_preconditioned_gmres.py` | FGMRES convergence with ILU preconditioners |
|
|
222
|
+
| `03_gemslr_preconditioner.py` | GeMSLR multilevel preconditioner comparison |
|
|
223
|
+
|
|
224
|
+
Run with:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
pip install matplotlib # for visualization
|
|
228
|
+
python examples/01_ilu_basics.py
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Related Publications
|
|
232
|
+
|
|
233
|
+
The design of SchurILU is informed by the following works:
|
|
234
|
+
|
|
235
|
+
- T. Xu, R. Li, and D. Osei-Kuffuor, "A Two-level GPU-Accelerated Incomplete LU Preconditioner for General Sparse Linear Systems," *International Journal of High Performance Computing Applications*, 39(3):424-442, 2025.
|
|
236
|
+
|
|
237
|
+
- T. Xu, V. Kalantzis, R. Li, Y. Xi, G. Dillon, and Y. Saad, "parGeMSLR: A Parallel Multilevel Schur Complement Low-Rank Preconditioning and Solution Package for General Sparse Matrices," *Parallel Computing*, 113:102956, 2022.
|
|
238
|
+
|
|
239
|
+
If you use SchurILU in academic work, please consider citing the relevant papers above. An official SchurILU citation will be provided once available.
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
MIT License
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "schurilu"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "NumPy/SciPy ILU and Schur-complement preconditioners for fair, reproducible Krylov baselines."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Tianshi Xu", email = "txu41@emory.edu"}
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"linear-algebra",
|
|
17
|
+
"sparse-matrix",
|
|
18
|
+
"ilu",
|
|
19
|
+
"preconditioner",
|
|
20
|
+
"krylov",
|
|
21
|
+
"gmres",
|
|
22
|
+
"conjugate-gradient",
|
|
23
|
+
"schur-complement",
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 3 - Alpha",
|
|
27
|
+
"Intended Audience :: Science/Research",
|
|
28
|
+
"License :: OSI Approved :: MIT License",
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.8",
|
|
32
|
+
"Programming Language :: Python :: 3.9",
|
|
33
|
+
"Programming Language :: Python :: 3.10",
|
|
34
|
+
"Programming Language :: Python :: 3.11",
|
|
35
|
+
"Programming Language :: Python :: 3.12",
|
|
36
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
37
|
+
]
|
|
38
|
+
dependencies = [
|
|
39
|
+
"numpy>=1.20.0",
|
|
40
|
+
"scipy>=1.6.0",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
dev = [
|
|
45
|
+
"pytest>=7.0.0",
|
|
46
|
+
"pytest-cov>=4.0.0",
|
|
47
|
+
]
|
|
48
|
+
examples = [
|
|
49
|
+
"matplotlib>=3.5.0",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/Hitenze/SchurILU"
|
|
54
|
+
Repository = "https://github.com/Hitenze/SchurILU"
|
|
55
|
+
Issues = "https://github.com/Hitenze/SchurILU/issues"
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.packages.find]
|
|
58
|
+
where = ["src"]
|
|
59
|
+
include = ["schurilu*"]
|
|
60
|
+
exclude = ["tests*", "examples*"]
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
testpaths = ["tests"]
|
|
64
|
+
python_files = ["test_*.py"]
|
|
65
|
+
python_classes = ["Test*"]
|
|
66
|
+
python_functions = ["test_*"]
|
|
67
|
+
addopts = "-v --tb=short"
|
|
68
|
+
|
|
69
|
+
[tool.coverage.run]
|
|
70
|
+
source = ["schurilu"]
|
|
71
|
+
omit = ["tests/*"]
|
|
72
|
+
|
|
73
|
+
[tool.coverage.report]
|
|
74
|
+
exclude_lines = [
|
|
75
|
+
"pragma: no cover",
|
|
76
|
+
"def __repr__",
|
|
77
|
+
"raise NotImplementedError",
|
|
78
|
+
]
|
schurilu-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SchurILU - Incomplete LU factorization with Schur complement support
|
|
3
|
+
|
|
4
|
+
A Python package for ILU preconditioners and Krylov solvers.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from schurilu.preconditioners import ilu0, iluk, ilut, ILUResult, GeMSLR, arnoldi
|
|
8
|
+
from schurilu.krylov import fgmres, fgmrez, pcg, planczos
|
|
9
|
+
from schurilu.reordering import (
|
|
10
|
+
multilevel_partition,
|
|
11
|
+
spectral_kway,
|
|
12
|
+
unweighted_laplacian,
|
|
13
|
+
connected_components,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__version__ = "0.1.0"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
# ILU factorizations
|
|
20
|
+
"ilu0",
|
|
21
|
+
"iluk",
|
|
22
|
+
"ilut",
|
|
23
|
+
"ILUResult",
|
|
24
|
+
# Krylov solvers
|
|
25
|
+
"fgmres",
|
|
26
|
+
"fgmrez",
|
|
27
|
+
"pcg",
|
|
28
|
+
"planczos",
|
|
29
|
+
# GeMSLR preconditioner
|
|
30
|
+
"GeMSLR",
|
|
31
|
+
"arnoldi",
|
|
32
|
+
# Reordering / partitioning
|
|
33
|
+
"multilevel_partition",
|
|
34
|
+
"spectral_kway",
|
|
35
|
+
"unweighted_laplacian",
|
|
36
|
+
"connected_components",
|
|
37
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Krylov solver module.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from schurilu.krylov.fgmres import fgmres
|
|
6
|
+
from schurilu.krylov.fgmrez import fgmrez
|
|
7
|
+
from schurilu.krylov.pcg import pcg
|
|
8
|
+
from schurilu.krylov.planczos import planczos
|
|
9
|
+
|
|
10
|
+
__all__ = ["fgmres", "fgmrez", "pcg", "planczos"]
|