From 3ab630a73816747d12f068aea0fc4466cc928464 Mon Sep 17 00:00:00 2001 From: Jo Bovy Date: Wed, 3 Jul 2024 21:33:12 -0400 Subject: [PATCH] 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 --- galpy/util/_load_extension_libs.py | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/galpy/util/_load_extension_libs.py b/galpy/util/_load_extension_libs.py index 5419fe916..1fb741446 100644 --- a/galpy/util/_load_extension_libs.py +++ b/galpy/util/_load_extension_libs.py @@ -1,5 +1,6 @@ # _load_extension_libs.py: centralized place to load the C extensions import ctypes +import subprocess import sys import sysconfig import warnings @@ -19,8 +20,38 @@ _libgalpy_actionAngleTorus = None _libgalpy_actionAngleTorus_loaded = None +_checked_openmp_issue = False -def load_libgalpy(): + +def _check_openmp_issue(): + # 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 + # This is a known issue with OpenMP and is not galpy's fault (GitHub Copilot suggested this comment!) + + # Check this by running a subprocess that imports galpy.orbit + proc = subprocess.run( + [ + sys.executable, + "-c", + "from galpy.util._load_extension_libs import load_libgalpy; load_libgalpy(check_openmp_issue=False)", + ], + check=True, + capture_output=True, + ) + print(proc.stdout) + print(proc.stderr) + print(proc.returncode) + global _checked_openmp_issue + _checked_openmp_issue = True + return False + + +def load_libgalpy(check_openmp_issue=True): + if check_openmp_issue and not _checked_openmp_issue: + _check_openmp_issue() + else: + print( + f"Not checking for OpenMP issue and _checked_openmp_issue={_checked_openmp_issue}" + ) global _libgalpy global _libgalpy_loaded if _libgalpy_loaded is False or not _libgalpy is None: