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

add np 2.0 deprecation #407

Merged
merged 12 commits into from
Jun 26, 2024
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest, macos-latest]

steps:
Expand Down
6 changes: 3 additions & 3 deletions pyamg/aggregation/adaptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def relax(A, x):
if symmetry == 'symmetric':
A_l = P_l.T.asformat(P_l.format) * A_l * P_l
elif symmetry == 'hermitian':
A_l = P_l.H.asformat(P_l.format) * A_l * P_l
A_l = P_l.T.conjugate().asformat(P_l.format) * A_l * P_l
else:
raise ValueError(f'aSA not implemented for symmetry={symmetry}.')

Expand Down Expand Up @@ -666,7 +666,7 @@ def expand_candidates(B_old, nodesize): # pylint: disable=unused-variable
if symmetry == 'symmetric': # R should reflect A's structure
levels[i].R = levels[i].P.T.asformat(levels[i].P.format)
elif symmetry == 'hermitian':
levels[i].R = levels[i].P.H.asformat(levels[i].P.format)
levels[i].R = levels[i].P.T.conjugate().asformat(levels[i].P.format)

# construct coarse A
levels[i+1].A = levels[i].R * levels[i].A * levels[i].P
Expand Down Expand Up @@ -701,7 +701,7 @@ def expand_candidates(B_old, nodesize): # pylint: disable=unused-variable
if symmetry == 'symmetric': # R should reflect A's structure
levels[i+1].R = levels[i+1].P.T.asformat(levels[i+1].P.format)
elif symmetry == 'hermitian':
levels[i+1].R = levels[i+1].P.H.asformat(levels[i+1].P.format)
levels[i+1].R = levels[i+1].P.T.conjugate().asformat(levels[i+1].P.format)

# run solver on candidate
solver = MultilevelSolver(levels[i+1:], coarse_solver=coarse_solver)
Expand Down
17 changes: 11 additions & 6 deletions pyamg/aggregation/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,11 @@ def unpack_arg(v):

A = levels[-1].A
B = levels[-1].B
AH = None
BH = None
TH = None
if A.symmetry == 'nonsymmetric':
AH = A.H.asformat(A.format)
AH = A.T.conjugate().asformat(A.format)
BH = levels[-1].BH

# Compute the strength-of-connection matrix C, where larger
Expand Down Expand Up @@ -391,23 +394,25 @@ def unpack_arg(v):
# based on A.H. Otherwise R = P.H or P.T.
symmetry = A.symmetry
if symmetry == 'hermitian':
R = P.H
R = P.T.conjugate()
elif symmetry == 'symmetric':
R = P.T
elif symmetry == 'nonsymmetric':
fn, kwargs = unpack_arg(smooth[len(levels)-1])
if fn == 'jacobi':
R = jacobi_prolongation_smoother(AH, TH, C, BH, **kwargs).H
R = jacobi_prolongation_smoother(AH, TH, C, BH, **kwargs).T.conjugate()
elif fn == 'richardson':
R = richardson_prolongation_smoother(AH, TH, **kwargs).H
R = richardson_prolongation_smoother(AH, TH, **kwargs).T.conjugate()
elif fn == 'energy':
R = energy_prolongation_smoother(AH, TH, C, BH, None, (False, {}),
**kwargs)
R = R.H
R = R.T.conjugate()
elif fn is None:
R = T.H
R = T.T.conjugate()
else:
raise ValueError(f'Unrecognized prolongation smoother method {str(fn)}')
else:
raise ValueError('Unrecognized symmetry.')

if keep:
levels[-1].C = C # strength of connection matrix
Expand Down
2 changes: 1 addition & 1 deletion pyamg/aggregation/pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def unpack_arg(v):
# Compute pairwise interpolation and restriction matrices, R=P^*
_, kwargs = unpack_arg(aggregate[len(levels)-1])
P = pairwise_aggregation(A, **kwargs, compute_P=True)[0]
R = P.H
R = P.T.conjugate()
if isspmatrix_csr(P):
# In this case, R will be CSC, which must be changed
R = R.tocsr()
Expand Down
8 changes: 4 additions & 4 deletions pyamg/aggregation/rootnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def unpack_arg(v):
A = levels[-1].A
B = levels[-1].B
if A.symmetry == 'nonsymmetric':
AH = A.H.asformat(A.format)
AH = A.T.conjugate().asformat(A.format)
BH = levels[-1].BH

# Compute the strength-of-connection matrix C, where larger
Expand Down Expand Up @@ -423,17 +423,17 @@ def unpack_arg(v):
# based on A.H. Otherwise R = P.H or P.T.
symmetry = A.symmetry
if symmetry == 'hermitian':
R = P.H
R = P.T.conjugate()
elif symmetry == 'symmetric':
R = P.T
elif symmetry == 'nonsymmetric':
fn, kwargs = unpack_arg(smooth[len(levels)-1])
if fn == 'energy':
R = energy_prolongation_smoother(AH, TH, C, BH, levels[-1].BH,
Cpt_params=Cpt_params, **kwargs)
R = R.H
R = R.T.conjugate()
elif fn is None:
R = T.H
R = T.T.conjugate()
else:
raise ValueError(f'Unrecognized prolongation smoother method: {str(fn)}')

Expand Down
2 changes: 1 addition & 1 deletion pyamg/aggregation/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def cgnr_prolongation_smoothing(A, T, B, BtBinv, pattern, maxiter,

# For non-SPD system, apply CG on Normal Equations with Diagonal
# Preconditioning (requires transpose)
Ah = A.H
Ah = A.T.conjugate()
Ah.sort_indices()

# Preallocate
Expand Down
2 changes: 1 addition & 1 deletion pyamg/aggregation/tests/test_tentative.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ def mask_candidate(AggOp, candidates):

# each fine level candidate should be fit (almost) exactly
assert_almost_equal(fine_candidates, Q * coarse_candidates)
assert_almost_equal(Q * (Q.H * fine_candidates), fine_candidates)
assert_almost_equal(Q * (Q.T.conjugate() * fine_candidates), fine_candidates)
2 changes: 2 additions & 0 deletions pyamg/gallery/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def diffusion_stencil_2d(epsilon=1.0, theta=0.0, type='FE'):
stencil = np.array([[a, b, c],
[d, e, d],
[c, b, a]])
else:
raise ValueError('only stencil types "FE" and "FD" are supported')

return stencil

Expand Down
5 changes: 2 additions & 3 deletions pyamg/gallery/elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,12 @@ def linear_elasticity_p1(vertices, elements, E=1e5, nu=0.3, format=None):
if elements.shape[1] != D + 1:
raise ValueError('dimension mismatch')

if D not in (2, 3):
raise ValueError('only dimension 2 and 3 are supported')

if D == 2:
local_K = p12d_local
elif D == 3:
local_K = p13d_local
else:
raise ValueError('only dimension 2 and 3 are supported')

row = elements.repeat(D).reshape(-1, D)
row *= D
Expand Down
17 changes: 11 additions & 6 deletions pyamg/gallery/fem.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,11 @@ def l2norm(u, mesh):
if mesh.degree == 1:
V = mesh.V
E = mesh.E

if mesh.degree == 2:
elif mesh.degree == 2:
V = mesh.V2
E = mesh.E2
else:
raise ValueError('only mesh.degree 1 or 2 supported')

if not isinstance(u, np.ndarray):
raise ValueError('u must be ndarray')
Expand Down Expand Up @@ -361,8 +362,7 @@ def basis1(x, y):
x,
y])
basis = basis1

if mesh.degree == 2:
elif mesh.degree == 2:
I = np.arange(6)

def basis2(x, y):
Expand All @@ -373,6 +373,8 @@ def basis2(x, y):
4*x*y,
4*y*(1-x-y)])
basis = basis2
else:
raise ValueError('only mesh.degree 1 or 2 supported')

for e in E:
x = V[e, 0]
Expand Down Expand Up @@ -663,11 +665,12 @@ def kappa(_x, _y):
E = mesh.E
X = mesh.X
Y = mesh.Y

if degree == 2:
elif degree == 2:
E = mesh.E2
X = mesh.X2
Y = mesh.Y2
else:
raise ValueError('only mesh.degree 1 or 2 supported')

# allocate sparse matrix arrays
m = 3 if degree == 1 else 6
Expand Down Expand Up @@ -918,6 +921,8 @@ def applybc(A, b, mesh, bc):
elif c['degree'] == 2:
X = mesh.X2
Y = mesh.Y2
else:
raise ValueError('only mesh.degree 1 or 2 supported')
u0[idx] = c['g'](X[idx], Y[idx])

# lift (2 of 3)
Expand Down
2 changes: 1 addition & 1 deletion pyamg/gallery/tests/test_laplacian.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_gaugelaplacian(self):

for A, beta in cases:
# Check Hermitian
diff = A - A.H
diff = A - A.T.conjugate()
assert_equal(diff.data, np.array([]))

# Check for definiteness
Expand Down
2 changes: 1 addition & 1 deletion pyamg/krylov/_cgne.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def cgne(A, b, x0=None, tol=1e-5, criteria='rr',
"""
# Store the conjugate transpose explicitly as it will be used much later on
if sparse.isspmatrix(A):
AH = A.H
AH = A.T.conjugate()
else:
# avoid doing this since A may be a different sparse type
AH = aslinearoperator(np.asarray(A).conj().T)
Expand Down
2 changes: 1 addition & 1 deletion pyamg/krylov/_cgnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def cgnr(A, b, x0=None, tol=1e-5, criteria='rr',
"""
# Store the conjugate transpose explicitly as it will be used much later on
if sparse.isspmatrix(A):
AH = A.H
AH = A.T.conjugate()
else:
# avoid doing this since A may be a different sparse type
AH = aslinearoperator(np.asarray(A).conj().T)
Expand Down
2 changes: 2 additions & 0 deletions pyamg/krylov/_gmres.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ def gmres(A, b, x0=None, tol=1e-5, restart=None, maxiter=None,
(x, flag) = gmres_mgs(A, b, x0=x0, tol=tol, restart=restart,
maxiter=maxiter, M=M,
callback=callback, residuals=residuals, **kwargs)
else:
raise ValueError('orthog must be either "mgs" or "householder"')

return (x, flag)
6 changes: 3 additions & 3 deletions pyamg/krylov/tests/test_scipy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test scipy methods."""
import inspect
from functools import partial

import numpy as np
Expand Down Expand Up @@ -37,6 +36,7 @@ def cb(x, normb):
b = case['b']
x0 = case['x0']
tol = case['tol']
rtol = tol

kwargs = dict(tol=tol, restart=3, maxiter=2)

Expand All @@ -52,8 +52,8 @@ def cb(x, normb):

# check if scipy gmres has rtol
kwargs['atol'] = 0
if 'rtol' in inspect.getfullargspec(sla.gmres).args:
kwargs['rtol'] = kwargs.pop(tol)
kwargs['rtol'] = rtol
del kwargs['tol']

_ = sla.gmres(A, b, x0, callback=callback, callback_type='pr_norm', **kwargs)

Expand Down
8 changes: 2 additions & 6 deletions pyamg/multilevel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Generic AMG solver."""
import inspect

from warnings import warn

import scipy as sp
Expand Down Expand Up @@ -173,7 +171,7 @@ def __init__(self, levels, coarse_solver='pinv'):

for level in levels[:-1]:
if not hasattr(level, 'R'):
level.R = level.P.H
level.R = level.P.T.conjugate()

def __repr__(self):
"""Print basic statistics about the multigrid hierarchy."""
Expand Down Expand Up @@ -486,10 +484,8 @@ def callback_wrapper(x):
callback_wrapper = callback

# for scipy solvers, see if rtol is available
kwargs['tol'] = tol
kwargs['rtol'] = tol
kwargs['atol'] = 0
if 'rtol' in inspect.getfullargspec(accel).args:
kwargs['rtol'] = kwargs.pop(tol)

x, info = accel(A, b, x0=x0, maxiter=maxiter, M=M,
callback=callback_wrapper, **kwargs)
Expand Down
Loading
Loading