waqasbhatti / astrobase

Python modules for light curve work and variable star astronomy
MIT License
55 stars 12 forks source link

Segfault in BLS period finding #94

Closed segasai closed 4 years ago

segasai commented 4 years ago

Hi,

this simple code

import astrobase.periodbase.kbls                                        
import numpy as np
np.random.seed(3)
#astrobase.periodbase.use_astropy_bls() 
times=np.random.uniform(size=100)          *100                             
mags=np.random.normal(0.,0.01,size=100)                                 
errs=mags*0+0.01                                                        
ret=astrobase.periodbase.kbls.bls_serial_pfind(times,mags,errs) 

seems to crash with segfault on my machine with the following backtrace

[I 200211 15:12:00 __init__:84] An Astropy implementation of BLS is available because Astropy >= 3.1.
[I 200211 15:12:00 __init__:86] If you want to use it as the default periodbase BLS runner, call the periodbase.use_astropy_bls() function.
[I 200211 15:12:00 kbls:380] min P: 0.1, max P: 100.0, nfreq: 380425, minfreq: 0.01, maxfreq: 10.0
[I 200211 15:12:00 kbls:385] autofreq = True: using AUTOMATIC values for freq stepsize: 2.6260130709364816e-05, nphasebins: 200, min transit duration: 0.01, max transit duration: 0.4
[W 200211 15:12:00 kbls:418] the requested max P = 100.000 is larger than the time base of the observations = 95.201,  will make minfreq = 2 x 1/timebase
[W 200211 15:12:00 kbls:421] new minfreq: 0.021008104567491852, maxfreq: 10.0

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6c589bd in __memset_sse2 () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install bzip2-libs-1.0.6-13.el7.x86_64 gdbm-1.10-8.el7.x86_64 glibc-2.17-292.el7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-37.el7_7.2.x86_64 libcom_err-1.42.9-16.el7.x86_64 libffi-3.0.13-18.el7.x86_64 libgcc-4.8.5-39.el7.x86_64 libselinux-2.5-14.1.el7.x86_64 libstdc++-4.8.5-39.el7.x86_64 libuuid-2.23.2-61.el7_7.1.x86_64 ncurses-libs-5.9-14.20130511.el7_4.x86_64 openssl-libs-1.0.2k-19.el7.x86_64 pcre-8.32-17.el7.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-18.el7.x86_64
(gdb) bt full
#0  0x00007ffff6c589bd in __memset_sse2 () from /lib64/libc.so.6
No symbol table info available.
#1  0x00007fffe73a8441 in eebls (n=<optimized out>, t=..., x=..., u=..., 
    v=..., nfreqs=<optimized out>, fmin=0.021008104567491852, 
    df=2.6260130709364816e-05, nbins=200, qmin=0.01, qmax=0.40000000000000002, 
    p=..., bper=47.600677004788423, bpow=0.0028800913220422253, 
    depth=0.0083002852006913031, qtran=0.14000000000000001, in1=55, in2=122)
    at pyeebls/eebls.f:156
        f0 = 0.021034364698201215
        i = <optimized out>
        ibi = (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...)
        j = 1
        jf = 2
        jn1 = 55
        jn2 = 122
        k = <optimized out>
---Type <return> to continue, or q <return> to quit---
        kk = <optimized out>
        kkmi = 5
        kma = 83
        kmi = 2
        nb2 = <optimized out>
        nbkma = 281
        p0 = 47.541250441736253
        ph = <optimized out>
        power = <optimized out>
        rn = <optimized out>
        rn1 = <optimized out>
        rn3 = 14
        s = <optimized out>
        s3 = -0.099935433816323291
        t1 = <optimized out>
        tot = <optimized out>
        y = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0---Type <return> to continue, or q <return> to quit---
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...)
#2  0x00007fffe73a56b6 in f2py_rout__pyeebls_eebls (capi_self=<optimized out>, 
    capi_args=<optimized out>, capi_keywds=<optimized out>, 
    f2py_func=0x7fffe73a7d90 <eebls>)
    at build/src.linux-x86_64-3.6/pyeebls/_pyeeblsmodule.c:400
        _save = 0x604c40
        capi_buildvalue = 0x0
        f2py_success = 1
        n = 100
        n_capi = 0x7ffff7d60210 <_Py_NoneStruct>
        t = 0x1e966f0
        t_Dims = {100}
        capi_t_tmp = 0x7fffec0f4a80
        capi_t_intent = 1
        t_capi = 0x7fffec0f4a80
        x = 0x1e97ac0
        x_Dims = {100}
        capi_x_tmp = 0x7fffec0f4ad0
        capi_x_intent = 1
        x_capi = 0x7fffec0f4ad0
        u = 0x1e95d70
        u_Dims = {100}
        capi_u_tmp = 0x7fffdcfd8a30
---Type <return> to continue, or q <return> to quit---
        capi_u_intent = 2
        u_capi = 0x7fffdcfd8a30
        v = 0x1e95a40
        v_Dims = {100}
        capi_v_tmp = 0x7fffec0f4b20
        capi_v_intent = 2
        v_capi = 0x7fffec0f4b20
        nfreqs = 380425
        nfreqs_capi = 0x7fffb1218450
        fmin = 0.021008104567491852
        fmin_capi = 0x7fffdcfd9be8
        df = 2.6260130709364816e-05
        df_capi = 0x7fffdcfd9ba0
        nbins = 200
        nbins_capi = 0x7fffdd4d98b0
        qmin = 0.01
        qmin_capi = 0x7fffec6b01e0
        qmax = 0.40000000000000002
        qmax_capi = 0x7fffec6b0270
        p = 0x7fffd3ab8010
        p_Dims = {380425}
        capi_p_tmp = 0x7fffdd50ee40
        capi_p_intent = 12
---Type <return> to continue, or q <return> to quit---
        bper = 47.600677004788423
        bpow = 0.0028800913220422253
        depth = 0.0083002852006913031
        qtran = 0.14000000000000001
        in1 = 55
        in2 = 122
        capi_kwlist = {0x7fffe73a9530 "t", 0x7fffe73a9553 "x", 
          0x7fffe73a9532 "u", 0x7fffe73a9534 "v", 0x7fffe73a9536 "nfreqs", 
          0x7fffe73a953d "fmin", 0x7fffe73a9542 "df", 0x7fffe73a9545 "nbins", 
          0x7fffe73a954b "qmin", 0x7fffe73a9550 "qmax", 0x7fffe73a9c35 "n", 
          0x0}
#3  0x00007ffff7960b60 in _PyObject_FastCallDict (func=0x7fffec1550a8, 
    args=<optimized out>, nargs=<optimized out>, kwargs=0x0)
    at Objects/abstract.c:2331
        tuple = 0x7fffd8154b48
        call = 0x7fffe73a6510 <fortran_call>
        result = 0x0
#4  0x00007ffff7a08f1c in call_function (
    pp_stack=pp_stack@entry=0x7fffffffcfd0, oparg=<optimized out>, 
    kwnames=kwnames@entry=0x0) at Python/ceval.c:4875
        pfunc = 0x1e98308
        func = 0x7fffec1550a8
        x = <optimized out>
---Type <return> to continue, or q <return> to quit---
        w = <optimized out>
        nkwargs = <optimized out>
        nargs = 10
        stack = <optimized out>
#5  0x00007ffff79fe087 in _PyEval_EvalFrameDefault (f=<optimized out>, 
    throwflag=<optimized out>) at Python/ceval.c:3335
        sp = 0x1e98360
        res = <optimized out>
        stack_pointer = <optimized out>
        next_instr = 0x7fffec15a7fc
        opcode = <optimized out>
        oparg = <optimized out>
        why = <optimized out>
        fastlocals = 0x1e982b0
        freevars = 0x1e98308
        retval = <optimized out>
        tstate = <optimized out>
        co = <optimized out>
        instr_ub = -1
        instr_lb = 0
        instr_prev = -1
        first_instr = <optimized out>
        names = 0x7fffa26c46c0
---Type <return> to continue, or q <return> to quit---
        consts = 0x7fffec1470c0
        opcode_targets = {0x7ffff7a07165 <_PyEval_EvalFrameDefault+37909>, 
   ....
#6  0x00007ffff7a08b5a in _PyFunction_FastCall (globals=<optimized out>, 
    nargs=<optimized out>, args=<optimized out>, co=<optimized out>)
    at Python/ceval.c:4933
        fastlocals = 0x1e982b0
        i = <optimized out>
        f = 0x1e98138
        tstate = 0x604c40
        result = <optimized out>
#7  fast_function (func=<optimized out>, stack=0x1e958e8, 
    nargs=<optimized out>, kwnames=<optimized out>) at Python/ceval.c:4968
        co = <optimized out>
        globals = <optimized out>
        argdefs = <optimized out>
        kwdefs = <optimized out>
        closure = <optimized out>
        name = <optimized out>
        qualname = <optimized out>
        d = <optimized out>
        nkwargs = <optimized out>
---Type <return> to continue, or q <return> to quit---
        nd = <optimized out>
#8  0x00007ffff7a08e93 in call_function (
    pp_stack=pp_stack@entry=0x7fffffffd200, oparg=<optimized out>, 
    kwnames=kwnames@entry=0x0) at Python/ceval.c:4872
        pfunc = 0x1e958e0
        func = 0x7fffec0ee9d8
        x = <optimized out>
        w = <optimized out>
        nkwargs = <optimized out>
        nargs = 8
        stack = <optimized out>
#9  0x00007ffff79fe087 in _PyEval_EvalFrameDefault (f=<optimized out>, 
    throwflag=<optimized out>) at Python/ceval.c:3335
        sp = 0x1e95928
        res = <optimized out>
        stack_pointer = <optimized out>
        next_instr = 0x19535be
        opcode = <optimized out>
        oparg = <optimized out>
        why = <optimized out>
        fastlocals = 0x1e95770
        freevars = 0x1e958d0
        retval = <optimized out>
---Type <return> to continue, or q <return> to quit---
        tstate = <optimized out>
        co = <optimized out>
        instr_ub = -1
        instr_lb = 0
        instr_prev = -1
        first_instr = <optimized out>
        names = 0x7fffec2a24d0
        consts = 0x7fffec30e778
        opcode_targets = {0x7ffff7a07165 <_PyEval_EvalFrameDefault+37909>, 
 ....
#10 0x00007ffff7a081d9 in _PyEval_EvalCodeWithName (_co=0x7fffec14fc90, 
    globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=<optimized out>, kwnames=0x0, kwargs=0x65cfb0, 
    kwcount=<optimized out>, kwstep=1, defs=0x7fffec17dec0, defcount=14, 
    kwdefs=0x0, closure=0x0, name=<optimized out>, qualname=0x7ffff043e7c8)
    at Python/ceval.c:4166
        co = 0x7fffec14fc90
        f = <optimized out>
        retval = 0x0
        fastlocals = <optimized out>
        freevars = <optimized out>
        tstate = 0x604c40
---Type <return> to continue, or q <return> to quit---
        x = <optimized out>
        u = <optimized out>
        total_args = <optimized out>
        i = 0
        n = <optimized out>
        kwdict = <optimized out>
#11 0x00007ffff7a08c0a in fast_function (func=<optimized out>, stack=0x65cf98, 
    nargs=3, kwnames=<optimized out>) at Python/ceval.c:4992
        co = <optimized out>
        globals = <optimized out>
        argdefs = <optimized out>
        kwdefs = 0x0
        closure = 0x0
        name = 0x7ffff043e7c8
        qualname = <optimized out>
        d = <optimized out>
        nkwargs = <optimized out>
        nd = <optimized out>
#12 0x00007ffff7a08e93 in call_function (
    pp_stack=pp_stack@entry=0x7fffffffd4e0, oparg=<optimized out>, 
    kwnames=kwnames@entry=0x0) at Python/ceval.c:4872
        pfunc = 0x65cf90
        func = 0x7fffdcfd0950
---Type <return> to continue, or q <return> to quit---
        x = <optimized out>
        w = <optimized out>
        nkwargs = <optimized out>
        nargs = 3
        stack = <optimized out>
#13 0x00007ffff79fe087 in _PyEval_EvalFrameDefault (f=<optimized out>, 
    throwflag=<optimized out>) at Python/ceval.c:3335
        sp = 0x65cfb0
        res = <optimized out>
        stack_pointer = <optimized out>
        next_instr = 0x7ffff7f25f04
        opcode = <optimized out>
        oparg = <optimized out>
        why = <optimized out>
        fastlocals = 0x65cf90
        freevars = 0x65cf90
        retval = <optimized out>
        tstate = <optimized out>
        co = <optimized out>
        instr_ub = -1
        instr_lb = 0
        instr_prev = -1
        first_instr = <optimized out>
---Type <return> to continue, or q <return> to quit---
        names = 0x7ffff7e8a8d0
        consts = 0x7ffff0481868
        opcode_targets = {0x7ffff7a07165 <_PyEval_EvalFrameDefault+37909>, 
          0x7ffff79fe250 <_PyEval_EvalFrameDefault+1280>, 
...
#14 0x00007ffff7a09135 in _PyEval_EvalCodeWithName (qualname=0x0, 
    name=<optimized out>, closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, 
    kwstep=2, kwcount=<optimized out>, kwargs=<optimized out>, kwnames=0x0, 
    argcount=0, args=0x0, locals=0x7ffff7f3c1f8, globals=0x7ffff7f3c1f8, 
    _co=0x7ffff7f01a50) at Python/ceval.c:4166
        co = 0x7ffff7f01a50
        retval = 0x0
        fastlocals = <optimized out>
        kwdict = <optimized out>
        tstate = 0x604c40
        x = <optimized out>
        u = <optimized out>
        n = <optimized out>
        f = 0x65ce18
        freevars = <optimized out>
        total_args = 0
        i = 0
#15 PyEval_EvalCodeEx (_co=_co@entry=0x7ffff7f01a50, 
---Type <return> to continue, or q <return> to quit---
    globals=globals@entry=0x7ffff7f3c1f8, locals=locals@entry=0x7ffff7f3c1f8, 
    args=args@entry=0x0, argcount=argcount@entry=0, kws=kws@entry=0x0, 
    kwcount=kwcount@entry=0, defs=defs@entry=0x0, defcount=defcount@entry=0, 
    kwdefs=kwdefs@entry=0x0, closure=closure@entry=0x0) at Python/ceval.c:4187
No locals.
#16 0x00007ffff7a09e8b in PyEval_EvalCode (co=co@entry=0x7ffff7f01a50, 
    globals=globals@entry=0x7ffff7f3c1f8, locals=locals@entry=0x7ffff7f3c1f8)
    at Python/ceval.c:731
No locals.
#17 0x00007ffff7a907fe in run_mod (mod=mod@entry=0x6b39c0, 
    filename=filename@entry=0x7ffff04411b8, 
    globals=globals@entry=0x7ffff7f3c1f8, locals=locals@entry=0x7ffff7f3c1f8, 
    flags=flags@entry=0x7fffffffd7d0, arena=arena@entry=0x7ffff7f55228)
    at Python/pythonrun.c:1025
        co = 0x7ffff7f01a50
        v = <optimized out>
#18 0x00007ffff7941ecb in PyRun_FileExFlags (fp=fp@entry=0x6ad530, 
    filename_str=filename_str@entry=0x7ffff7efd460 "xx.py", 
    start=start@entry=257, globals=globals@entry=0x7ffff7f3c1f8, 
    locals=locals@entry=0x7ffff7f3c1f8, closeit=closeit@entry=1, 
    flags=flags@entry=0x7fffffffd7d0) at Python/pythonrun.c:978
        ret = 0x0
        mod = 0x6b39c0
---Type <return> to continue, or q <return> to quit---
        arena = 0x7ffff7f55228
        filename = 0x7ffff04411b8
#19 0x00007ffff79422b7 in PyRun_SimpleFileExFlags (fp=fp@entry=0x6ad530, 
    filename=<optimized out>, closeit=closeit@entry=1, 
    flags=flags@entry=0x7fffffffd7d0) at Python/pythonrun.c:419
        m = 0x7ffff7f3a228
        d = 0x7ffff7f3c1f8
        v = <optimized out>
        ext = <optimized out>
        set_file_name = 1
        ret = -1
        len = <optimized out>
#20 0x00007ffff794285a in PyRun_AnyFileExFlags (fp=fp@entry=0x6ad530, 
    filename=<optimized out>, closeit=closeit@entry=1, 
    flags=flags@entry=0x7fffffffd7d0) at Python/pythonrun.c:81
No locals.
#21 0x00007ffff7a97203 in run_file (p_cf=0x7fffffffd7d0, 
    filename=0x6042c0 L"xx.py", fp=0x6ad530) at Modules/main.c:340
        unicode = 0x7ffff7e88298
        bytes = 0x7ffff7efd440
        filename_str = <optimized out>
        run = <optimized out>
#22 Py_Main (argc=argc@entry=2, argv=argv@entry=0x603010) at Modules/main.c:810
---Type <return> to continue, or q <return> to quit---
        c = <optimized out>
        sts = -1
        command = 0x0
        filename = 0x6042c0 L"xx.py"
        module = 0x0
        fp = 0x6ad530
        p = <optimized out>
        skipfirstline = <optimized out>
        stdin_is_interactive = 1
        help = <optimized out>
        version = <optimized out>
        saw_unbuffered_flag = <optimized out>
        opt = <optimized out>
        cf = {cf_flags = 0}
        main_importer_path = <optimized out>
        warning_option = <optimized out>
        warning_options = <optimized out>
#23 0x0000000000400a19 in main (argc=2, argv=<optimized out>)
    at ./Programs/python.c:69
        argv_copy = 0x603010
        argv_copy2 = 0x603030
        i = <optimized out>
        res = <optimized out>
---Type <return> to continue, or q <return> to quit---
        oldloc = 0x603050 ""

I don't know if I'll have time to look at/debug it further, but it looks like a clear bug. (I'm using python 3.6 on linux with the latest astrobase)

Thanks Sergey

waqasbhatti commented 4 years ago

Hello!

Thanks for the bug report. I'm traveling and have spotty internet access at the moment, but will take a look in a couple of days.

waqasbhatti commented 4 years ago

Apologies for the late response.

It appears that the Fortran code in pyeebls (wrapped by the periodbase.kbls module) doesn't like unsorted time input arrays. Using a sorted time array avoids the segfault. The latest commit should fix the issue.