Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error when using "pairwise" aggregation method in smoothed_aggregation_solver #457

@darius513

Description

@darius513

When I use the "pairwise" method to aggregate nodes in smoothed_aggregation_solver, I encounter the following error:

warn('Implicit conversion of A to CSR', SparseEfficiencyWarning)
Traceback (most recent call last):
  File "/root/pyamg/my_test/test_sa.py", line 14, in <module>
    ml = pyamg.smoothed_aggregation_solver(A, aggregate='pairwise', presmoother=('jacobi', {'iterations': 5}), postsmoother=('jacobi', {'iterations': 5}))
  File "/root/python311/lib/python3.11/site-packages/pyamg/aggregation/aggregation.py", line 272, in smoothed_aggregation_solver
    _extend_hierarchy(levels, strength, aggregate, smooth,
  File "/root/python311/lib/python3.11/site-packages/pyamg/aggregation/aggregation.py", line 372, in _extend_hierarchy
    T, B = fit_candidates(AggOp, B)
  File "/root/python311/lib/python3.11/site-packages/pyamg/aggregation/tentative.py", line 118, in fit_candidates
    raise TypeError('expected csr_array for argument AggOp')
TypeError: expected csr_array for argument AggOp

My code is as follows:

from scipy.io import mmread
import pyamg
import numpy as np

A = mmread("/root/AMG_mg/data/bcsstk01/bcsstk01.mtx", spmatrix=True)
ml = pyamg.smoothed_aggregation_solver(
    A, 
    aggregate='pairwise',
    presmoother=('jacobi', {'iterations': 5}),
    postsmoother=('jacobi', {'iterations': 5})
)
b = np.ones((A.shape[0], 1))
accelerated_residuals = []
x = ml.solve(b, tol=1e-6, maxiter=1000, accel='cg', residuals=accelerated_residuals)

print("Number of iterations of preconditioner: {}\n".format(len(accelerated_residuals)))
for i, r in enumerate(accelerated_residuals):
    print("residual at iteration {0:2}: {1:^6.2e}".format(i, r))

Could you please let me know why this error occurs when using the "pairwise" aggregation method, and how to fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions