Skip to content

Conversation

@JonathanMaes
Copy link
Contributor

@JonathanMaes JonathanMaes commented Jan 19, 2026

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_PRECISION is set, see below). The appropriate binary is then loaded during the import mumaxplus statement.

Two switches control the floating-point precision, as listed below in descending order of priority. Both can take the values SINGLE/1/32 for single precision and DOUBLE/2/64 for double precision.

  • A command-line flag --mumaxplus-fp-precision passed to the python command.
    • Example: python some_mumax_script.py --mumaxplus-fp-precision DOUBLE.
  • The environment variable MUMAXPLUS_FP_PRECISION.
    • Setting this will also affect the compilation: mumax+ will then only be compiled for one kind of floating point precision. This can be useful to reduce compile time during development, but passing the opposite precision with --mumaxplus-fp-precision will then result in a ModuleNotFoundError.

The used precision can then be accessed as mumaxplus.FP_PRECISION.

Note

Since the choice of precision must be made before the import mumaxplus statement, 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.

@JonathanMaes JonathanMaes added the enhancement New feature or request label Jan 19, 2026
Copy link
Collaborator

@ilateur ilateur left a 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

Copy link
Contributor

@DiegoDeGusem DiegoDeGusem left a 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.

@JonathanMaes
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants