-
Notifications
You must be signed in to change notification settings - Fork 27
Modified setup.py and pyamgx/System.pyx. #37
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() |
| 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() |
| 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() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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": | ||
|
|
@@ -73,12 +77,19 @@ | |
| library_dirs = [ | ||
| numpy.get_include(), | ||
| ] + AMGX_lib_dirs, | ||
| <<<<<<< HEAD | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a bad merge here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
There was a problem hiding this comment.
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?