Skip to content

Commit

Permalink
v1.16 - improved import of C and C++ code
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoleski committed Aug 12, 2020
1 parent 284fc7e commit 7b181ee
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 156 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[**Detailed documentation: https://rpoleski.github.io/MulensModel/**](https://rpoleski.github.io/MulensModel/)

[Latest release: 1.14.0](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code.
[Latest release: 1.16.0](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code.

MulensModel can generate a microlensing light curve for a given set of microlensing parameters, fit that light curve to some data, and return a chi2 value. That chi2 can then be input into an arbitrary likelihood function to find the best-fit parameters.

Expand Down Expand Up @@ -42,10 +42,8 @@ pip install -r requirements.txt
```
Alternatively, you can run makefiles: go to `source/VBBL/` and run `make`, then go to `source/AdaptiveContouring/` and do the same. Then and add the path `MulensModel/source` to your `PYTHONPATH`. If you have any problems, please contact the authors and we will try to help.

If you want to **install MulensModel on Windows**, please see notes [here](documents/windows_install.md). If you have **problems with installing or running MulensModel on MacOS**, please see notes [here](documents/macos_install.md). We're now working on improving intallation process.

---
[![astropy](http://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat)](http://www.astropy.org/)

file revised Jul 2020
file revised Aug 2020

6 changes: 3 additions & 3 deletions developers_board.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
1. windows compilation - [link](https://docs.python.org/3.7/extending/index.html)
3. UC 16 - make it ready for e-mail annoucement
4. new method for FSPL with LD
5. UC 16 - file_name removed in minimal example
5. UC 16 - file\_name removed in minimal example
6. remove unused branches
7. check notes below
8. add notes: 1) adding t_eff_1, t_eff_2, 2) example with [parallel EMCEE](https://emcee.readthedocs.io/en/stable/tutorials/parallel/); 3) example 2 - clarify first function; 4) data.bad requires example - note that one has to substitute full vector, not single values
8. add notes: 1) adding t\_eff\_1, t\_eff\_2, 2) example with [parallel EMCEE](https://emcee.readthedocs.io/en/stable/tutorials/parallel/); 3) example 2 - clarify first function; 4) data.bad requires example - note that one has to substitute full vector, not single values
8. back to triple lenses

## Nov & Dec goals:
Expand All @@ -30,7 +30,7 @@

_italics_ mark important tasks

Changes for planned v2 are here: [documents/MM_v2.md](documents/MM_v2.md)
Changes for planned v2 are here: [documents/MM\_v2.md](documents/MM_v2.md)

* Install
* **makefile for Windows (basic instructions exist already) [good example](https://stackoverflow.com/a/145649), [checking for Windows in makefile](https://github.com/dariomanesku/cmft/issues/28)**
Expand Down
18 changes: 0 additions & 18 deletions documents/macos_install.md

This file was deleted.

28 changes: 0 additions & 28 deletions documents/windows_install.md

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
version = line_.split()[2][1:-1]

ext_AC = Extension('MulensModel.AdaptiveContouring',
glob.glob(os.path.join(source_AC, "*.c")))
sources=glob.glob(os.path.join(source_AC, "*.c")))
ext_VBBL = Extension('MulensModel.VBBL',
glob.glob(os.path.join(source_VBBL, "*.cpp")))
sources=glob.glob(os.path.join(source_VBBL, "*.cpp")))

setup(
name='MulensModel',
Expand Down
50 changes: 50 additions & 0 deletions source/AdaptiveContouring/ac_wrap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#ifndef FLOAT
#define FLOAT double
#endif


FLOAT ld_linear(int n, FLOAT gam[], FLOAT rho);

FLOAT mag_binext(FLOAT y1, FLOAT y2, FLOAT rho, FLOAT d, FLOAT q,
FLOAT (*ld_func)(int,FLOAT*,FLOAT), int n, FLOAT gam[],
FLOAT acc, FLOAT ld_acc);

FLOAT mag_binpt(FLOAT y1, FLOAT y2, FLOAT d, FLOAT q);


static PyObject * Adaptive_Contouring_Linear_wrapper(PyObject *self, PyObject *args) {
double d, q, y1, y2, rho, gamma, acc, ld_acc;
double mag, gam[1];

if (!PyArg_ParseTuple(args, "dddddddd", &d, &q, &y1, &y2, &rho, &gamma, &acc, &ld_acc)) return NULL;

if (gamma == 0.0) {
mag = mag_binext(y1, y2, rho, d, q, NULL, -1, NULL, acc, ld_acc);
}
else {
gam[0] = gamma;
mag = mag_binext(y1, y2, rho, d, q, ld_linear, 1, gam, acc, ld_acc);
}

return Py_BuildValue("d", mag);
}

static PyMethodDef ACMethods[] = {
{"Adaptive_Contouring_Linear", Adaptive_Contouring_Linear_wrapper, METH_VARARGS, "some notes here"},
{NULL, NULL, 0, NULL} /* Sentinel */
};

static struct PyModuleDef ACmodule = {
PyModuleDef_HEAD_INIT,
"AdaptiveContouring",
NULL,
-1,
ACMethods
};

PyMODINIT_FUNC PyInit_AdaptiveContouring(void) {
return PyModule_Create(&ACmodule);
}
78 changes: 50 additions & 28 deletions source/MulensModel/binarylens.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

import MulensModel
from MulensModel.utils import Utils
try:
import MulensModel.VBBL as mm_vbbl
except:
_vbbl_wrapped = False
else:
_vbbl_wrapped = True
try:
import MulensModel.AdaptiveContouring as mm_ac
except:
_adaptive_contouring_wrapped = False
else:
_adaptive_contouring_wrapped = True


def _try_load(path, name):
Expand All @@ -29,11 +41,6 @@ def _try_load(path, name):
return None


def _get_path_1(name):
"""convenience function"""
return os.path.join(os.path.dirname(MulensModel.__file__), name + "*.so")


def _get_path_2(name_1, name_2):
"""convenience function"""
module_path = os.path.abspath(__file__)
Expand All @@ -42,38 +49,53 @@ def _get_path_2(name_1, name_2):
return os.path.join(module_path, 'source', name_1, name_2)


vbbl = _try_load(glob.glob(_get_path_1("VBBL")), "VBBL")
if vbbl is None:
vbbl = _try_load(_get_path_2('VBBL', "VBBinaryLensingLibrary_wrapper.so"),
"VBBL")
_vbbl_wrapped = (vbbl is not None)
def _import_compiled_VBBL():
"""try importing manually compiled VBBL package"""
vbbl = _try_load(
_get_path_2('VBBL', "VBBinaryLensingLibrary_wrapper.so"), "VBBL")
_vbbl_wrapped = (vbbl is not None)
if _vbbl_wrapped:
vbbl.VBBinaryLensing_BinaryMagDark.argtypes = 7 * [ctypes.c_double]
vbbl.VBBinaryLensing_BinaryMagDark.restype = ctypes.c_double

ac = "AdaptiveContouring"
adaptive_contour = _try_load(glob.glob(_get_path_1(ac)), ac)
if adaptive_contour is None:
adaptive_contour = _try_load(_get_path_2(ac, ac + "_wrapper.so"), ac)
_adaptive_contouring_wrapped = (adaptive_contour is not None)
vbbl.VBBL_SG12_5.argtypes = 12 * [ctypes.c_double]
vbbl.VBBL_SG12_5.restype = np.ctypeslib.ndpointer(
dtype=ctypes.c_double, shape=(10,))
return (_vbbl_wrapped, vbbl.VBBinaryLensing_BinaryMagDark, vbbl.VBBL_SG12_5)

if _vbbl_wrapped:
vbbl.VBBinaryLensing_BinaryMagDark.argtypes = 7 * [ctypes.c_double]
vbbl.VBBinaryLensing_BinaryMagDark.restype = ctypes.c_double
_vbbl_binary_mag_dark = vbbl.VBBinaryLensing_BinaryMagDark

vbbl.VBBL_SG12_5.argtypes = 12 * [ctypes.c_double]
vbbl.VBBL_SG12_5.restype = np.ctypeslib.ndpointer(
dtype=ctypes.c_double, shape=(10,))
_vbbl_SG12_5 = vbbl.VBBL_SG12_5
def _import_compiled_AdaptiveContouring():
"""try importing manually compiled AdaptiveContouring package"""
ac = "AdaptiveContouring"
adaptive_contour = _try_load(_get_path_2(ac, ac + "_wrapper.so"), ac)
_adaptive_contouring_wrapped = (adaptive_contour is not None)
if _adaptive_contouring_wrapped:
adaptive_contour.Adaptive_Contouring_Linear.argtypes = (
8 * [ctypes.c_double])
adaptive_contour.Adaptive_Contouring_Linear.restype = ctypes.c_double
return (_adaptive_contouring_wrapped,
adaptive_contour.Adaptive_Contouring_Linear)


# Check import and try manually compiled versions.
if _vbbl_wrapped:
_vbbl_binary_mag_dark = mm_vbbl.VBBinaryLensing_BinaryMagDark
_vbbl_SG12_5 = mm_vbbl.VBBL_SG12_5
else:
out = _import_compiled_VBBL()
_vbbl_wrapped = out[0]
_vbbl_binary_mag_dark = out[1]
_vbbl_SG12_5 = out[2]
if not _vbbl_wrapped:
_solver = 'numpy'
else:
_solver = 'Skowron_and_Gould_12'

if _adaptive_contouring_wrapped:
adaptive_contour.Adaptive_Contouring_Linear.argtypes = (
8 * [ctypes.c_double])
adaptive_contour.Adaptive_Contouring_Linear.restype = ctypes.c_double
_adaptive_contouring_linear = adaptive_contour.Adaptive_Contouring_Linear
_adaptive_contouring_linear = mm_ac.Adaptive_Contouring_Linear
else:
out = _import_compiled_AdaptiveContouring()
_adaptive_contouring_wrapped = out[0]
_adaptive_contouring_linear = out[1]


class BinaryLens(object):
Expand Down
2 changes: 1 addition & 1 deletion source/MulensModel/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = "1.15.12"
__version__ = "1.16.0"
72 changes: 0 additions & 72 deletions source/VBBL/VBBinaryLensingLibrary_wrapper.cpp_NEW

This file was deleted.

Loading

0 comments on commit 7b181ee

Please sign in to comment.