From 08b1fd736cd0e1cf156fb61ddd08c685c2cbbb13 Mon Sep 17 00:00:00 2001 From: Miroslav Stoyanov Date: Sat, 30 Mar 2024 17:32:16 -0400 Subject: [PATCH] fix python library bugs --- InterfacePython/TasmanianAddons.py | 4 ++-- InterfacePython/TasmanianDreamLikely.py | 4 ++-- InterfacePython/TasmanianDreamSampler.py | 9 +++++---- InterfacePython/TasmanianDreamState.py | 4 ++-- InterfacePython/TasmanianGradientDescent.py | 4 ++-- InterfacePython/TasmanianSG.py | 10 +++------- InterfacePython/testAcceleration.py | 1 - 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/InterfacePython/TasmanianAddons.py b/InterfacePython/TasmanianAddons.py index 7df476efa..b6a3391aa 100644 --- a/InterfacePython/TasmanianAddons.py +++ b/InterfacePython/TasmanianAddons.py @@ -28,7 +28,7 @@ # IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE. ############################################################################################################################################################################## -from ctypes import c_int, c_double, c_char_p, c_void_p, POINTER, CFUNCTYPE, cdll +from ctypes import c_int, c_double, c_char_p, c_void_p, POINTER, CFUNCTYPE, CDLL, RTLD_GLOBAL import numpy as np import sys @@ -36,7 +36,7 @@ import TasmanianSG TasmanianInputError = TasmanianConfig.TasmanianInputError -pLibCTSG = cdll.LoadLibrary(TasmanianConfig.__path_libcaddons__) +pLibCTSG = CDLL(TasmanianConfig.__path_libcaddons__, mode = RTLD_GLOBAL) type_1Dfunc = CFUNCTYPE(c_double, c_double) type_lpnmodel = CFUNCTYPE(None, c_int, POINTER(c_double), c_int, POINTER(c_double), c_int, POINTER(c_int)) diff --git a/InterfacePython/TasmanianDreamLikely.py b/InterfacePython/TasmanianDreamLikely.py index aab3c482a..63108df71 100644 --- a/InterfacePython/TasmanianDreamLikely.py +++ b/InterfacePython/TasmanianDreamLikely.py @@ -28,14 +28,14 @@ # IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE. ############################################################################################################################################################################## -from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, cdll, create_string_buffer +from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, CDLL, create_string_buffer, RTLD_GLOBAL import numpy as np import sys from TasmanianConfig import __path_libdream__ from TasmanianConfig import TasmanianInputError as InputError -pLibDTSG = cdll.LoadLibrary(__path_libdream__) +pLibDTSG = CDLL(__path_libdream__, mode = RTLD_GLOBAL) pLibDTSG.tsgGetNumOutputsLikelihood.restype = c_int diff --git a/InterfacePython/TasmanianDreamSampler.py b/InterfacePython/TasmanianDreamSampler.py index cb0c6a66b..34afb4053 100644 --- a/InterfacePython/TasmanianDreamSampler.py +++ b/InterfacePython/TasmanianDreamSampler.py @@ -28,7 +28,7 @@ # IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE. ############################################################################################################################################################################## -from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, cdll, CFUNCTYPE +from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, CDLL, CFUNCTYPE, RTLD_GLOBAL import numpy as np import sys @@ -47,10 +47,11 @@ type_dream_dupdate = CFUNCTYPE(c_double) type_dream_random = CFUNCTYPE(c_double) -pLibDTSG = cdll.LoadLibrary(__path_libdream__) +pLibDTSG = CDLL(__path_libdream__, mode = RTLD_GLOBAL) + +pLibDTSG.tsgGenUniformSamples.argtypes = [c_int, c_int, POINTER(c_double), POINTER(c_double), c_char_p, c_int, type_dream_random, POINTER(c_double)] +pLibDTSG.tsgGenGaussianSamples.argtypes = [c_int, c_int, POINTER(c_double), POINTER(c_double), c_char_p, c_int, type_dream_random, POINTER(c_double)] -pLibDTSG.tsgGenUniformSamples.argtypes = [c_int, c_int, POINTER(c_double), POINTER(c_double), c_char_p, c_int, type_dream_random] -pLibDTSG.tsgGenGaussianSamples.argtypes = [c_int, c_int, POINTER(c_double), POINTER(c_double), c_char_p, c_int, type_dream_random] pLibDTSG.tsgDreamSample.argtypes = [c_int, c_int, c_int, type_dream_pdf, c_void_p, diff --git a/InterfacePython/TasmanianDreamState.py b/InterfacePython/TasmanianDreamState.py index f87b15a0d..2aaa73e53 100644 --- a/InterfacePython/TasmanianDreamState.py +++ b/InterfacePython/TasmanianDreamState.py @@ -28,7 +28,7 @@ # IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE. ############################################################################################################################################################################## -from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, cdll, create_string_buffer +from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, CDLL, create_string_buffer, RTLD_GLOBAL import numpy as np import sys @@ -37,7 +37,7 @@ from TasmanianSG import TasmanianSparseGrid as SparseGrid -pLibDTSG = cdll.LoadLibrary(__path_libdream__) +pLibDTSG = CDLL(__path_libdream__, mode = RTLD_GLOBAL) pLibDTSG.tsgMakeDreamState.restype = c_void_p pLibDTSG.tsgMakeDreamState.argtypes = [c_int, c_int] diff --git a/InterfacePython/TasmanianGradientDescent.py b/InterfacePython/TasmanianGradientDescent.py index 3bce15aa8..ee05f8a77 100644 --- a/InterfacePython/TasmanianGradientDescent.py +++ b/InterfacePython/TasmanianGradientDescent.py @@ -29,7 +29,7 @@ # RESPONSIBILITY FOR ALL LIABILITIES, PENALTIES, FINES, CLAIMS, CAUSES OF ACTION, AND COSTS AND EXPENSES, CAUSED BY, RESULTING # FROM OR ARISING OUT OF, IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE. -from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, cdll, cast, CFUNCTYPE, Structure +from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, CDLL, cast, CFUNCTYPE, Structure, RTLD_GLOBAL from numpy.ctypeslib import as_ctypes import numpy as np import sys @@ -48,7 +48,7 @@ class optimization_status(Structure): def clean_status(input_status): return dict((field, getattr(input_status, field)) for field, _ in input_status._fields_) -pLibDTSG = cdll.LoadLibrary(__path_libdream__) +pLibDTSG = CDLL(__path_libdream__, mode = RTLD_GLOBAL) pLibDTSG.tsgGradientDescentState_Construct.restype = c_void_p pLibDTSG.tsgGradientDescentState_Construct.argtypes = [c_int, POINTER(c_double), c_double] diff --git a/InterfacePython/TasmanianSG.py b/InterfacePython/TasmanianSG.py index 4d0b35340..bcaf53780 100644 --- a/InterfacePython/TasmanianSG.py +++ b/InterfacePython/TasmanianSG.py @@ -28,12 +28,12 @@ # IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE. ############################################################################################################################################################################## -from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, cdll, create_string_buffer +from ctypes import c_char_p, c_int, c_double, c_void_p, POINTER, CDLL, create_string_buffer, RTLD_GLOBAL import numpy as np import sys from TasmanianConfig import TasmanianInputError, __path_libsparsegrid__ -pLibTSG = cdll.LoadLibrary(__path_libsparsegrid__) +pLibTSG = CDLL(__path_libsparsegrid__, mode = RTLD_GLOBAL) # The ctypes library requires that we manually specify the return types of functions. In C, this is done by header files, so the # declarations below serve as a header. @@ -62,8 +62,6 @@ pLibTSG.tsgGetLoadedPoints.restype = POINTER(c_double) pLibTSG.tsgGetNeededPoints.restype = POINTER(c_double) pLibTSG.tsgGetPoints.restype = POINTER(c_double) -pLibTSG.tsgGetQuadratureWeights.restype = POINTER(c_double) -pLibTSG.tsgGetInterpolationWeights.restype = POINTER(c_double) pLibTSG.tsgBatchGetInterpolationWeights.restype = POINTER(c_double) pLibTSG.tsgIsSetDomainTransfrom.restype = c_int pLibTSG.tsgIsSetConformalTransformASIN.restype = c_int @@ -110,9 +108,7 @@ pLibTSG.tsgGetLoadedPointsStatic.argtypes = [c_void_p, POINTER(c_double)] pLibTSG.tsgGetNeededPointsStatic.argtypes = [c_void_p, POINTER(c_double)] pLibTSG.tsgGetPointsStatic.argtypes = [c_void_p, POINTER(c_double)] -pLibTSG.tsgGetQuadratureWeights.argtypes = [c_void_p, POINTER(c_double)] -pLibTSG.tsgGetQuadratureWeightsStatic.argtypes = [c_void_p] -pLibTSG.tsgGetInterpolationWeights.argtypes = [c_void_p, POINTER(c_double)] +pLibTSG.tsgGetQuadratureWeightsStatic.argtypes = [c_void_p, POINTER(c_double)] pLibTSG.tsgGetInterpolationWeightsStatic.argtypes = [c_void_p, POINTER(c_double), POINTER(c_double)] pLibTSG.tsgLoadNeededValues.argtypes = [c_void_p, POINTER(c_double)] pLibTSG.tsgGetLoadedValuesStatic.argtypes = [c_void_p, POINTER(c_double)] diff --git a/InterfacePython/testAcceleration.py b/InterfacePython/testAcceleration.py index 491b6e830..d2797d01b 100644 --- a/InterfacePython/testAcceleration.py +++ b/InterfacePython/testAcceleration.py @@ -105,7 +105,6 @@ def checkEvaluateConsistency(self): 'grid.makeWaveletGrid(2, 1, 3, 1)', 'grid.makeWaveletGrid(2, 1, 3, 3)', 'grid.makeFourierGrid(2, 1, 3, "level")' ] - lTests = ['grid.makeLocalPolynomialGrid(2, 3, 4, 1, "localp")'] iNumGPUs = grid.getNumGPUs() lsAccelTypes = ["none", "cpu-blas", "gpu-cuda", "gpu-cublas", "gpu-magma"]