Question or issue on macOS:
I have a piece of code which computes the Helmholtz-Hodge Decomposition.
I’ve been running on my Mac OS Yosemite and it was working just fine. A month ago, however, my Mac got pretty slow (it was really old), and I opted to buy a new notebook (Windows 8.1, Dell).
After installing all Python libs and so on, I continued my work running this same code (versioned in Git). And then the result was pretty weird, completely different from the one obtained in the old notebook.
For instance, what I do is to construct to matrices a and b(really long calculus) and then I call the solver:
s = numpy.linalg.solve(a, b)
This was returning a (wrong, and different of the result obtained in my Mac, which was right).
Then, I tried to use:
s = scipy.linalg.solve(a, b)
And the program exits with code 0 but at the middle of it.
Then, I just made a simple test of:
print 'here1' s = scipy.linalg.solve(a, b) print 'here2'
And here2 is never printed.
print 'here1' x, info = numpy.linalg.cg(a, b) print 'here2'
And the same happens.
I also tried to check the solution after using numpy.linalg.solve:
print numpy.allclose(numpy.dot(a, s), b)
And I got a False (?!).
I don’t know what is happening, how to find a solution, I just know that the same code runs in my Mac, but it would be very good if I could run it in other platforms. Now I’m stucked in this problem (don’t have a Mac anymore) and with no clue about the cause.
The weirdest thing is that I don’t receive any error on runtime warning, no feedback at all.
Thank you for any help.
Numpy Suit Test Results:
Scipy Suit Test Results:
How to solve this problem?
Solution no. 1:
Download Anaconda package manager
When you download this it will already have all the dependencies for numpy worked out for you. It installs locally and will work on most platforms.
Solution no. 2:
This is not really an answer, but this blog discusses in length the problems of having a numpy ecosystem that evolves fast, at the expense of reproducibility.
By the way, which version of numpy are you using? The documentation for the latest 1.9 does not report any method called
cg as the one you use…
I suggest the use of this example so that you (and others) can check the results.
>>> import numpy as np >>> import scipy.linalg >>> np.random.seed(123) >>> a = np.random.random(size=(10000, 10000)) >>> b = np.random.random(size=(10000,)) >>> s_np = np.linalg.solve(a, b) >>> s_sc = scipy.linalg.solve(a, b) >>> np.allclose(s_np,s_sc) >>> s_np array([-15.59186559, 7.08345804, 4.48174646, ..., -16.43310046, -8.81301553, -10.77509242])
Solution no. 3:
I hope you can find the answer – one option in the future is to create a virtual machine for each of your projects, using Docker. This allows easy portability.
See a great article here discussing Docker for research.