From 72ccdde50e402f4680c246931f7851fe9824c4a5 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Fri, 1 Mar 2024 10:22:02 +0100 Subject: [PATCH 01/12] correcting VBBL imports --- source/MulensModel/binarylensimports.py | 21 +++++++++----- .../VBBL/VBBinaryLensingLibrary_wrapper.cpp | 29 ++++++++++++------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/source/MulensModel/binarylensimports.py b/source/MulensModel/binarylensimports.py index 6da802e7c..c375a7d76 100644 --- a/source/MulensModel/binarylensimports.py +++ b/source/MulensModel/binarylensimports.py @@ -49,13 +49,17 @@ def _import_compiled_VBBL(): _get_path_2('VBBL', "VBBinaryLensingLibrary_wrapper.so"), "VBBL") _vbbl_wrapped = (vbbl is not None) if not _vbbl_wrapped: - return (_vbbl_wrapped, None, None, None, None) + return (_vbbl_wrapped, None, None, None, None, None, None) - vbbl.VBBinaryLensing_BinaryMagDark.argtypes = 7 * [ctypes.c_double] - vbbl.VBBinaryLensing_BinaryMagDark.restype = ctypes.c_double + def _set_in_out(function, n_double): + """set input to n_double doubles and output to double""" + function.argtypes = n_double * [ctypes.c_double] + function.restype = ctypes.c_double - vbbl.VBBinaryLensing_BinaryMag0.argtypes = 7 * [ctypes.c_double] - vbbl.VBBinaryLensing_BinaryMag0.restype = ctypes.c_double + _set_in_out(vbbl.VBBinaryLensing_BinaryMagDark, 7) + _set_in_out(vbbl.VBBinaryLensing_BinaryMagFinite, 5) + _set_in_out(vbbl.VBBinaryLensing_BinaryMag0, 4) + _set_in_out(vbbl.VBBinaryLensing_BinaryMag0_shear, 7) vbbl.VBBL_SG12_5.argtypes = 12 * [ctypes.c_double] vbbl.VBBL_SG12_5.restype = np.ctypeslib.ndpointer( @@ -66,8 +70,11 @@ def _import_compiled_VBBL(): dtype=ctypes.c_double, shape=(18,)) return (_vbbl_wrapped, - vbbl.VBBinaryLensing_BinaryMagDark, vbbl.VBBL_SG12_5, - vbbl.VBBinaryLensing_BinaryMag0, vbbl.VBBL_SG12_9) + vbbl.VBBinaryLensing_BinaryMagDark, + vbbl.VBBinaryLensing_BinaryMagFinite, + vbbl.VBBinaryLensing_BinaryMag0, + vbbl.VBBinaryLensing_BinaryMag0_shear, + vbbl.VBBL_SG12_5, vbbl.VBBL_SG12_9) def _import_compiled_AdaptiveContouring(): diff --git a/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp b/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp index d00107852..5d9e356f4 100644 --- a/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp +++ b/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp @@ -5,13 +5,29 @@ extern "C" { double VBBinaryLensing_BinaryMagDark(double a, double q, double y1, double y2, double RSv, double a1, double Tol) { static VBBinaryLensing VBBL; - + return VBBL.BinaryMagDark(a, q, y1, y2, RSv, a1, Tol); } } extern "C" { - double VBBinaryLensing_BinaryMag0(double a,double q,double y1,double y2, double K, double G, double Gi) { + double VBBinaryLensing_BinaryMagFinite(double a, double q, double y1, double y2, double RSv) { + static VBBinaryLensing VBBL; + + return VBBL.BinaryMagDark2(a, q, y1, y2, RSv); + } +} + +extern "C" { + double VBBinaryLensing_BinaryMag0(double a, double q, double y1, double y2) { + static VBBinaryLensing VBBL; + + return VBBL.BinaryMag0(a, q, y1, y2); + } +} + +extern "C" { + double VBBinaryLensing_BinaryMag0_shear(double a,double q,double y1,double y2, double K, double G, double Gi) { static VBBinaryLensing_shear VBBL; return VBBL.BinaryMag0_shear(a, q, y1, y2, K, G, Gi); @@ -43,15 +59,6 @@ extern "C" double* VBBL_SG12_5(double p0, double p1, return roots; } -extern "C" { - double VBBL_BinaryMag(double a, double q, double y1, double y2) { - static VBBinaryLensing VBBL; - - return VBBL.BinaryMag0(a, q, y1, y2); - } -} - - extern "C" double* VBBL_SG12_9(double p0, double p1, double p2, double p3, double p4, double p5, double p6, double p7, double p8, double p9, double p10, double p11, From 6435b043d35affa6b6aadd546774bbcf2ed3bd72 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 7 Mar 2024 14:27:42 +0100 Subject: [PATCH 02/12] getting rid of 0 in VBBL function names and correcting imports - now the correct functions are called for compiled VBBL --- source/MulensModel/binarylens.py | 6 ++---- source/MulensModel/binarylensimports.py | 17 ++++++++++------- source/MulensModel/binarylenswithshear.py | 6 +++--- source/VBBL/VBBinaryLensingLibrary_wrapper.cpp | 6 +++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/source/MulensModel/binarylens.py b/source/MulensModel/binarylens.py index 4c77205bd..8fcf40074 100644 --- a/source/MulensModel/binarylens.py +++ b/source/MulensModel/binarylens.py @@ -4,7 +4,7 @@ from MulensModel.binarylensimports import ( _vbbl_wrapped, _adaptive_contouring_wrapped, - _vbbl_binary_mag_dark, _vbbl_binary_mag_0, + _vbbl_binary_mag_dark, _vbbl_binary_mag_point, _vbbl_SG12_5, _adaptive_contouring_linear, _solver) import MulensModel as mm @@ -335,9 +335,7 @@ def _point_source_magnification_VBBL(self, source_x, source_y): """ args = [self.separation, self.mass_2/self.mass_1, source_x, source_y] - args += [0., 0., 0.] # THIS IS A HACK THAT SHOULD BE REMOVED BY PROPER IMPORT OF VBBL - - return _vbbl_binary_mag_0(*[float(arg) for arg in args]) + return _vbbl_binary_mag_point(*[float(arg) for arg in args]) def _point_source_magnification(self, source_x, source_y): """ diff --git a/source/MulensModel/binarylensimports.py b/source/MulensModel/binarylensimports.py index c375a7d76..cf1a06e79 100644 --- a/source/MulensModel/binarylensimports.py +++ b/source/MulensModel/binarylensimports.py @@ -58,8 +58,8 @@ def _set_in_out(function, n_double): _set_in_out(vbbl.VBBinaryLensing_BinaryMagDark, 7) _set_in_out(vbbl.VBBinaryLensing_BinaryMagFinite, 5) - _set_in_out(vbbl.VBBinaryLensing_BinaryMag0, 4) - _set_in_out(vbbl.VBBinaryLensing_BinaryMag0_shear, 7) + _set_in_out(vbbl.VBBinaryLensing_BinaryMagPoint, 4) + _set_in_out(vbbl.VBBinaryLensing_BinaryMagPointShear, 7) vbbl.VBBL_SG12_5.argtypes = 12 * [ctypes.c_double] vbbl.VBBL_SG12_5.restype = np.ctypeslib.ndpointer( @@ -72,8 +72,8 @@ def _set_in_out(function, n_double): return (_vbbl_wrapped, vbbl.VBBinaryLensing_BinaryMagDark, vbbl.VBBinaryLensing_BinaryMagFinite, - vbbl.VBBinaryLensing_BinaryMag0, - vbbl.VBBinaryLensing_BinaryMag0_shear, + vbbl.VBBinaryLensing_BinaryMagPoint, + vbbl.VBBinaryLensing_BinaryMagPointShear, vbbl.VBBL_SG12_5, vbbl.VBBL_SG12_9) @@ -101,9 +101,12 @@ def _import_compiled_AdaptiveContouring(): out = _import_compiled_VBBL() _vbbl_wrapped = out[0] _vbbl_binary_mag_dark = out[1] - _vbbl_SG12_5 = out[2] - _vbbl_binary_mag_0 = out[3] - _vbbl_SG12_9 = out[4] + # VBBinaryLensing_BinaryMagFinite -> 2 + _vbbl_binary_mag_point = out[3] + _vbbl_binary_mag_point_shear = out[4] + _vbbl_SG12_5 = out[5] + _vbbl_SG12_9 = out[6] + if not _vbbl_wrapped: _solver = 'numpy' diff --git a/source/MulensModel/binarylenswithshear.py b/source/MulensModel/binarylenswithshear.py index 7b7ef1d22..19fb79f56 100644 --- a/source/MulensModel/binarylenswithshear.py +++ b/source/MulensModel/binarylenswithshear.py @@ -3,8 +3,8 @@ from math import sqrt from MulensModel.binarylens import BinaryLens -from MulensModel.binarylensimports import (_vbbl_wrapped, - _vbbl_binary_mag_0, _vbbl_SG12_9) +from MulensModel.binarylensimports import ( + _vbbl_wrapped, _vbbl_binary_mag_point_shear, _vbbl_SG12_9) import MulensModel as mm @@ -568,7 +568,7 @@ def point_source_magnification(self, source_x, source_y, vbbl_on=True): x = float(source_x) y = float(source_y) - magnification = _vbbl_binary_mag_0( + magnification = _vbbl_binary_mag_point_shear( s, q, x, y, self.convergence_K, self.shear_G.real, self.shear_G.imag) else: diff --git a/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp b/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp index 5d9e356f4..2fdce9cdd 100644 --- a/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp +++ b/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp @@ -14,12 +14,12 @@ extern "C" { double VBBinaryLensing_BinaryMagFinite(double a, double q, double y1, double y2, double RSv) { static VBBinaryLensing VBBL; - return VBBL.BinaryMagDark2(a, q, y1, y2, RSv); + return VBBL.BinaryMag2(a, q, y1, y2, RSv); } } extern "C" { - double VBBinaryLensing_BinaryMag0(double a, double q, double y1, double y2) { + double VBBinaryLensing_BinaryMagPoint(double a, double q, double y1, double y2) { static VBBinaryLensing VBBL; return VBBL.BinaryMag0(a, q, y1, y2); @@ -27,7 +27,7 @@ extern "C" { } extern "C" { - double VBBinaryLensing_BinaryMag0_shear(double a,double q,double y1,double y2, double K, double G, double Gi) { + double VBBinaryLensing_BinaryMagPointShear(double a,double q,double y1,double y2, double K, double G, double Gi) { static VBBinaryLensing_shear VBBL; return VBBL.BinaryMag0_shear(a, q, y1, y2, K, G, Gi); From 5820a50d12e1150f621339b82f5adf98cc12a595 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 7 Mar 2024 15:37:06 +0100 Subject: [PATCH 03/12] calling non-LD FS VBBL function and adding _get_u() --- source/MulensModel/binarylens.py | 37 +++++++++++++++---------- source/MulensModel/binarylensimports.py | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/source/MulensModel/binarylens.py b/source/MulensModel/binarylens.py index 8fcf40074..83d1a9e56 100644 --- a/source/MulensModel/binarylens.py +++ b/source/MulensModel/binarylens.py @@ -4,7 +4,7 @@ from MulensModel.binarylensimports import ( _vbbl_wrapped, _adaptive_contouring_wrapped, - _vbbl_binary_mag_dark, _vbbl_binary_mag_point, + _vbbl_binary_mag_dark, _vbbl_binary_mag_finite, _vbbl_binary_mag_point, _vbbl_SG12_5, _adaptive_contouring_linear, _solver) import MulensModel as mm @@ -624,24 +624,31 @@ def vbbl_magnification(self, source_x, source_y, rho, if not _vbbl_wrapped: raise ValueError('VBBL was not imported properly') + args = [float(self.separation), float(self.mass_2 / self.mass_1), + float(source_x), float(source_y), float(rho)] + + u_limb_darkening = self._get_u(gamma, u_limb_darkening) + if u_limb_darkening is None: + _vbbl_function = _vbbl_binary_mag_finite + else: + args += [u_limb_darkening, float(accuracy)] + _vbbl_function = _vbbl_binary_mag_dark + + return _vbbl_function(*args) + + def _get_u(self, gamma, u_limb_darkening): + """ + Check if one one parameter is defined, extract the u value, + and make sure it's a float. + """ if gamma is not None and u_limb_darkening is not None: raise ValueError('Only one limb darkening parameters can be set' + ' in BinaryLens.vbbl_magnification()') elif gamma is not None: - u_limb_darkening = float(mm.Utils.gamma_to_u(gamma)) + out = float(mm.Utils.gamma_to_u(gamma)) elif u_limb_darkening is not None: - u_limb_darkening = float(u_limb_darkening) + out = float(u_limb_darkening) else: - u_limb_darkening = float(0.0) - - s = float(self.separation) - q = float(self.mass_2 / self.mass_1) - x = float(source_x) - y = float(source_y) - rho = float(rho) - accuracy = float(accuracy) + out = None - magnification = _vbbl_binary_mag_dark( - s, q, x, y, rho, u_limb_darkening, accuracy) - - return magnification + return out diff --git a/source/MulensModel/binarylensimports.py b/source/MulensModel/binarylensimports.py index cf1a06e79..e21e32305 100644 --- a/source/MulensModel/binarylensimports.py +++ b/source/MulensModel/binarylensimports.py @@ -101,7 +101,7 @@ def _import_compiled_AdaptiveContouring(): out = _import_compiled_VBBL() _vbbl_wrapped = out[0] _vbbl_binary_mag_dark = out[1] - # VBBinaryLensing_BinaryMagFinite -> 2 + _vbbl_binary_mag_finite = out[2] _vbbl_binary_mag_point = out[3] _vbbl_binary_mag_point_shear = out[4] _vbbl_SG12_5 = out[5] From b33bb86e9c2f7bf0a2252ded43841dd80709ae18 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 7 Mar 2024 15:48:12 +0100 Subject: [PATCH 04/12] starting changes in vbbl_wrapper.cpp --- source/VBBL/vbbl_wrapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/VBBL/vbbl_wrapper.cpp b/source/VBBL/vbbl_wrapper.cpp index 93a8eb1c3..8e3d97bfe 100644 --- a/source/VBBL/vbbl_wrapper.cpp +++ b/source/VBBL/vbbl_wrapper.cpp @@ -19,7 +19,7 @@ VBBinaryLensing_BinaryMagDark_wrapper(PyObject *self, PyObject *args) { return Py_BuildValue("d", mag); } -static PyObject * +/*static PyObject * VBBinaryLensing_BinaryMag0_wrapper(PyObject *self, PyObject *args) { double a, q, y1, y2, K, G, Gi, mag; static VBBinaryLensing_shear VBBL; @@ -29,7 +29,7 @@ VBBinaryLensing_BinaryMag0_wrapper(PyObject *self, PyObject *args) { mag = VBBL.BinaryMag0_shear(a, q, y1, y2, K, G, Gi); return Py_BuildValue("d", mag); -} +}*/ PyObject * makelist(double *array, size_t size) { PyObject *l = PyList_New(size); @@ -111,7 +111,7 @@ VBBL_SG12_9_wrapper(PyObject *self, PyObject *args) { static PyMethodDef VBBLMethods[] = { {"VBBinaryLensing_BinaryMagDark", VBBinaryLensing_BinaryMagDark_wrapper, METH_VARARGS, "some notes here"}, - {"VBBinaryLensing_BinaryMag0", VBBinaryLensing_BinaryMag0_wrapper, METH_VARARGS, "some notes here"}, + //{"VBBinaryLensing_BinaryMag0", VBBinaryLensing_BinaryMag0_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_SG12_5", VBBL_SG12_5_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_BinaryMag", VBBinaryLensing_BinaryMag_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_SG12_9", VBBL_SG12_9_wrapper, METH_VARARGS, "some notes here"}, From 26ef71cf6f74ec0026dc4cd99bccee0576df0126 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 14 Mar 2024 15:40:18 +0100 Subject: [PATCH 05/12] tolerance passed to VBBL code; all tests pass --- source/MulensModel/binarylens.py | 4 ++-- source/MulensModel/binarylensimports.py | 2 +- source/VBBL/VBBinaryLensingLibrary_wrapper.cpp | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/MulensModel/binarylens.py b/source/MulensModel/binarylens.py index 83d1a9e56..d708de5a4 100644 --- a/source/MulensModel/binarylens.py +++ b/source/MulensModel/binarylens.py @@ -625,13 +625,13 @@ def vbbl_magnification(self, source_x, source_y, rho, raise ValueError('VBBL was not imported properly') args = [float(self.separation), float(self.mass_2 / self.mass_1), - float(source_x), float(source_y), float(rho)] + float(source_x), float(source_y), float(rho), float(accuracy)] u_limb_darkening = self._get_u(gamma, u_limb_darkening) if u_limb_darkening is None: _vbbl_function = _vbbl_binary_mag_finite else: - args += [u_limb_darkening, float(accuracy)] + args += [u_limb_darkening] _vbbl_function = _vbbl_binary_mag_dark return _vbbl_function(*args) diff --git a/source/MulensModel/binarylensimports.py b/source/MulensModel/binarylensimports.py index e21e32305..21736d8c1 100644 --- a/source/MulensModel/binarylensimports.py +++ b/source/MulensModel/binarylensimports.py @@ -57,7 +57,7 @@ def _set_in_out(function, n_double): function.restype = ctypes.c_double _set_in_out(vbbl.VBBinaryLensing_BinaryMagDark, 7) - _set_in_out(vbbl.VBBinaryLensing_BinaryMagFinite, 5) + _set_in_out(vbbl.VBBinaryLensing_BinaryMagFinite, 6) _set_in_out(vbbl.VBBinaryLensing_BinaryMagPoint, 4) _set_in_out(vbbl.VBBinaryLensing_BinaryMagPointShear, 7) diff --git a/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp b/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp index 2fdce9cdd..8e9cd7acd 100644 --- a/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp +++ b/source/VBBL/VBBinaryLensingLibrary_wrapper.cpp @@ -3,17 +3,19 @@ #include "VBBinaryLensingLibrary.h" extern "C" { - double VBBinaryLensing_BinaryMagDark(double a, double q, double y1, double y2, double RSv, double a1, double Tol) { + double VBBinaryLensing_BinaryMagDark(double a, double q, double y1, double y2, double RSv, double tolerance, double a1) { static VBBinaryLensing VBBL; - return VBBL.BinaryMagDark(a, q, y1, y2, RSv, a1, Tol); + return VBBL.BinaryMagDark(a, q, y1, y2, RSv, a1, tolerance); } } extern "C" { - double VBBinaryLensing_BinaryMagFinite(double a, double q, double y1, double y2, double RSv) { + double VBBinaryLensing_BinaryMagFinite(double a, double q, double y1, double y2, double RSv, double tolerance) { static VBBinaryLensing VBBL; + VBBL.Tol = tolerance; + return VBBL.BinaryMag2(a, q, y1, y2, RSv); } } From 764c8b3695c83426c52dd6ddc66e6445f99d14c6 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 14 Mar 2024 16:37:04 +0100 Subject: [PATCH 06/12] VBBL imports in vbbl_wrapper.cpp --- source/MulensModel/binarylensimports.py | 4 ++- source/VBBL/vbbl_wrapper.cpp | 45 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/source/MulensModel/binarylensimports.py b/source/MulensModel/binarylensimports.py index 21736d8c1..585c9d583 100644 --- a/source/MulensModel/binarylensimports.py +++ b/source/MulensModel/binarylensimports.py @@ -94,7 +94,9 @@ def _import_compiled_AdaptiveContouring(): # Check import and try manually compiled versions. if _vbbl_wrapped: _vbbl_binary_mag_dark = mm_vbbl.VBBinaryLensing_BinaryMagDark - _vbbl_binary_mag_0 = mm_vbbl.VBBinaryLensing_BinaryMag0 + _vbbl_binary_mag_finite = mm_vbbl.VBBinaryLensing_BinaryMagFinite + _vbbl_binary_mag_point = mm_vbbl.VBBinaryLensing_BinaryMagPoint + _vbbl_binary_mag_point_shear = mm_vbbl.VBBinaryLensing_BinaryMagPointShear _vbbl_SG12_5 = mm_vbbl.VBBL_SG12_5 _vbbl_SG12_9 = mm_vbbl.VBBL_SG12_9 else: diff --git a/source/VBBL/vbbl_wrapper.cpp b/source/VBBL/vbbl_wrapper.cpp index 8e3d97bfe..84e532834 100644 --- a/source/VBBL/vbbl_wrapper.cpp +++ b/source/VBBL/vbbl_wrapper.cpp @@ -9,27 +9,53 @@ Based on code written by Przemek Mroz static PyObject * VBBinaryLensing_BinaryMagDark_wrapper(PyObject *self, PyObject *args) { - double a, q, y1, y2, RSv, a1, Tol, mag; + double a, q, y1, y2, RSv, a1, tolerance, mag; static VBBinaryLensing VBBL; - if (!PyArg_ParseTuple(args, "ddddddd", &a, &q, &y1, &y2, &RSv, &a1, &Tol)) return NULL; + if (!PyArg_ParseTuple(args, "ddddddd", &a, &q, &y1, &y2, &RSv, &tolerance, &a1)) return NULL; - mag = VBBL.BinaryMagDark(a, q, y1, y2, RSv, a1, Tol); + mag = VBBL.BinaryMagDark(a, q, y1, y2, RSv, a1, tolerance); return Py_BuildValue("d", mag); } -/*static PyObject * -VBBinaryLensing_BinaryMag0_wrapper(PyObject *self, PyObject *args) { +static PyObject * +VBBinaryLensing_BinaryMagFinite_wrapper(PyObject *self, PyObject *args) { + double a, q, y1, y2, RSv, tolerance, mag; + static VBBinaryLensing VBBL; + + if (!PyArg_ParseTuple(args, "dddddd", &a, &q, &y1, &y2, &RSv, &tolerance)) return NULL; + + VBBL.Tol = tolerance; + + mag = VBBL.BinaryMag2(a, q, y1, y2, RSv); + + return Py_BuildValue("d", mag); +} + +static PyObject * +VBBinaryLensing_BinaryMagPoint_wrapper(PyObject *self, PyObject *args) { + double a, q, y1, y2, mag; + static VBBinaryLensing VBBL; + + if (!PyArg_ParseTuple(args, "dddd", &a, &q, &y1, &y2)) return NULL; + + mag = VBBL.BinaryMag0(a, q, y1, y2); + + return Py_BuildValue("d", mag); +} + +static PyObject * +VBBinaryLensing_BinaryMagPointShear_wrapper(PyObject *self, PyObject *args) { double a, q, y1, y2, K, G, Gi, mag; - static VBBinaryLensing_shear VBBL; + static VBBinaryLensing VBBL; if (!PyArg_ParseTuple(args, "ddddddd", &a, &q, &y1, &y2, &K, &G, &Gi)) return NULL; - mag = VBBL.BinaryMag0_shear(a, q, y1, y2, K, G, Gi); + mag = VBBL.BinaryMag return Py_BuildValue("d", mag); -}*/ +} PyObject * makelist(double *array, size_t size) { PyObject *l = PyList_New(size); @@ -111,6 +137,9 @@ VBBL_SG12_9_wrapper(PyObject *self, PyObject *args) { static PyMethodDef VBBLMethods[] = { {"VBBinaryLensing_BinaryMagDark", VBBinaryLensing_BinaryMagDark_wrapper, METH_VARARGS, "some notes here"}, + {"VBBinaryLensing_BinaryMagFinite", VBBinaryLensing_BinaryMagFinite_wrapper, METH_VARARGS, "some notes here"}, + {"VBBinaryLensing_BinaryMagPoint", VBBinaryLensing_BinaryMagPoint_wrapper, METH_VARARGS, "some notes here"}, + {"VBBinaryLensing_BinaryMagPointShear", VBBinaryLensing_BinaryMagPointShear_wrapper, METH_VARARGS, "some notes here"}, //{"VBBinaryLensing_BinaryMag0", VBBinaryLensing_BinaryMag0_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_SG12_5", VBBL_SG12_5_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_BinaryMag", VBBinaryLensing_BinaryMag_wrapper, METH_VARARGS, "some notes here"}, From ecdc44076621594e039861b02a4b7407d5e0d770 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Fri, 15 Mar 2024 08:32:23 +0100 Subject: [PATCH 07/12] updateding workflow --- .github/workflows/python-app.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index c2a42ab23..449d07dc1 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -8,6 +8,7 @@ on: branches: [ "master" ] pull_request: branches: [ "master" ] + workflow_dispatch: permissions: contents: read From 690554eb157bad9dfa7f9679b95d4dd712e30054 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Fri, 15 Mar 2024 08:35:36 +0100 Subject: [PATCH 08/12] bug in vbbl_wrapper.cpp --- source/VBBL/vbbl_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/VBBL/vbbl_wrapper.cpp b/source/VBBL/vbbl_wrapper.cpp index 84e532834..d71acff07 100644 --- a/source/VBBL/vbbl_wrapper.cpp +++ b/source/VBBL/vbbl_wrapper.cpp @@ -52,7 +52,7 @@ VBBinaryLensing_BinaryMagPointShear_wrapper(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "ddddddd", &a, &q, &y1, &y2, &K, &G, &Gi)) return NULL; - mag = VBBL.BinaryMag + mag = VBBL.BinaryMag0_shear(a, q, y1, y2, K, G, Gi); return Py_BuildValue("d", mag); } From 54851b2e1f8e6e2088b8750c7fd56776dc819923 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Fri, 15 Mar 2024 08:44:18 +0100 Subject: [PATCH 09/12] second bug in vbbl_wrapper.cpp --- source/VBBL/vbbl_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/VBBL/vbbl_wrapper.cpp b/source/VBBL/vbbl_wrapper.cpp index d71acff07..21e4879e1 100644 --- a/source/VBBL/vbbl_wrapper.cpp +++ b/source/VBBL/vbbl_wrapper.cpp @@ -48,7 +48,7 @@ VBBinaryLensing_BinaryMagPoint_wrapper(PyObject *self, PyObject *args) { static PyObject * VBBinaryLensing_BinaryMagPointShear_wrapper(PyObject *self, PyObject *args) { double a, q, y1, y2, K, G, Gi, mag; - static VBBinaryLensing VBBL; + static VBBinaryLensing_shear VBBL; if (!PyArg_ParseTuple(args, "ddddddd", &a, &q, &y1, &y2, &K, &G, &Gi)) return NULL; From b279864deedcf03b6c8e1a7565bb37bd3912baa1 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Fri, 15 Mar 2024 11:36:55 +0100 Subject: [PATCH 10/12] starting tests/test_BinaryLensImports.py --- .../tests/test_BinaryLensImports.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 source/MulensModel/tests/test_BinaryLensImports.py diff --git a/source/MulensModel/tests/test_BinaryLensImports.py b/source/MulensModel/tests/test_BinaryLensImports.py new file mode 100644 index 000000000..39a0115bb --- /dev/null +++ b/source/MulensModel/tests/test_BinaryLensImports.py @@ -0,0 +1,37 @@ +from numpy.testing import assert_almost_equal +import warnings + +import MulensModel as mm + + +def test_VBBL_dark(): + """ + Directly (hence, calling private function) test imported VBBL function: + + """ + if not mm.binarylensimports._vbbl_wrapped: + warnings.warn("VBBL not imported", UserWarning) + return + + out = mm.binarylensimports._vbbl_binary_mag_dark( + 1.35, 0.00578, 0.6598560303179819, -0.05280389642190758, 0.01, + 0.001, 0.0) + assert_almost_equal(out, 1.635980468652538) + +""" + out = mm.binarylensimports._vbbl_binary_mag_finite(0.8, 0.1, 0.01, 0.01, 0.01, 0.001) + print(out) + out = mm.binarylensimports._vbbl_binary_mag_point(0.8, 0.1, 0.01, 0.01) + print(out) + out = mm.binarylensimports._vbbl_binary_mag_point_shear(1.1, 0.2, 0.19090909090909103, 0.0, 0.1, 0.1, -0.1) + print(out) + out = mm.binarylensimports._vbbl_SG12_9(-0.0006162037037037004, 0.018455861111111117, 0.06027712777777768, -0.08050824074074037, -0.30724011207070717, -0.5752337759963271, -0.524794951286975, -0.2288742865013774, -0.0350081818181818, 0.0, 0.0006162037037037004, 0.005693722222222227, 0.006298813888888853, -0.0035301525925927266, 0.063350366010101, 0.1906118155555555, 0.09094615694687937, 0.029791669421487667, 0.03019545454545458, 0.0158) + print(out) + +18.283392940574107 +18.185448359975954 +7.797177952275903 +[-1.50992662 2.47560471 -1.61711916 -0.4453668 -0.75676062 -0.14298556 + 0.36097464 -0.29933664 0.02381135 -0.74906129 -3.63807783 0.90118702 + 1.29719497 0.60196247 -0.63649524 0.0565556 -0.0138864 -0.03508702] +""" From 9bf5770e632645ae4733bd3d0f4d30a9ad3655ca Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Fri, 15 Mar 2024 12:01:08 +0100 Subject: [PATCH 11/12] finishing tests/test_BinaryLensImports.py --- .../tests/test_BinaryLensImports.py | 102 +++++++++++++++--- 1 file changed, 85 insertions(+), 17 deletions(-) diff --git a/source/MulensModel/tests/test_BinaryLensImports.py b/source/MulensModel/tests/test_BinaryLensImports.py index 39a0115bb..bd6c3a603 100644 --- a/source/MulensModel/tests/test_BinaryLensImports.py +++ b/source/MulensModel/tests/test_BinaryLensImports.py @@ -7,7 +7,7 @@ def test_VBBL_dark(): """ Directly (hence, calling private function) test imported VBBL function: - + _vbbl_binary_mag_dark() """ if not mm.binarylensimports._vbbl_wrapped: warnings.warn("VBBL not imported", UserWarning) @@ -18,20 +18,88 @@ def test_VBBL_dark(): 0.001, 0.0) assert_almost_equal(out, 1.635980468652538) -""" - out = mm.binarylensimports._vbbl_binary_mag_finite(0.8, 0.1, 0.01, 0.01, 0.01, 0.001) - print(out) + +def test_VBBL_finite(): + """ + Directly (hence, calling private function) test imported VBBL function: + _vbbl_binary_mag_finite() + """ + if not mm.binarylensimports._vbbl_wrapped: + warnings.warn("VBBL not imported", UserWarning) + return + + out = mm.binarylensimports._vbbl_binary_mag_finite( + 0.8, 0.1, 0.01, 0.01, 0.01, 0.001) + assert_almost_equal(out, 18.283392940574107) + + +def test_VBBL_point(): + """ + Directly (hence, calling private function) test imported VBBL function: + _vbbl_binary_mag_point() + """ + if not mm.binarylensimports._vbbl_wrapped: + warnings.warn("VBBL not imported", UserWarning) + return + out = mm.binarylensimports._vbbl_binary_mag_point(0.8, 0.1, 0.01, 0.01) - print(out) - out = mm.binarylensimports._vbbl_binary_mag_point_shear(1.1, 0.2, 0.19090909090909103, 0.0, 0.1, 0.1, -0.1) - print(out) - out = mm.binarylensimports._vbbl_SG12_9(-0.0006162037037037004, 0.018455861111111117, 0.06027712777777768, -0.08050824074074037, -0.30724011207070717, -0.5752337759963271, -0.524794951286975, -0.2288742865013774, -0.0350081818181818, 0.0, 0.0006162037037037004, 0.005693722222222227, 0.006298813888888853, -0.0035301525925927266, 0.063350366010101, 0.1906118155555555, 0.09094615694687937, 0.029791669421487667, 0.03019545454545458, 0.0158) - print(out) - -18.283392940574107 -18.185448359975954 -7.797177952275903 -[-1.50992662 2.47560471 -1.61711916 -0.4453668 -0.75676062 -0.14298556 - 0.36097464 -0.29933664 0.02381135 -0.74906129 -3.63807783 0.90118702 - 1.29719497 0.60196247 -0.63649524 0.0565556 -0.0138864 -0.03508702] -""" + assert_almost_equal(out, 18.185448359975954) + + +def test_VBBL_shear(): + """ + Directly (hence, calling private function) test imported VBBL function: + _vbbl_binary_mag_point_shear() + """ + if not mm.binarylensimports._vbbl_wrapped: + warnings.warn("VBBL not imported", UserWarning) + return + + out = mm.binarylensimports._vbbl_binary_mag_point_shear( + 1.1, 0.2, 0.19090909090909103, 0.0, 0.1, 0.1, -0.1) + assert_almost_equal(out, 7.797177952275903) + + +def test_VBBL_SG12_5(): + """ + Directly (hence, calling private function) test imported VBBL function: + _vbbl_SG12_5() + """ + if not mm.binarylensimports._vbbl_wrapped: + warnings.warn("VBBL not imported", UserWarning) + return + + out = mm.binarylensimports._vbbl_SG12_5( + -0.17073496203535826, -0.2960054288981844, 0.2635469112719409, + 0.8257865631242759, 0.8806819361918513, 0.31179330108200043, + 0.029491785441276515, 0.17299410121242445, 0.2364363674161051, + 0.13879110194896355, 0.056792767235166075, -0.003964567527886535) + expected = [ + -0.58000512, -1.6727006, -0.57653394, 0.56004431, -0.5526021, + 0.90541606, -0.16774112, -0.76401705, -0.14860692, -0.04307995] + assert_almost_equal(out, expected) + + +def test_VBBL_SG12_9(): + """ + Directly (hence, calling private function) test imported VBBL function: + _vbbl_SG12_9() + """ + if not mm.binarylensimports._vbbl_wrapped: + warnings.warn("VBBL not imported", UserWarning) + return + + out = mm.binarylensimports._vbbl_SG12_9( + -0.0006162037037037004, 0.018455861111111117, 0.06027712777777768, + -0.08050824074074037, -0.30724011207070717, -0.5752337759963271, + -0.524794951286975, -0.2288742865013774, -0.0350081818181818, 0.0, + 0.0006162037037037004, 0.005693722222222227, 0.006298813888888853, + -0.0035301525925927266, 0.063350366010101, 0.1906118155555555, + 0.09094615694687937, 0.029791669421487667, 0.03019545454545458, + 0.0158) + expected = [ + -1.50992662, 2.47560471, -1.61711916, -0.4453668, -0.75676062, + -0.14298556, 0.36097464, -0.29933664, 0.02381135, -0.74906129, + -3.63807783, 0.90118702, 1.29719497, 0.60196247, -0.63649524, + 0.0565556, -0.0138864, -0.03508702] + assert_almost_equal(out, expected) From f62f98a6922c94a66b2583eda077c7349c2d2670 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Mon, 18 Mar 2024 11:31:06 +0100 Subject: [PATCH 12/12] comments in VBBL imports --- source/MulensModel/tests/test_BinaryLensImports.py | 6 ++++++ source/VBBL/vbbl_wrapper.cpp | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source/MulensModel/tests/test_BinaryLensImports.py b/source/MulensModel/tests/test_BinaryLensImports.py index bd6c3a603..f4833ca58 100644 --- a/source/MulensModel/tests/test_BinaryLensImports.py +++ b/source/MulensModel/tests/test_BinaryLensImports.py @@ -4,6 +4,12 @@ import MulensModel as mm +# The test presented check if VBBL code was imported properly and +# they intentionally call private functions from mm.binarylensimports. + +# The values for tests were copied from other tests. + + def test_VBBL_dark(): """ Directly (hence, calling private function) test imported VBBL function: diff --git a/source/VBBL/vbbl_wrapper.cpp b/source/VBBL/vbbl_wrapper.cpp index 21e4879e1..d8594dfd0 100644 --- a/source/VBBL/vbbl_wrapper.cpp +++ b/source/VBBL/vbbl_wrapper.cpp @@ -140,7 +140,6 @@ static PyMethodDef VBBLMethods[] = { {"VBBinaryLensing_BinaryMagFinite", VBBinaryLensing_BinaryMagFinite_wrapper, METH_VARARGS, "some notes here"}, {"VBBinaryLensing_BinaryMagPoint", VBBinaryLensing_BinaryMagPoint_wrapper, METH_VARARGS, "some notes here"}, {"VBBinaryLensing_BinaryMagPointShear", VBBinaryLensing_BinaryMagPointShear_wrapper, METH_VARARGS, "some notes here"}, - //{"VBBinaryLensing_BinaryMag0", VBBinaryLensing_BinaryMag0_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_SG12_5", VBBL_SG12_5_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_BinaryMag", VBBinaryLensing_BinaryMag_wrapper, METH_VARARGS, "some notes here"}, {"VBBL_SG12_9", VBBL_SG12_9_wrapper, METH_VARARGS, "some notes here"},