havakv / pycox

Survival analysis with PyTorch
BSD 2-Clause "Simplified" License
781 stars 180 forks source link

Numba TypingError: Failed in nopython mode pipeline (step: nopython frontend) #95

Closed berkuva closed 2 years ago

berkuva commented 2 years ago

I wasn't sure whether to post this on Numba or here, but I am guessing I am getting this error because of my incorrect way of using PyCox, so I am posting here. This occurs when I try to instantiate an EvalSurv object.

I have no experience in Numba, and some online digging did not help.. Please help. Thank you.

/usr/local/lib/python3.7/site-packages/pycox/evaluation/eval_surv.py in __init__(self, surv, durations, events, censor_surv, censor_durations, steps)
     31         self.durations = durations
     32         self.events = events
---> 33         self.censor_surv = censor_surv
     34         self.censor_durations = censor_durations
     35         self.steps = steps

/usr/local/lib/python3.7/site-packages/pycox/evaluation/eval_surv.py in censor_surv(self, censor_surv)
     49         elif type(censor_surv) is str:
     50             if censor_surv == 'km':
---> 51                 self.add_km_censor()
     52             else:
     53                 raise ValueError(f"censor_surv cannot be {censor_surv}. Use e.g. 'km'")

/usr/local/lib/python3.7/site-packages/pycox/evaluation/eval_surv.py in add_km_censor(self, steps)
    102         (durations, 1-events).
    103         """
--> 104         km = utils.kaplan_meier(self.durations, 1-self.events)
    105         surv = pd.DataFrame(np.repeat(km.values.reshape(-1, 1), len(self.durations), axis=1),
    106                             index=km.index)

/usr/local/lib/python3.7/site-packages/pycox/utils.py in kaplan_meier(durations, events, start_duration)
     63     ni = np.zeros(len(surv_idx), dtype='int')
     64     di = np.zeros_like(ni)
---> 65     di, ni = _group_loop(n, surv_idx, durations, events, di, ni)
     66     ni = n - ni.cumsum()
     67     ni[1:] = ni[:-1]

~/Library/Python/3.7/lib/python/site-packages/numba/core/dispatcher.py in _compile_for_args(self, *args, **kws)
    418                 e.patch_message(msg)
    419 
--> 420             error_rewrite(e, 'typing')
    421         except errors.UnsupportedError as e:
    422             # Something unsupported is present in the user code, add help info

~/Library/Python/3.7/lib/python/site-packages/numba/core/dispatcher.py in error_rewrite(e, issue_type)
    359                 raise e
    360             else:
--> 361                 raise e.with_traceback(None)
    362 
    363         argtypes = []

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
non-precise type array(pyobject, 1d, C)
During: typing of argument at /usr/local/lib/python3.7/site-packages/pycox/utils.py (33)

File "../../../../usr/local/lib/python3.7/site-packages/pycox/utils.py", line 33:
def _group_loop(n, surv_idx, durations, events, di, ni):
    idx = 0
    ^
havakv commented 2 years ago

Hi @hyunjaecho94 , probably not a numba bug. Could you post a minimal example the reproduce this error? And could you post your versiono of numba and python?

berkuva commented 2 years ago

Numba: 0.53.1 Python: 3.7

surv = build_surv() //custom built function

eval_surv = EvalSurv(surv=surv,
                     durations=my_durations,
                     events=my_events,
                     censor_surv='km',
                     censor_durations=my_durations)

All my data is uncensored, so durations and censor_durations are the same.

berkuva commented 2 years ago

The problem was that my_events was not all 1 despite duration and censor_durations were identical.