Skip to content

Commit

Permalink
unifying time measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
nadrino committed Jan 14, 2024
1 parent 59cc049 commit 4e88a0b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/Fitter/Engine/src/FitterEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void FitterEngine::readConfigImpl(){
});
GenericToolbox::Json::deprecatedAction(_config_, "mcmcConfig", [&]{
LogAlert << "mcmcConfig should now be set as minimizerConfig" << std::endl;
minimizerConfig = GenericToolbox::Json::fetchValue( _config_, "mcmcConfig" , JsonType() );
minimizerConfig = GenericToolbox::Json::fetchValue( _config_, "mcmcConfig" , minimizerConfig );
});
GenericToolbox::Json::deprecatedAction(_config_, "engineType", [&]{
LogAlert << "engineType should now be specified withing minimizerConfig/minimizerType" << std::endl;
Expand Down
6 changes: 1 addition & 5 deletions src/Fitter/Likelihood/include/JointProbability.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,4 @@ namespace JointProbability {
}






#endif //GUNDAM_JOINT_PROBABILITY_H
#endif // GUNDAM_JOINT_PROBABILITY_H
18 changes: 8 additions & 10 deletions src/Fitter/Minimizer/include/MinimizerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MinimizerBase : public JsonBaseClass {
virtual void calcErrors(){}
virtual void scanParameters( TDirectory* saveDir_ );
virtual double evalFit( const double* parArray_ );
virtual bool isErrorCalcEnabled() const { return false; }
[[nodiscard]] virtual bool isErrorCalcEnabled() const { return false; }

// c-tor
explicit MinimizerBase(FitterEngine* owner_) : _owner_(owner_) {}
Expand All @@ -44,8 +44,8 @@ class MinimizerBase : public JsonBaseClass {
void setDisableCalcError(bool disableCalcError_){ _disableCalcError_ = disableCalcError_; }

// const getters
bool disableCalcError() const{ return _disableCalcError_; }
int getMinimizerStatus() const { return _minimizerStatus_; }
[[nodiscard]] bool disableCalcError() const{ return _disableCalcError_; }
[[nodiscard]] int getMinimizerStatus() const { return _minimizerStatus_; }

// mutable getters
Monitor& getMonitor(){ return _monitor_; }
Expand All @@ -55,11 +55,10 @@ class MinimizerBase : public JsonBaseClass {
int getNbDegreeOfFreedom(){ return getLikelihoodInterface().getNbSampleBins() - _nbFreeParameters_; }

protected:

const FitterEngine& getOwner() const;
const Propagator& getPropagator() const;
const ParameterScanner& getParameterScanner() const;
const LikelihoodInterface& getLikelihoodInterface() const;
[[nodiscard]] const FitterEngine& getOwner() const;
[[nodiscard]] const Propagator& getPropagator() const;
[[nodiscard]] const ParameterScanner& getParameterScanner() const;
[[nodiscard]] const LikelihoodInterface& getLikelihoodInterface() const;

FitterEngine& getOwner();
Propagator& getPropagator();
Expand Down Expand Up @@ -88,8 +87,7 @@ class MinimizerBase : public JsonBaseClass {

GenericToolbox::Time::AveragedTimer<10> evalLlhTimer{};
GenericToolbox::Time::AveragedTimer<10> externalTimer{};
GenericToolbox::Time::CycleTimer itSpeed;
GenericToolbox::Time::CycleCounterClock itSpeedMon{"it"};
GenericToolbox::Time::AveragedTimer<1> iterationCounterClock{};

GenericToolbox::VariablesMonitor convergenceMonitor;

Expand Down
23 changes: 5 additions & 18 deletions src/Fitter/Minimizer/src/MinimizerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ void MinimizerBase::initializeImpl(){
_monitor_.historyTree->Branch("totalLikelihood", &getLikelihoodInterface().getBuffer().totalLikelihood);
_monitor_.historyTree->Branch("statLikelihood", &getLikelihoodInterface().getBuffer().statLikelihood);
_monitor_.historyTree->Branch("penaltyLikelihood", &getLikelihoodInterface().getBuffer().penaltyLikelihood);
_monitor_.historyTree->Branch("iterationSpeed", _monitor_.itSpeedMon.getCountSpeedPtr());
}

_monitor_.convergenceMonitor.addDisplayedQuantity("VarName");
Expand Down Expand Up @@ -137,7 +136,7 @@ double MinimizerBase::evalFit( const double* parArray_ ){
if( isGradientDescentStep ){

if( gradient.lastGradientFall == _monitor_.nbEvalLikelihoodCalls - 1 ){
LogWarning << "Overriding last gradient descent entry (minimizer adjusting step size...): ";
LogWarning << "Minimizer is adjusting the step size: ";
}
else{
gradient.stepPointList.emplace_back();
Expand All @@ -152,16 +151,7 @@ double MinimizerBase::evalFit( const double* parArray_ ){
}
if( _monitor_.convergenceMonitor.isGenerateMonitorStringOk() ){

_monitor_.itSpeedMon.cycle( _monitor_.nbEvalLikelihoodCalls - _monitor_.itSpeedMon.getCounts() );

if( _monitor_.itSpeed.counts != 0 ){
_monitor_.itSpeed.counts = _monitor_.nbEvalLikelihoodCalls - _monitor_.itSpeed.counts; // how many cycles since last print
_monitor_.itSpeed.cumulated = GenericToolbox::getElapsedTimeSinceLastCallInMicroSeconds("itSpeed"); // time since last print
}
else{
_monitor_.itSpeed.counts = _monitor_.nbEvalLikelihoodCalls;
GenericToolbox::getElapsedTimeSinceLastCallInMicroSeconds("itSpeed");
}
_monitor_.iterationCounterClock.count( _monitor_.nbEvalLikelihoodCalls );

std::stringstream ssHeader;
ssHeader << std::endl << __METHOD_NAME__ << ": call #" << _monitor_.nbEvalLikelihoodCalls;
Expand All @@ -182,10 +172,9 @@ double MinimizerBase::evalFit( const double* parArray_ ){
t << _monitor_.minimizerTitle << GenericToolbox::TablePrinter::NextLine;

t << "Speed" << GenericToolbox::TablePrinter::NextColumn;
t << _monitor_.itSpeedMon << GenericToolbox::TablePrinter::NextColumn;
// t << (double)_monitor_.itSpeed.counts / (double)_monitor_.itSpeed.cumulated * 1E6 << " it/s" << GenericToolbox::TablePrinter::NextColumn;
t << getPropagator().weightProp << GenericToolbox::TablePrinter::NextColumn;
t << getPropagator().fillProp << GenericToolbox::TablePrinter::NextColumn;
t << _monitor_.iterationCounterClock.calcCountSpeed() << " it/s" << GenericToolbox::TablePrinter::NextColumn;
t << getPropagator().reweightTimer << GenericToolbox::TablePrinter::NextColumn;
t << getPropagator().refillHistogramTimer << GenericToolbox::TablePrinter::NextColumn;
t << _monitor_.externalTimer << GenericToolbox::TablePrinter::NextLine;

ssHeader << t.generateTableString();
Expand Down Expand Up @@ -238,8 +227,6 @@ double MinimizerBase::evalFit( const double* parArray_ ){
true // force generate
);
}

_monitor_.itSpeed.counts = _monitor_.nbEvalLikelihoodCalls;
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/Fitter/Minimizer/src/SimpleMcmcInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,17 @@ void SimpleMcmcInterface::minimize() {
LogInfo << "Parameters in likelihood: " << _point_.size() << std::endl;

// Create the output tree for the accepted points.
TTree *outputTree = new TTree(_outTreeName_.c_str(),
auto *outputTree = new TTree(_outTreeName_.c_str(),
"Tree of accepted points");
outputTree->Branch("Points",&_point_);
outputTree->Branch("LLHPenalty",&_llhPenalty_);
outputTree->Branch("LLHStatistical",&_llhStatistical_);
outputTree->Branch("Models",&_saveModel_);
outputTree->Branch("ModelUncertainty",&_saveUncertainty_);

_monitor_.stateTitleMonitor = "Running MCMC chain...";
_monitor_.minimizerTitle = _algorithmName_ + "/" + _proposalName_;

// Run a chain.
int nbFitCallOffset = _monitor_.nbEvalLikelihoodCalls;
LogInfo << "Fit call offset: " << nbFitCallOffset << std::endl;
Expand All @@ -898,7 +901,7 @@ void SimpleMcmcInterface::minimize() {
LogInfo << "MCMC ended after " << nbMCMCCalls << " calls." << std::endl;

// Save the sampled points to the outputfile
if (outputTree) outputTree->Write();
outputTree->Write();

// success
_minimizerStatus_ = 0;
Expand Down
5 changes: 2 additions & 3 deletions src/Propagator/include/Propagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ class Propagator : public JsonBaseClass {
EventDialCache _eventDialCache_{};

public:
GenericToolbox::Time::CycleTimer dialUpdate;
GenericToolbox::Time::CycleTimer weightProp;
GenericToolbox::Time::CycleTimer fillProp;
GenericToolbox::Time::AveragedTimer<10> reweightTimer;
GenericToolbox::Time::AveragedTimer<10> refillHistogramTimer;

};
#endif //GUNDAM_PROPAGATOR_H
Expand Down
16 changes: 9 additions & 7 deletions src/Propagator/src/Propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,32 +502,34 @@ void Propagator::resetReweight(){
});
}
void Propagator::reweightMcEvents() {
reweightTimer.start();

bool usedGPU{false};
#ifdef GUNDAM_USING_CACHE_MANAGER
GenericToolbox::getElapsedTimeSinceLastCallInMicroSeconds(__METHOD_NAME__);
if(GundamGlobals::getEnableCacheManager()) {
if( GundamGlobals::getEnableCacheManager() ) {
Cache::Manager::Update(getSampleSet(), getEventDialCache());
usedGPU = Cache::Manager::Fill();
}
#endif
if( not usedGPU ){
GenericToolbox::getElapsedTimeSinceLastCallInMicroSeconds(__METHOD_NAME__);
if( not _devSingleThreadReweight_ ){ GundamGlobals::getParallelWorker().runJob("Propagator::reweightMcEvents"); }
else{ this->reweightMcEvents(-1); }
}
weightProp.counts++;
weightProp.cumulated += GenericToolbox::getElapsedTimeSinceLastCallInMicroSeconds(__METHOD_NAME__);

reweightTimer.stop();
}
void Propagator::refillSampleHistograms(){
GenericToolbox::getElapsedTimeSinceLastCallInMicroSeconds(__METHOD_NAME__);
refillHistogramTimer.start();

if( not _devSingleThreadHistFill_ ){
GundamGlobals::getParallelWorker().runJob("Propagator::refillSampleHistograms");
}
else{
refillSampleHistogramsFct(-1);
refillSampleHistogramsPostParallelFct();
}
fillProp.counts++; fillProp.cumulated += GenericToolbox::getElapsedTimeSinceLastCallInMicroSeconds(__METHOD_NAME__);

refillHistogramTimer.stop();
}

// Misc
Expand Down
2 changes: 1 addition & 1 deletion submodules/cpp-generic-toolbox

0 comments on commit 4e88a0b

Please sign in to comment.