Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] [minuit] FPE/crash in Minuit2 #6775

Closed
andriish opened this issue Nov 8, 2020 · 3 comments · Fixed by #10492
Closed

[bug] [minuit] FPE/crash in Minuit2 #6775

andriish opened this issue Nov 8, 2020 · 3 comments · Fixed by #10492

Comments

@andriish
Copy link
Contributor

andriish commented Nov 8, 2020

Describe the bug

FPE when calling Simplex with no free parameters.

Expected behavior

No FPE/crash

To Reproduce

simplex.cxx

#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnPrint.h"
#include "Minuit2/MnMigrad.h"
#include "Minuit2/MnSimplex.h"
#include "Minuit2/FCNBase.h"

#include <fenv.h>


using namespace ROOT::Minuit2;

class TestChi2 : public ROOT::Minuit2::FCNBase
{
public:
    TestChi2() {}
    ~TestChi2() {}
    virtual double Up() const {return 1.0;}
    virtual double operator () (const std::vector<double> &a) const
    {
        return std::pow(a.at(0)-0.11,2)+std::pow(a.at(1)-0.5,2)/100.0;
    }
};

int main(int argc, char ** argv)
{
     feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
     MnUserParameters fit_parameters;
     fit_parameters.Add("A",0.118,0.01,0,1);
     fit_parameters.Add("B",0.5,0.1,0.1,100.0);
     fit_parameters.Fix("A");
     fit_parameters.Fix("B");
     TestChi2* FULL= new TestChi2();
     MnUserParameters temp_fit_parameters=fit_parameters;
     MnMigrad migrad0(*FULL, temp_fit_parameters);           
     FunctionMinimum min_migrad0 = migrad0();                // OK
     MnSimplex simplex0(*FULL, temp_fit_parameters);
     FunctionMinimum min_simplex0 = simplex0();              // FPE
     exit(0);
}
g++ simplex.cc -o simplex.exe  $(root-config --glibs --cflags)  -lMinuit2
./simplex.exe

results in

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  ROOT::Minuit2::SimplexBuilder::Minimum (this=0x7ffcf9555c58, mfcn=..., seed=..., maxfcn=200, minedm=0.10000000000000001) at /usr/src/debug/root-6.22.02/math/minuit2/src/SimplexBuilder.cxx:48
#6  0x00007f045c93e1cd in ROOT::Minuit2::ModularFunctionMinimizer::Minimize (this=<optimized out>, mfcn=..., gc=..., seed=..., strategy=..., maxfcn=200, toler=<optimized out>) at /usr/src/debug/root-6.22.02/math/minuit2/src/ModularFunctionMinimizer.cxx:166
#7  0x00007f045c93c737 in ROOT::Minuit2::ModularFunctionMinimizer::Minimize (this=0x7ffcf9555c48, fcn=..., st=..., strategy=..., maxfcn=200, toler=0.10000000000000001) at /usr/src/debug/root-6.22.02/math/minuit2/src/ModularFunctionMinimizer.cxx:120
#8  0x00007f045c905c51 in ROOT::Minuit2::MnApplication::operator() (this=0x7ffcf9555b00, maxfcn=200, toler=0.10000000000000001) at /usr/src/debug/root-6.22.02/math/minuit2/src/MnApplication.cxx:57
#9  0x000000000041068c in main ()
===========================================================

Setup

CentOS7/gcc-4.8.5 root 6.22 from EPEL

Additional context

Not a personal priority of me, so it is unlikely that I will provode a patch in the next days.
However, I can briefly describe how the FPE occurs.
It occurs on line 48 in SimplexBuilder when all parameters are fixed and 1./double(n) is always 1/0. So it is just plain crash, not an FPE.
To avoid it the Simplex builder should not be called for the case when there are no free parameters but instead, ModularFunctionMinimizer::Minimize() should call FCn just once and return "current state".

And yes, just preempting a question about a fit with zero free parameters. Yes, it is very useful.
Imagine a set of different models fitted to the data using the same codebase. Some models have 2 free parameters, others 3, but some have 0. And for the last category because if this bug one cannot use simplex from ROOT. (I use migrad).

@andriish
Copy link
Contributor Author

Hi @eguiraud ,

this is still present in 6.26.

Andrii

@eguiraud
Copy link
Member

Hi @andriish , that is likely expected as the issue is still open. It is a question for @lmoneta what the strategy here is, let's ping him.

@andriish
Copy link
Contributor Author

andriish commented May 8, 2023

Present in 6.28

guitargeek pushed a commit to andriish/root that referenced this issue Sep 27, 2023
@guitargeek guitargeek assigned guitargeek and unassigned lmoneta Sep 27, 2023
guitargeek added a commit to andriish/root that referenced this issue Sep 27, 2023
This avoids the problems when running simplex with zero parameters
reported in root-project#6775.
guitargeek added a commit that referenced this issue Sep 27, 2023
This avoids the problems when running simplex with zero parameters
reported in #6775.
maksgraczyk pushed a commit to maksgraczyk/root that referenced this issue Jan 12, 2024
This avoids the problems when running simplex with zero parameters
reported in root-project#6775.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants