-
Notifications
You must be signed in to change notification settings - Fork 7
Move choice of floating-point precision to the Python layer #123
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: dev
Are you sure you want to change the base?
Conversation
ilateur
left a comment
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.
Someone (or some-multiple) should test this on linux
DiegoDeGusem
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the kernel restarts, but not in the right conda env? The imports before import mumaxplus work just fine.
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.