Skip to content

Commit

Permalink
implement sparse krylov eigensolver
Browse files Browse the repository at this point in the history
the benchmark results for n=1000, m=10, p=0.01

---------------------------------------------------------------------------------------------------- benchmark: 5 tests ---------------------------------------------------------------------------------------------------
Name (time in ms)                               Min                    Max                   Mean              StdDev                 Median                 IQR            Outliers      OPS            Rounds  Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_bench_krylovschursparse_sparse         10.8453 (1.0)          16.5309 (1.0)          11.3857 (1.0)        0.8429 (1.0)          11.1605 (1.0)        0.2873 (1.0)          4;12  87.8298 (1.0)          90           1
test_bench_krylovschur                      81.1637 (7.48)        152.8512 (9.25)         92.8233 (8.15)      18.0401 (21.40)        86.6190 (7.76)       3.7345 (13.00)         1;2  10.7732 (0.12)         14           1
test_bench_krylovschursparse_dense         167.0333 (15.40)       171.3705 (10.37)       168.6568 (14.81)      1.5691 (1.86)        168.6245 (15.11)      1.8513 (6.44)          2;0   5.9292 (0.07)          6           1
test_bench_scipyqz                       1,267.5347 (116.87)    1,367.5376 (82.73)     1,317.1783 (115.69)    37.7192 (44.75)     1,318.1551 (118.11)    52.8220 (183.86)        2;0   0.7592 (0.01)          5           1
test_bench_scipyschur                   12,110.3315 (>1000.0)  13,519.9540 (817.86)   12,802.8013 (>1000.0)  545.0723 (646.63)   12,666.1154 (>1000.0)  789.2605 (>1000.0)       2;0   0.0781 (0.00)          5           1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  • Loading branch information
axsk committed Jun 10, 2020
1 parent 332309d commit 14381ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/cmdtools/analysis/pcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,25 @@ def krylovschur(A, n, massmatrix=None, onseperation="continue"):

from petsc4py import PETSc
from slepc4py import SLEPc
M = PETSc.Mat().create()
M.createDense(list(np.shape(A)), array=A)
M = petsc_matrix(A)
E = SLEPc.EPS().create()
E.setOperators(M)
E.setDimensions(nev=n)
E.setWhichEigenpairs(E.Which.LARGEST_REAL)
E.solve()
X = np.column_stack([x.array for x in E.getInvariantSubspace()])
return X[:, :n]


def petsc_matrix(A):
from scipy import sparse
from petsc4py import PETSc
from slepc4py import SLEPc

M = PETSc.Mat()
if sparse.isspmatrix_csr(A):
nrows = np.size(A, 0)
M.createAIJWithArrays(nrows, (A.indptr, A.indices, A.data))
else:
M.createDense(list(np.shape(A)), array=A)
return M
32 changes: 29 additions & 3 deletions tests/test_pcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,48 @@ def test_krylovschur(n=30, m=5, N=100):
assert R == m


def test_bench_scipyschur(benchmark, n=500, m=6):
N_BENCHMARK = 1000
M_BENCHMARK = 10


def test_bench_scipyschur(benchmark, n=N_BENCHMARK, m=M_BENCHMARK):
T = utils.randompropagator(n)
massmatrix = np.diag(np.ones(n))
solver = pcca.ScipySchur()
benchmark(solver.solve, T, m, massmatrix)


def test_bench_scipyqz(benchmark, n=500, m=6):
def test_bench_scipyqz(benchmark, n=N_BENCHMARK, m=M_BENCHMARK):
T = utils.randompropagator(n)
solver = pcca.ScipySchur()
benchmark(solver.solve, T, m)


def test_bench_krylovschur(benchmark, n=500, m=6):
def test_bench_krylovschur(benchmark, n=N_BENCHMARK, m=M_BENCHMARK):
if not pcca.HAS_SLEPC:
return
T = utils.randompropagator(n)
solver = pcca.KrylovSchur(onseperation="continue")
benchmark(solver.solve, T, m)


def test_bench_krylovschursparse_dense(benchmark, n=N_BENCHMARK, m=M_BENCHMARK):
if not pcca.HAS_SLEPC:
return
from scipy import sparse
T = utils.randompropagator(n)
T = sparse.csr_matrix(T)
solver = pcca.KrylovSchur(onseperation="continue")
benchmark(solver.solve, T, m)


def test_bench_krylovschursparse_sparse(benchmark, n=N_BENCHMARK, m=M_BENCHMARK, p=0.01):
if not pcca.HAS_SLEPC:
return
from scipy import sparse
T = sparse.random(n, n, p)
T = np.array(np.identity(n) + T)
T = utils.rowstochastic(T)
T = sparse.csr_matrix(T)
solver = pcca.KrylovSchur(onseperation="continue")
benchmark(solver.solve, T, m)

0 comments on commit 14381ad

Please sign in to comment.