Segfault due to weird interaction between initVm() and Numpy linear algebra inverse
The following code results in a Segmentation Fault:
import orekit
import numpy
# XXX: If you uncomment this, BOTH inverse operations will work fine.
# mat = numpy.linalg.inv(numpy.random.rand(6, 6))
orekit.initVM()
numpy.linalg.inv(numpy.random.rand(6, 6)) # XXX: If orekit.initVM() is called first, this inversion will cause a Segmentation fault.
# NOTE: Matrices of size 5,5 or smaller seem to work fine.
Versions:
- python 3.10.9
- numpy 1.22.4 (but also observed this issue with numpy 1.25+)
- numpy is seemingly linked to openblas64 (version 0.3.18?)
- orekit 11.3.2 (installed via conda-forge)
This issue is similar and probably related to https://github.com/bcdev/jpy/issues/139 We've reproduced this issue on two separate machines, but on a third machine it doesn't reproduce, despite all using the same environment (Docker containers with the same version of packages).
I'm not sure whether this is an Orekit, numpy, openblas, or JavaVM issue, but I've reported it here since it affects orekit usage specifically.
I guess there might not be much to investigate or fix from the Orekit side, so I leave this here as a potential warning and/or work-around to anyone else who might run into this weird issue. If you perform the inv operation before calling initVM, it all seems to work, so maybe numpy.linalg needs to kind of initialise before JavaVM?