Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/FiPy/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
pyamgx.initialize()

from pyamgx_solver import PyAMGXSolver
with open (os.environ['AMGX_DIR']+'/core/configs/AMG_CLASSICAL_PMIS.json') as f:
#with open (os.environ['AMGX_DIR']+'/core/configs/AMG_CLASSICAL_PMIS.json') as f:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just delete this?

with open (os.environ['AMGX_DIR']+'/src/configs/AMG_CLASSICAL_PMIS.json') as f:
cfg = json.load(f)

cfg['solver']['max_iters'] = 1000
Expand Down
69 changes: 69 additions & 0 deletions examples/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

import numpy as np
import scipy.sparse as sparse
import scipy.sparse.linalg as splinalg

import pyamgx

pyamgx.initialize()

# Initialize config and resources:
cfg = pyamgx.Config().create_from_dict({
"config_version": 2,
"determinism_flag": 1,
"exception_handling" : 1,
"solver": {
"monitor_residual": 1,
"solver": "BICGSTAB",
"convergence": "RELATIVE_INI_CORE",
"preconditioner": {
"solver": "NOSOLVER"
}
}
})

rsc = pyamgx.Resources().create_simple(cfg)

# Create matrices and vectors:
A = pyamgx.Matrix().create(rsc)
b = pyamgx.Vector().create(rsc)
x = pyamgx.Vector().create(rsc)

# Create solver:
solver = pyamgx.Solver().create(rsc, cfg)

# Upload system:

N = 5

M = sparse.csr_matrix(np.random.rand(N, N))
rhs = np.random.rand(N)
sol = np.zeros(N, dtype=np.float64)

A.upload_CSR(M)
b.upload(rhs)
x.upload(sol)

# Setup and solve system:
solver.setup(A)
solver.solve(b, x)

# Download solution
x.download(sol)
print("pyamgx solution: ", sol)
print(" norm: ", np.linalg.norm(M*sol-rhs))

X = splinalg.spsolve(M, rhs)

print("scipy solution: ", X)
print(" norm: ", np.linalg.norm(M*X-rhs))

# Clean up:
A.destroy()
x.destroy()
b.destroy()
solver.destroy()
rsc.destroy()
cfg.destroy()

pyamgx.finalize()
69 changes: 69 additions & 0 deletions examples/testBICGSTAB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

import numpy as np
import scipy.sparse as sparse
import scipy.sparse.linalg as splinalg

import pyamgx

pyamgx.initialize()

# Initialize config and resources:
cfg = pyamgx.Config().create_from_dict({
"config_version": 2,
"determinism_flag": 1,
"exception_handling" : 1,
"solver": {
"monitor_residual": 1,
"solver": "BICGSTAB",
"convergence": "RELATIVE_INI_CORE",
"preconditioner": {
"solver": "SCHWARTZ"
}
}
})

rsc = pyamgx.Resources().create_simple(cfg)

# Create matrices and vectors:
A = pyamgx.Matrix().create(rsc)
b = pyamgx.Vector().create(rsc)
x = pyamgx.Vector().create(rsc)

# Create solver:
solver = pyamgx.Solver().create(rsc, cfg)

# Upload system:

N = 20

M = sparse.csr_matrix(np.random.rand(N, N))
rhs = np.random.rand(N)
sol = np.zeros(N, dtype=np.float64)

A.upload_CSR(M)
b.upload(rhs)
x.upload(sol)

# Setup and solve system:
solver.setup(A)
solver.solve(b, x)

# Download solution
x.download(sol)
print("pyamgx solution: ", sol)
print(" norm: ", np.linalg.norm(M*sol-rhs))

X = splinalg.spsolve(M, rhs)

print("scipy solution: ", X)
print(" norm: ", np.linalg.norm(M*X-rhs))

# Clean up:
A.destroy()
x.destroy()
b.destroy()
solver.destroy()
rsc.destroy()
cfg.destroy()

pyamgx.finalize()
69 changes: 69 additions & 0 deletions examples/testGMRES.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

import numpy as np
import scipy.sparse as sparse
import scipy.sparse.linalg as splinalg

import pyamgx

pyamgx.initialize()

# Initialize config and resources:
cfg = pyamgx.Config().create_from_dict({
"config_version": 2,
"determinism_flag": 1,
"exception_handling" : 1,
"solver": {
"monitor_residual": 1,
"solver": "GMRES",
"convergence": "RELATIVE_INI_CORE",
"preconditioner": {
"solver": "NOSOLVER"
}
}
})

rsc = pyamgx.Resources().create_simple(cfg)

# Create matrices and vectors:
A = pyamgx.Matrix().create(rsc)
b = pyamgx.Vector().create(rsc)
x = pyamgx.Vector().create(rsc)

# Create solver:
solver = pyamgx.Solver().create(rsc, cfg)

# Upload system:

N = 200

M = sparse.csr_matrix(np.random.rand(N, N))
rhs = np.random.rand(N)
sol = np.zeros(N, dtype=np.float64)

A.upload_CSR(M)
b.upload(rhs)
x.upload(sol)

# Setup and solve system:
solver.setup(A)
solver.solve(b, x)

# Download solution
x.download(sol)
print("pyamgx solution: ", sol)
print(" norm: ", np.linalg.norm(M*sol-rhs))

X = splinalg.spsolve(M, rhs)

print("scipy solution: ", X)
print(" norm: ", np.linalg.norm(M*X-rhs))

# Clean up:
A.destroy()
x.destroy()
b.destroy()
solver.destroy()
rsc.destroy()
cfg.destroy()

pyamgx.finalize()
4 changes: 2 additions & 2 deletions pyamgx/System.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def reset_signal_handler():
check_error(AMGX_reset_signal_handler())


cdef void c_register_print_callback(AMGX_print_callback function):
cdef void c_register_print_callback(AMGX_print_callback function)noexcept:
AMGX_register_print_callback(function)

cdef void c_print_callback(char *msg, int length):
cdef void c_print_callback(char *msg, int length)noexcept:
global print_callback
print_callback(msg.decode('utf-8'))

Expand Down
15 changes: 13 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import sys
import numpy

AMGX_DIR = os.environ.get('AMGX_DIR')
AMGX_BUILD_DIR = os.environ.get('AMGX_BUILD_DIR')
#AMGX_DIR = os.environ.get('AMGX_DIR')
#AMGX_BUILD_DIR = os.environ.get('AMGX_BUILD_DIR')
key = 'AMGX_DIR'
AMGX_DIR = os.getenv(key)
key2 = 'AMGX_BUILD_DIR'
AMGX_BUILD_DIR = os.getenv(key2)


if sys.platform == "win32":
Expand Down Expand Up @@ -73,12 +77,19 @@
library_dirs = [
numpy.get_include(),
] + AMGX_lib_dirs,
<<<<<<< HEAD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a bad merge here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for replying. Yes, I think I did a gitdiff and it messed up my files. Let me look these files over and get back to you. I'll rename the "tests" directory as you suggested.

Rod

runtime_library_dirs = runtime_lib_dirs
)])
=======
runtime_library_dirs = [
numpy.get_include(),
] + AMGX_lib_dirs,)], compiler_directives={"language_level": "3"})
>>>>>>> c3d8943 (Modified setup.py and pyamgx/System.pyx.)

setup(name='pyamgx',
author='Ashwin Srinath',
version='0.1',
ext_modules = ext,
data_files=data_files,
zip_safe=False)