Error calling Migrad in python

I am getting the following error:

TypeError: int TMinuit::Migrad() =>
    TypeError: callable was deleted

when calling:

import ROOT
gMinuit = ROOT.TMinuit(10)
# setup the function, etc...

This is with Root 6.22, and worked fine with Root 6.18 and previously for many years.

_ROOT Version: 6.22
_Platform: Mac (MacPorts)
Compiler: Not Provided

Hi @roodman,

Could you please send us a minimal code excerpt that we can use to reproduce the problem? Other than that, I am sure @moneta can help with this.


I would recommend not to use TMinuit, but the ROOT::Math::Minimizer class. It should work fine in Python. A C++ example is here: ROOT: tutorials/fit/NumericalMinimization.C File Reference


Thanks for the responses - with further searching around this forum, I found the issue. As of Root 6.22 the types of the arguments in a TMinuit FCN function changed from TROOT types to python ctypes.

I had:

def chisq(self,npar, gin, f, par, iflag ):
    ... calculate stuff
    f[0] = chisquared

but this needs to change to:

    f.value = chisquared


Hi again,

I am still having problems with this issue - calling a TMinuit function from within Python.

I can get this to work in a simple example, when the FCN is just defined as a standalone function in Python. But my actual code sets up the fit and the fit FCN inside a Python Class, and in that case I am still getting the

TypeError: int TMinuit::Migrad() =>TypeError: callable was deleted

error. I am hoping to find a solution that does not require me to rewrite a lot of my code, or change to do a different interface.

Attached I have two test scripts - works fine, while with the FCN in a class gives the error. I am running root 6.24.00 and python 3.8

Thanks very much for your help!

Aaron (785 Bytes) (1.2 KB)

Also in C++ you cannot pass class member functions to TMinuit. You would need to use th MInimizer class where you can pass a functor object as function to be minimized.


This topic was automatically closed after 13 days. New replies are no longer allowed.