Move choice of floating-point precision to the Python layer#123
Move choice of floating-point precision to the Python layer#123JonathanMaes merged 22 commits intodevfrom
Conversation
ilateur
left a comment
There was a problem hiding this comment.
Someone (or some-multiple) should test this on linux
DiegoDeGusem
left a comment
There was a problem hiding this comment.
On my linux device the code compiles and the test succeeds 🎉
I also agree with @ilateur's comment about a larger description.
|
A webpage was added in the Tutorials section, explaining how to choose a precision, what errors can occur, and showcasing the effect on the error floor. |
lamoreel
left a comment
There was a problem hiding this comment.
I was able to successfully compile with a single (no pun intended) and with both precisions on a Linux machine 🌈 .
I was also able to choose the precision to be used by both the flag and the env var, hence my pending approval.
Most of my comments are about documentation
| "# Restart the kernel so we can load mumax+ again with a different precision.\n", | ||
| "# This likely gives a popup saying that the kernel was stopped or will restart.\n", | ||
| "get_ipython().kernel.do_shutdown(restart=True)" |
There was a problem hiding this comment.
This doesn't work for me 😕 . (The kernel dies, but refuses to restart when trying to execute the next cell).
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], [line 8]
5 import numpy as np
6 from math import acos, atan, pi, exp, tan, sin, cos, sqrt
----> 8 from mumaxplus import *
9 from mumaxplus.util import *
12 def magnetic_moment_precession(time, initial_magnetization, hfield_z, damping):
ModuleNotFoundError: No module named 'mumaxplus'There was a problem hiding this comment.
Looks like the kernel restarts, but not in the right conda env? The imports before import mumaxplus work just fine.
lamoreel
left a comment
There was a problem hiding this comment.
The tutorial hyperlink in the README leads to a 404 error, but I'm guessing the website just needs rebuilding after the merge?
|
Indeed, after rebuilding the website this link should begin to exist. |
This PR simplifies the process of switching between single and double floating-point precision.
Previously, the precision had to be chosen before compilation, by editing
CMakeLists.txt.Now, mumax+ compiles two binaries: one for single and one for double precision (unless
MUMAXPLUS_FP_PRECISIONis set, see below). The appropriate binary is then loaded during theimport mumaxplusstatement.Two switches control the floating-point precision, as listed below in descending order of priority. Both can take the values
SINGLE/1/32for single precision andDOUBLE/2/64for double precision.--mumaxplus-fp-precisionpassed to thepythoncommand.python some_mumax_script.py --mumaxplus-fp-precision DOUBLE.MUMAXPLUS_FP_PRECISION.--mumaxplus-fp-precisionwill then result in aModuleNotFoundError.The used precision can then be accessed as
mumaxplus.FP_PRECISION.Note
Since the choice of precision must be made before the
import mumaxplusstatement, it is not possible to use single precision in one part of a script and double precision in another: these must be run in separate processes. Reloading mumax+ with a different floating point precision during runtime may lead to a vast wealth of errors.The unit test is based on
examples/errorscaling.py, since the error scaling is highly dependent on the floating point precision.