-
Notifications
You must be signed in to change notification settings - Fork 11
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
Replace maths library with Python libraries #3418
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3418 +/- ##
==========================================
+ Coverage 31.21% 31.37% +0.15%
==========================================
Files 81 81
Lines 19432 19477 +45
==========================================
+ Hits 6065 6110 +45
Misses 13367 13367 ☔ View full report in Codecov by Sentry. |
sigma, umat, vmat, ierr, work2 = ml.svd( | ||
nrws, np.asfortranarray(gmat), truth, truth | ||
) | ||
umat, sigma, vmat = svd(gmat) |
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.
The changes to PF coil require a bit of explaining. The single value decomposition from scipy returns different results to the maths library implementation. This causes the integration tests to fail, but none of the regression tests.
In some cases, like test_solv
the values of ccls
changed, but their sum did not.
In test_efc
, the ccls
values changed (one of the PF coils groups ended up with 0 current!?) but the ssq
value did not, weirdly, ssq
is calculated from the ccls
.
Overall, I suspect this is nothing to worry about, but its worth careful consideration before approving.
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.
I see, this is tricky. There are some quite substantial (to me) differences in the test results; we just need to be happy that this is due to differences in the SVD implementations and not any mistakes in the refactoring. It's particularly strange about the sum and ssq
values, as you say.
bb1f726
to
d51c80d
Compare
43bf5be
to
f66dfef
Compare
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.
Great, just the question of the SVD differences. I'm not sure how serious these differences are; it looks correct, but maybe we need to convince ourselves fully.
tests/integration/test_pfcoil_int.py
Outdated
0.58040662653667285, | ||
0.42974674788703021, | ||
0.42974674788703021, | ||
174.22748790786324, |
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.
I'm sure this is intentional, but can you explain why curpfb
and curfps
values have been swapped?
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.
Im not sure this is happening anymore
assert_array_almost_equal( | ||
work2, np.array([-2.22044605e-16, -1.73205081e00, 0.00000000e00]) | ||
) | ||
assert_array_almost_equal(ccls, np.array([-0.069036, 0.488642, 0.080394])) |
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.
These are quite different, as you say.
sigma, umat, vmat, ierr, work2 = ml.svd( | ||
nrws, np.asfortranarray(gmat), truth, truth | ||
) | ||
umat, sigma, vmat = svd(gmat) |
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.
I see, this is tricky. There are some quite substantial (to me) differences in the test results; we just need to be happy that this is due to differences in the SVD implementations and not any mistakes in the refactoring. It's particularly strange about the sum and ssq
values, as you say.
The SVD differences can be explained as follows. The original SVD implementation does not return a correctly factorised matrix. The following code demonstrates that when attempting to recreate the original matrix (https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.svd.html) for the import numpy as np
OLD = True
if OLD:
U = np.array([
[-0.81649658, -0.57735027, 0.0],
[0.40824829, -0.57735027, -0.70710678],
[0.40824829, -0.57735027, 0.70710678],
])
V = np.array([
[-0.81649658, -0.57735027, 0.0],
[0.40824829, -0.57735027, -0.70710678],
[0.40824829, -0.57735027, 0.70710678],
])
s = np.array([5.1279005e-16, 6.0000000e00, 0.0000000e00])
else:
U = np.array([
[-0.57735027, -0.57735027, -0.57735027],
[-0.57735027, -0.21132487, 0.78867513],
[-0.57735027, 0.78867513, -0.21132487],
])
V = np.array([
[-0.57735027, -0.57735027, -0.57735027],
[0.0, -0.70710678, 0.70710678],
[0.81649658, -0.40824829, -0.40824829],
])
s = np.array([6.0, 0.0, 0.0])
# reconstruct
sigma = np.zeros((3, 3))
for i in range(3):
sigma[i, i] = s[i]
a1 = np.dot(U, np.dot(sigma, V))
print(f"Checking {'old' if OLD else 'new'} SVD results")
print("Original matrix was 3x3 all 2's")
print(a1) |
1bb8c39
to
b8140b5
Compare
b8140b5
to
972dd21
Compare
Removing some of the maths routines that can be replaced with simple routines from libraries like numpy and scipy.