Skip to content

Commit

Permalink
Added isReadOnlySys option for evaluation
Browse files Browse the repository at this point in the history
- Added `isReadOnlySys` option, usable for evaluation only. One may set `isReadOnlySys = Ture` while using the python wrapper, in order to avoid writing anything to disk during evaluation.
  • Loading branch information
IftachSadeh committed Nov 16, 2018
1 parent 4146fec commit bfd6614
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Changelog

## Master version (22/05/2018)
## Master version (16/11/2018)

- Updated `py/ANNZ.py` and `scripts/annz_evalWrapper.py` for `python-3.6` compatibility.

- Fixed bug in the `Makefile`; now ROOT shared libraries are linked *after* the local objects.

- Added `isReadOnlySys` option, usable for evaluation only. One may set `isReadOnlySys = Ture` while using the python wrapper, in order to avoid writing anything to disk during evaluation.

## ANNZ v2.3.0 (03/04/2018)

### For users:
Expand Down
5 changes: 4 additions & 1 deletion examples/scripts/annz_evalWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def init(testType, opts):
opts['doRegression'] = False
opts['doClassification'] = False

# can run evaluation within a read-only system, by setting isReadOnlySys
# opts['isReadOnlySys'] = True

# --------------------------------------------------------------------------------------------------
# can work with single-regression, eg:
# --------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -149,7 +152,7 @@ def init(testType, opts):
if testType == 'doRandomCls':
opts['doClassification'] = True
opts['doRandomCls'] = True
opts["outDirName"] = "test_randCls_advanced"
opts["outDirName"] = "test_randCls_quick"

# --------------------------------------------------------------------------------------------------
# list of parameter types and parameter names - THIS MUST INCLUDE any parameter
Expand Down
6 changes: 4 additions & 2 deletions src/ANNZ_err.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ void ANNZ::setupKdTreeKNN(
// setup the factory
// -----------------------------------------------------------------------------------------------------------
TString outFileNameTrain = getKeyWord(MLMname,"knnErrXML","outFileNameKnnErr");
knnErrOutFile = new TFile(outFileNameTrain,"RECREATE");
knnErrFactory = new TMVA::Factory(typeANNZ, knnErrOutFile, (TString)verbLvlF+drawProgBarStr+transStr+analysType);
if(glob->GetOptB("isReadOnlySys")) knnErrOutFile = NULL;
else knnErrOutFile = new TFile(outFileNameTrain,"RECREATE");

knnErrFactory = new TMVA::Factory(typeANNZ, knnErrOutFile, (TString)verbLvlF+drawProgBarStr+transStr+analysType);

#if ROOT_TMVA_V0
typedef TMVA::Factory def_dataLoader;
Expand Down
4 changes: 2 additions & 2 deletions src/ANNZ_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void ANNZ::Init() {
if(glob->GetOptB("doOnlyKnnErr")) trainingNeeded = false;

// initialize the outputs with the training directory and reset it
if(trainingNeeded) {
if(trainingNeeded && !glob->GetOptB("isReadOnlySys")) {
outputs->InitializeDir(glob->GetOptC("outDirNameFull"),glob->GetOptC("baseName"));
}
glob->NewOptB("trainingNeeded",trainingNeeded);
Expand All @@ -602,7 +602,7 @@ void ANNZ::Init() {

// save the final configuration options to file
// -----------------------------------------------------------------------------------------------------------
bool saveConfig = ( (glob->GetOptB("doTrain") && trainingNeeded) || !glob->GetOptB("doTrain") );
bool saveConfig = ( ( (glob->GetOptB("doTrain") && trainingNeeded) || !glob->GetOptB("doTrain") ) && !glob->GetOptB("isReadOnlySys") );
if(saveConfig) {
TString saveFileName = getKeyWord("","baseConfig","current");
aLOG(Log::INFO)<<coutYellow<<" - Saving run information in "<<coutGreen<<saveFileName<<coutYellow<<" ..."<<coutDef<<endl;
Expand Down
8 changes: 8 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ vector<TString> Utils::splitStringByChar(TString s, char delim) {
void Utils::safeRM(TString cmnd, bool verbose, bool checkExitStatus) {
// ===================================================================

if(glob->GetOptB("isReadOnlySys")) {
if(verbose) aLOG(Log::INFO) <<coutGreen<<" - isReadOnlySys is true, will not remove: "
<<coutPurple<<cmnd<<coutDef<<endl;
return;
}

checkCmndSafety(cmnd);
int sysReturn = exeShellCmndOutput((TString)"rm -rf "+cmnd,verbose,false);

Expand Down Expand Up @@ -293,6 +299,8 @@ void Utils::checkPathPrefix(TString pathName) {
// ===========================================================================================================
void Utils::resetDirectory(TString OutDirName, bool verbose, bool copyCode) {
// ==========================================================================
VERIFY(LOCATION,(TString)"Trying use Utils::resetDirectory() together with isReadOnlySys ... something is horribly wrong ?!?!" ,!glob->GetOptB("isReadOnlySys"));

if(glob->OptOrNullB("debugSysCmnd")) verbose = true;
if(glob->OptOrNullB("copyCodeToOutDir")) copyCode = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void Wrapper::Init(int argc, char ** argv) {
utils = aManager->utils;
glob = aManager->glob;
outputs = aManager->outputs;

aANNZ = new ANNZ("aANNZ"+name,utils,glob,outputs);
aANNZ->aRegEval = new RegEval("aRegEval"+name,utils,glob,outputs);

Expand Down
10 changes: 10 additions & 0 deletions src/myANNZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ Manager::Manager() {
glob->NewOptI("initSeedRnd" ,1979); // some random number so that the same set of randoms are chosen each time the code is run
glob->NewOptB("doStoreToAscii" ,true); // store evaluation into ascii files
glob->NewOptI("minObjTrainTest" ,50); // minimal number of objects to use for training (very dangerous to set this too low !!!!)
glob->NewOptB("isReadOnlySys" ,false); // allow evalWrapper to be run on a read-only system

// number of times to divide the collection of MLMs needed for evaluation - in principle, no division is neccessary, however,
// some MLMs (notabley BDTs) require a lot of memory. Therefore, it might be better to only evaluate a sub-sample of the MLMs
Expand Down Expand Up @@ -914,6 +915,15 @@ void Manager::Init(int argc, char ** argv) {
}
}

// verify that isReadOnlySys can be enabled only together with doEval
if(glob->GetOptB("isReadOnlySys") && !glob->GetOptB("doEval")) {
glob->SetOptB("isReadOnlySys" ,false);

aLOG(Log::WARNING) <<coutRed<<" - Found [\"isReadOnlySys\" = "<<coutPurple<<"true"
<<coutRed<<"] which can only be used together with \"doEval\""<<coutDef<<endl;
}


// print out final init parameters
if(inLOG(Log::DEBUG)) { glob->printOpts(2,30); cout<<endl; }

Expand Down

0 comments on commit bfd6614

Please sign in to comment.