Skip to content

Commit 3ab630a

Browse files
committed
Start on a check for the OpenMP issue, but need to learn what the error message looks like and can't reproduce locally, so pushing this to find out from the GHA wheel
1 parent c808134 commit 3ab630a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

galpy/util/_load_extension_libs.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# _load_extension_libs.py: centralized place to load the C extensions
22
import ctypes
3+
import subprocess
34
import sys
45
import sysconfig
56
import warnings
@@ -19,8 +20,38 @@
1920
_libgalpy_actionAngleTorus = None
2021
_libgalpy_actionAngleTorus_loaded = None
2122

23+
_checked_openmp_issue = False
2224

23-
def load_libgalpy():
25+
26+
def _check_openmp_issue():
27+
# Check whether we get an error of the type "OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized.", which occurs, e.g., when using pip-installed galpy with conda-installed numpy and causes segmentation faults and general issues
28+
# This is a known issue with OpenMP and is not galpy's fault (GitHub Copilot suggested this comment!)
29+
30+
# Check this by running a subprocess that imports galpy.orbit
31+
proc = subprocess.run(
32+
[
33+
sys.executable,
34+
"-c",
35+
"from galpy.util._load_extension_libs import load_libgalpy; load_libgalpy(check_openmp_issue=False)",
36+
],
37+
check=True,
38+
capture_output=True,
39+
)
40+
print(proc.stdout)
41+
print(proc.stderr)
42+
print(proc.returncode)
43+
global _checked_openmp_issue
44+
_checked_openmp_issue = True
45+
return False
46+
47+
48+
def load_libgalpy(check_openmp_issue=True):
49+
if check_openmp_issue and not _checked_openmp_issue:
50+
_check_openmp_issue()
51+
else:
52+
print(
53+
f"Not checking for OpenMP issue and _checked_openmp_issue={_checked_openmp_issue}"
54+
)
2455
global _libgalpy
2556
global _libgalpy_loaded
2657
if _libgalpy_loaded is False or not _libgalpy is None:

0 commit comments

Comments
 (0)