Home | News | Documentation | Download

Python *** Break *** abort

Hello.
I run fitting with minuit in python, at some stage program crashes with error:

#7  0x00007f081354d387 in raise () from /lib64/libc.so.6
#8  0x00007f081354ea78 in abort () from /lib64/libc.so.6
#9  0x00007f08048157d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#10 0x00007f0804813746 in ?? () from /lib64/libstdc++.so.6
#11 0x00007f0804813773 in std::terminate() () from /lib64/libstdc++.so.6
#12 0x00007f0804813993 in __cxa_throw () from /lib64/libstdc++.so.6
#13 0x00007f07edcdcc6f in ?? ()
#14 0x00007ffe7abea680 in ?? ()
#15 0x000000000dab4080 in ?? ()
#16 0x0000000000000000 in ?? ()

Please, advise what’s wrong.
I did not experience any problems with my code in Python 2.6 with ROOT 5.34.

ROOT Version: 6.22/02
Platform: CentOS Linux 7 (Core)
Compiler: Not Provided
It’s CERN Lxplus machine.

Hello @kot,

Can you please send us a copy of your code in order to try to reproduce your error? Also, please, can you tell us the Python version that you are using.

Cheers,
J.

Hello, @jalopezg
I found the reason of the crash is an attempt to save a dictionary with TF1 functions which are required for further usage. I use python 2.7.5, which is called by default with python2 at Lxplus.

The code sample is given below

import ROOT
import numpy as np
import shelve


class eff:
    def __call__(self, x, par):
        return par[1] * exp0(x[0], par[0])

def exp0(x, par):
    return np.exp(-x * par)

def fit(x_min, x_max, n_pars):
    amp, alpha = 10, 1
    func_dct = {}
    # workaround with creation of python callable: https://root-forum.cern.ch/t/th1-fit-method-error/40895
    instance = eff()
    for j in range(2):
        key = 'key'+str(j)
        func_dct[key] = ROOT.TF1('func name ' + key, instance, 
        x_min, x_max, n_pars) 
        func_dct[key].SetParameter(0, amp)
        func_dct[key].SetParameter(1, alpha)
    return func_dct


if __name__ == '__main__':
    x_min, x_max = 0, 5
    n_pars = 2
    func_dct = fit(x_min, x_max, n_pars)
    ses = shelve.open('filename','n')
    # crashes here
    ses['res'] = func_dct
    ses.close()

Hello @kot,

I think @etejedor may have an answer for this issue.

Cheers,
J.

Hi @kot,
it seems that pickling a PyROOT proxy to a TF1 (which is a C++ object) that uses a python functor as its expression is just too much magic, although I can’t tell what goes wrong exactly.

Best guess: instance has already gone out of scope when the TF1 is pickled/shelved.
Keeping it alive resolves the crash (not 100% sure everything is written to file as you want, but that’s easily verified):

def fit(x_min, x_max, n_pars):                                                                                          
    amp, alpha = 10, 1                                                                                                  
    func_dct = {}                                                                                                       
    # workaround with creation of python callable: https://root-forum.cern.ch/t/th1-fit-method-error/40895              
    instance = eff()                                                                                                    
    for j in range(2):                                                                                                  
        key = 'key'+str(j)                                                                                              
        func_dct[key] = ROOT.TF1('func name ' + key, "sin(x)",·                                                         
        x_min, x_max, n_pars)·                                                                                          
        func_dct[key].SetParameter(0, amp)                                                                              
        func_dct[key].SetParameter(1, alpha)                                                                            
    return func_dct, instance # RETURN instance TOO!!                 
                                                                                                                        
                                                                                                                        
if __name__ == '__main__':                                                                                              
    x_min, x_max = 0, 5                                                                                                 
    n_pars = 2                                                                                                          
    func_dct, inst = fit(x_min, x_max, n_pars)                                                                          
    ses = shelve.open('filename','n')                                                                                   
    print("ok")                                                                                                         
    # crashes here                                                                                                      
    ses['res'] = func_dct                                                                                               
    print("ok")                                                                                                         
    ses.close() 

Cheers,
Enrico

Dear Enrico,

Thank you for the workaround!
TF1 objects have been saved and then read correctly.

Best regards,
Alex

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.