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

Adding exported aksolve source code #15

Merged
merged 2 commits into from
May 6, 2022
Merged

Conversation

mostroski
Copy link
Contributor

No description provided.

Copy link
Contributor

@Ethan-DeBandi99 Ethan-DeBandi99 left a comment

Choose a reason for hiding this comment

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

The functionality looks good to me. Mostly need to move testing into test directory and configure it to use pytest. A few functions could probably be split up into sub-functions for readability, but this is less important than test configuration.

Comment on lines 141 to 218
if __name__ == '__main__':
from aksolve.util import matvec_from_coo

print('####################')
print('# PERFORMING TESTS #')
print('####################')

host = input("enter arkouda hostname: ")
ak.connect(host)

print('==== Testing Conjugate Gradients ====')
# A = [[4, 1],
# [1, 3]]
R = ak.array([0, 0, 1, 1])
C = ak.array([0, 1, 0, 1])
V = ak.array([4, 1, 1, 3])

x = ak.array([1/11, 7/11]) # true answer
b = ak.array([1, 2]) # RHS

matvec = matvec_from_coo(R, C, V)

print('\n--> RHS == 0\n')
ans = cg(matvec, ak.zeros(2), verbose=True)
assert ans[1] == 0

print('\n--> Ax == b\n')
ans = cg(matvec, b, x)
assert ans[1] == 1 and ak.all(ans[0] == x)

print('\n--> Typical Solving\n')
ans = cg(
matvec,
b,
x_start=ak.array([2, 1]),
max_iter=5,
verbose=True)
assert ak.all(ak.abs(ans[0] - x) < 1.0e-4)
assert ans[3] < 1.0e-6
assert ans[2] == 2
assert ans[1] == 3

print('\n--> Solve to Machine Precision\n')
ans = cg(
matvec,
b,
x_start=ak.array([2, 1]),
tol=EPS,
max_iter=5,
verbose=True)
assert ak.all(ak.abs(ans[0] - x) < 1.0e-4)
assert ans[3] < EPS
assert ans[2] == 3
assert ans[1] == 2

print('\n--> Solve with Diagonal Preconditioning\n')
P = lambda x: ak.array([1/4, 1/3]) * x
ans = cg(matvec, b, precon=P, verbose=True)
assert ak.all(ak.abs(ans[0] - x) < 1.0e-4)
assert ans[3] < EPS
assert ans[2] == 2
assert ans[1] == 2

print('\n--> Solve: Large Diagonal matrix with Diagonal Preconditioning\n')
D = ak.randint(1, 1000, 2 ** 32, dtype='float64')
matvec = lambda x: x * D
x = ak.randint(0, 1, 2 ** 32, dtype='float64')
P = lambda x: x * (1.0 / D)
b = matvec(x)
ans = cg(matvec, b, precon=P, verbose=True)
assert ak.all(ak.abs(ans[0] - x) < 1.0e-4)
assert ans[3] < 1.0e-6
assert ans[2] == 1
assert ans[1] == 3

print('##############')
print('# YOU PASSED #')
print('##############')
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be moved into a test directory (same level as client). Configure to use pytest.

from aksolve.util import eye, EPS, FMAX, inner, norm, Operator


def minres(
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the comment here so It is easier overall. I am thinking we may want to break some of these calculations into sub-functions for readability. The functionality looks good to me, but it looks like there are sections that would easily break out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Added Issue #35 to track

Comment on lines 283 to 348
if __name__ == '__main__':
from aksolve.util import matvec_from_coo

print('####################')
print('# PERFORMING TESTS #')
print('####################')

host = input("enter arkouda hostname: ")
ak.connect(host)

print('==== Testing MINRES ====')
# A = [[ 6., 3., 0.],
# [ 3., -2., 5.],
# [ 0., 5., 2.]]
R = ak.array([0, 0, 0, 1, 1, 1, 2, 2, 2])
C = ak.array([0, 1, 2, 0, 1, 2, 2, 1, 2])
V = ak.array([6, 3, 0, 3, -2, 5, 0, 5, 2])

x = ak.array([2., -2., 9.])
b = ak.array([6., 55., 8.])

matvec = matvec_from_coo(R, C, V)
assert ak.all(matvec(x) == b)

print('\n--> RHS == 0\n')
ans = minres(matvec, ak.zeros(3), verbose=True)
assert ans[1] == 0

print('\n--> Ax == b\n')
ans = minres(matvec, b, x, verbose=True)
assert ans[1] == 0 and ak.all(ans[0] == x)

print('\n--> Typical Solving\n')
ans = minres(matvec, b, max_iter=3, verbose=True)
print(ans)
assert ak.all(ak.abs(ans[0] - x) < 1.0e-4)
assert ans[3] < 1.0e-6
assert ans[2] == 3
assert ans[1] == 1

print('\n--> Solve with Preconditioning\n')
invV = ak.array([0.15104167, 0.03125, -0.078125, 0.03125, -0.0625,
0.15625, -0.078125, 0.15625, 0.109375])
precon = matvec_from_coo(R, C, invV)
ans = minres(matvec, b, precon=precon, verbose=True)
print(ans)
assert ak.all(ak.abs(ans[0] - x) < 1.0e-4)
assert ans[3] <= 1.0e-6
assert ans[2] == 2
assert ans[1] == 2

print('\n--> Solve: Large Diagonal matrix with Diagonal Preconditioning\n')
D = ak.randint(1, 1000, 2 ** 32, dtype='float64')
matvec = lambda x: x * D
x = ak.randint(0, 1, 2 ** 32, dtype='float64')
P = lambda x: x * (1.0 / D)
b = matvec(x)
ans = minres(matvec, b, precon=P, verbose=True)
assert ak.all(ak.abs(ans[0] - x) < 1.0e-4)
assert ans[3] < 1.0e-6
assert ans[2] == 1
assert ans[1] == 3

print('##############')
print('# YOU PASSED #')
print('##############')
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, we need to move this to a tests directory and configure to use pytest.

@@ -0,0 +1,242 @@
def symmlq(
Copy link
Contributor

Choose a reason for hiding this comment

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

This function looks to have less natural breakpoints than the other, but I definitely think we could sub-function some elements out for readability here.

@@ -0,0 +1,2 @@
from aksolve.util import *
Copy link
Contributor

Choose a reason for hiding this comment

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

did you mean to import symmlq.py and minres.py stuff?

self.assertEqual(ans[1], 3)


#TODO: finish converting these
Copy link
Contributor

Choose a reason for hiding this comment

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

do these things still need to be worked?

Copy link
Contributor

Choose a reason for hiding this comment

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

Added issue #34 to track

Copy link
Contributor

@mhmerrill mhmerrill left a comment

Choose a reason for hiding this comment

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

i left comments

@mhmerrill mhmerrill self-requested a review May 6, 2022 16:03
Copy link
Contributor

@mhmerrill mhmerrill left a comment

Choose a reason for hiding this comment

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

looks ok to start, we will put in issues to cover changes that need to be made to work with the current version of Arkouda.

@mhmerrill mhmerrill dismissed Ethan-DeBandi99’s stale review May 6, 2022 16:03

looks ok to start, we will put in issues to cover changes that need to be made to work with the current version of Arkouda.

@mhmerrill mhmerrill merged commit 3a24d34 into Bears-R-Us:main May 6, 2022
@mostroski mostroski deleted the aksolve branch May 12, 2022 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants