Skip to content

[RF] Deprecate RooMinuit class (adapter between RooFit and minuit, got replaced by the more general RooMinimizer)#8609

Merged
guitargeek merged 6 commits intoroot-project:masterfrom
guitargeek:__ROOFIT_NOROOMINIMIZER
Jul 6, 2021
Merged

[RF] Deprecate RooMinuit class (adapter between RooFit and minuit, got replaced by the more general RooMinimizer)#8609
guitargeek merged 6 commits intoroot-project:masterfrom
guitargeek:__ROOFIT_NOROOMINIMIZER

Conversation

@guitargeek
Copy link
Copy Markdown
Contributor

See commit descriptions.

This also includes an update of the reference file
`stressRooFit_ref.root`, because the fit results differed at the 6th
digit with the new RooMinimzer:

```
RooFitResult::isIdentical: constant parameter sigma_g2 differs in value:	4.18951 vs.	4.18946	(1.25945e-05)
RooFitResult::isIdentical: final parameter frac differs in value:	0.656146 vs.	0.65613	(2.51561e-05)
RooUnitTest ERROR: comparison of object RooFitResult::nll from result rf601_r2 fails comparison with counterpart in reference RooFitResult nll
Test 38 : Interactive Minuit.....................................FAILED
```
In particular, this means means removing the `OldMinuit` value for the
`Minimzer` command argument of `RooAbsPdf::fitTo()`.

A more general minimizer adapter class called `RooMinimizer` was
introduced in ROOT 5.24 (see commit 12389f7).

With ROOT 6.08, the new RooMinimizer became the default interface to
minuit in RooFit. Now, this commit removed the option to use the old
`RooMinuit` in `RooAbsPdf::fitTo()` for 6.24.
The code of the RooMinuit class is moved to the RooFitLegacy
subdirectories to clearly mark them as deprecated.
@guitargeek guitargeek self-assigned this Jul 5, 2021
@guitargeek guitargeek linked an issue Jul 5, 2021 that may be closed by this pull request
Copy link
Copy Markdown
Member

@hageboeck hageboeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I have a few more suggestions.

Comment on lines 71 to 77
// void setAlwaysStartFromMin(Bool_t flag) { _startFromMin = flag ; }
// Bool_t alwaysStartFromMin() const { return _startFromMin ; }

//RooMinuit* minuit() { return _minuit ; }
//RooMinimizer* minimizer() { return _minimizer ; }
RooAbsReal& nll() { return const_cast<RooAbsReal&>(_nll.arg()) ; }
// const RooArgSet& bestFitParams() const ;
// const RooArgSet& bestFitObs() const ;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe clean this up while you are at it ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all code that will just rot because it's never being compiled.

Comment on lines 112 to 118
TIterator* _oiter ; //! Iterator of profile likelihood output parameter(s)
*/

// mutable RooMinuit* _minuit ; //! Internal minuit instance
// mutable RooMinimizer* _minimizer ; //! Internal minimizer instance

// mutable Bool_t _absMinValid ; // flag if absmin is up-to-date
// mutable Double_t _absMin ; // absolute minimum of -log(L)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and here.

Comment on lines 1055 to 1062
/*
RooMsgService::instance().setGlobalKillBelow(RooFit::DEBUG) ;
profile->getVal();
RooMinuit* minuit = ((RooProfileLL*) profile)->minuit();
RooMinimizer* minuit = ((RooProfileLL*) profile)->minimizer();
minuit->setPrintLevel(5) ; // Print MINUIT messages
minuit->setVerbose(5) ; // Print RooMinuit messages with parameter
minuit->setVerbose(5) ; // Print RooMinimizer messages with parameter
// changes (corresponds to the Verbose() option of fitTo()
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and here.

Comment on lines 59 to 60
TIterator* _piter ; //! Iterator over profile likelihood parameters to be minimized
TIterator* _oiter ; //! Iterator of profile likelihood output parameter(s)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you see (mutable) iterator members that are not serialised (//!), that is almost always a sign that a range-based for loop or a counting loop should be used. Less members, faster, easier to understand.

Just saying, maybe for another day ...

Comment on lines +187 to +189
for(auto const& arg : obsSetOrig) {
auto var = dynamic_cast<RooRealVar*>(arg);
if(var == nullptr) break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern was used in a lot of old loops, and although it looks like a double check (both for checking that the loop isn't finished and that the type is correct), it's usually only checking if the loop is finished. In almost all cases, you can static_cast and run through the full collection. For good measure, I put an assert with a dynamic_cast into the loop. It brings extra debug info, and it doesn't cost anything in release builds.

Note also that if they were really checking the types, it wouldn't make any sense if you put {var, var, otherType, var} in a collection, because the last var would never be reached. That's most probably a bug.

Long story short: Those loops usually work with range-base and static_cast, and they will be much faster this way. Consider this as a standard way to modernise those kinds of loops (and make the var const whenever you can; here you can't). Also note that although auto const& looks like an awesome thing for "normal" collections, it's actually obfuscating the fact that you have a collection of pointers.

Suggested change
for(auto const& arg : obsSetOrig) {
auto var = dynamic_cast<RooRealVar*>(arg);
if(var == nullptr) break;
for(auto const arg : obsSetOrig) {
auto var = static_cast<RooRealVar*>(arg);
assert(dynamic_cast<RooRealVar*>(arg));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you want (I never went there), you can write an adapter that exposes a special kind of iterator:

for (auto const pvar : CastCollection<const RooRealVar*>(obsSetOrig) ) {
  pvar->GetName();
}

Maybe you can get some inspiration from #8421

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment! Very good point, I was too cautions here and didn't want to change the logic of the code. I'll do it now.

* use `std::unique_ptr`

* use range-based loops

* use overloads of `getObservables` and `getParameters that don't do
  heap allocation
@guitargeek guitargeek force-pushed the __ROOFIT_NOROOMINIMIZER branch from e144515 to 1bdeafd Compare July 5, 2021 16:38
@guitargeek
Copy link
Copy Markdown
Contributor Author

@phsft-bot build

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@root-project root-project deleted a comment from phsft-bot Jul 6, 2021
@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-07-06T10:20:00.007Z] CMake Error at /home/sftnight/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-2.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@guitargeek
Copy link
Copy Markdown
Contributor Author

@phsft-bot build (ne more round of tests now that pcepsft10 is fixed)

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-4.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-07-06T12:29:04.135Z] CMake Error at /mnt/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@guitargeek
Copy link
Copy Markdown
Contributor Author

Since the ROOT-ubuntu16 tests passed already in the previous round on a machine where it worked, we have now all the tested configurations passing.

@guitargeek guitargeek merged commit 0088755 into root-project:master Jul 6, 2021
@guitargeek guitargeek deleted the __ROOFIT_NOROOMINIMIZER branch July 6, 2021 13:40
@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-07-06T14:09:44.859Z] CMake Error at /home/sftnight/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-performance-centos8-multicore/default.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-07-06T14:32:50.932Z] CMake Error at /data/sftnight/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@phsft-bot
Copy link
Copy Markdown

Build failed on mac1014/python3.
Running on macitois21.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-07-06T15:47:36.425Z] CMake Error at /Volumes/HD2/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2021-07-06T16:37:18.021Z] CMake Error at C:/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft23.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-07-06T16:47:50.592Z] CMake Error at /Users/sftnight/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RF] Remove "No RooMinimizer" code paths.

3 participants