Skip to content

Commit

Permalink
1. add meaningful description argument to all progress_bar instance
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Oct 8, 2024
1 parent d3a3c9e commit 1b70b2e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 24 deletions.
3 changes: 2 additions & 1 deletion ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
1. implement tests for USTAT & DNN
1. prepend the default progress-bar for trees/datasets/frames with `Entries:`
1. add a kind of replacement of `ROOT.RooAbsCollection.assign` for old versions of ROOT

1. add meaningful `description` argument to all `progress_bar` instance

## Backward incompatible

## Bug fixes
Expand Down
4 changes: 2 additions & 2 deletions ostap/fitting/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _rad_loop_ ( dataset ,

## loop over dataset
source = range ( first , last )
if progress : source = progress_bar ( source )
if progress : source = progress_bar ( source , description = 'Entries:' )

nevents = 0
for event in source :
Expand Down Expand Up @@ -2754,7 +2754,7 @@ def ds_to_csv ( dataset , fname , vars = () , more_vars = () , weight_var = '' ,
writer.writerow ( vnames )

## loop over entries in the dataset
for entry, _ in progress_bar ( dataset , max_value = len ( dataset ) , silent = not progress ) :
for entry, _ in progress_bar ( dataset , max_value = len ( dataset ) , silent = not progress , description = 'Entries:' ) :

values = [ entry [ a ].getVal() for a in vnames1 ]
values += [ v.getVal() for v in mvars ]
Expand Down
4 changes: 2 additions & 2 deletions ostap/fitting/ds2numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def ds2numpy ( dataset ,
nmax = max ( nevts // 6 , 30000 // nvars )

## get data is chunks/batches
for first, last in progress_bar ( split_range ( 0 , nevts , nmax ) , silent = silent ) :
for first, last in progress_bar ( split_range ( 0 , nevts , nmax ) , silent = silent , description = 'Chunks:' ) :

num = last - first
wget = False
Expand Down Expand Up @@ -387,7 +387,7 @@ def ds2numpy ( dataset ,
data = np.zeros ( len ( dataset ) , dtype = dtypes )

## make an explict loop:
for i , item in enumerate ( progress_bar ( dataset , silent = silent ) ) :
for i , item in enumerate ( progress_bar ( dataset , silent = silent ) , description = 'Entries:' ) :

evt, the_weight = item

Expand Down
4 changes: 2 additions & 2 deletions ostap/fitting/pdfbasic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ def graph_nll ( self ,
vmin = None
with SETPARS ( self , dataset ) , SETVAR ( var ) :
from ostap.utils.progress_bar import progress_bar
for v in progress_bar ( values , silent = silent ) :
for v in progress_bar ( values , silent = silent , description = 'Points:' ) :
var.setVal ( v )
n = nLL.getVal()
res = v , n
Expand Down Expand Up @@ -1458,7 +1458,7 @@ def graph_profile ( self ,
results = []
with SETPARS ( self , dataset ) , RangeVar ( var , minv , maxv ) , SETVAR ( var ) :
from ostap.utils.progress_bar import progress_bar
for i , v in enumerate ( progress_bar ( vals , silent = silent ) ) :
for i , v in enumerate ( progress_bar ( vals , silent = silent , description = 'Points:' ) ) :
var.setVal ( v )
p = pLL.getVal()
res = v , p
Expand Down
10 changes: 6 additions & 4 deletions ostap/fitting/pyselectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,9 @@ def process_entry ( self ):
self.logger.info ( "Selector(%s): processing TChain('%s') #entries: %d" % ( self.name , tree.GetName() , self.total ) )
## decoration:
from ostap.utils.progress_bar import ProgressBar
self.__progress = ProgressBar ( max_value = self.total ,
silent = self.silence )
self.__progress = ProgressBar ( max_value = self.total ,
description = 'Entries:' ,
silent = self.silence )
if not self.silence :

evnt = self.event ()
Expand Down Expand Up @@ -1409,8 +1410,9 @@ def SlaveBegin ( self , tree ) :
self.logger.info ( "Selector(%s): processing TChain('%s') #entries: %d" % ( self.name , tree.GetName() , self.total ) )
## decoration:
from ostap.utils.progress_bar import ProgressBar
self.__progress = ProgressBar ( max_value = self.total ,
silent = self.silence )
self.__progress = ProgressBar ( max_value = self.total ,
description = 'Entries:' ,
silent = self.silence )

if self.__progress and not self.silence :
self.__progress.update_amount ( self.event () )
Expand Down
4 changes: 2 additions & 2 deletions ostap/fitting/roostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,12 +1491,12 @@ def scan_with_progress ( self , *values ) :

elif 1 == len ( values ) and isinstance ( values [ 0 ] , sequence_types ) :

for v in progress_bar ( values [ 0 ] ) :
for v in progress_bar ( values [ 0 ] , description = 'Scan:' ) :
self.__inverter.RunOnePoint ( v )

else :

for v in progress_bar ( values ) :
for v in progress_bar ( values , description = 'Scan:' ) :
self.__inverter.RunOnePoint ( v )

@property
Expand Down
16 changes: 10 additions & 6 deletions ostap/fitting/toys.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def make_toys ( pdf ,

## run pseudoexperiments
from ostap.utils.progress_bar import progress_bar
for i in progress_bar ( range ( nToys ) , silent = not progress ) :
for i in progress_bar ( range ( nToys ) , silent = not progress , description = 'Toys:' ) :

## 1. reset PDF parameters
pdf.load_params ( params = fix_pars , silent = True ) ## silent = silent )
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def make_toys2 ( gen_pdf , ## pdf to generate toys

## run pseudoexperiments
from ostap.utils.progress_bar import progress_bar
for i in progress_bar ( range ( nToys ) , silent = not progress ) :
for i in progress_bar ( range ( nToys ) , silent = not progress , description = 'Toys:' ) :

## 1. reset PDF parameters
gen_pdf.load_params ( params = fix_gen_init , silent = True ) ## silent = silent )
Expand Down Expand Up @@ -1235,7 +1235,10 @@ def make_jackknife ( pdf ,
NN = 0
from ostap.utils.progress_bar import progress_bar
## run jackknife bootstrapping
for i , ds in progress_bar ( enumerate ( data.jackknife ( begin , end ) ) , max_value = end - begin , silent = not progress ) :
for i , ds in progress_bar ( enumerate ( data.jackknife ( begin , end ) ) ,
max_value = end - begin ,
description = 'Sample:' ,
silent = not progress ) :

## 2. reset parameters of fit_pdf
pdf.load_params ( params = fix_fit_init , silent = True ) ## silent = silent )
Expand Down Expand Up @@ -1359,7 +1362,7 @@ def make_bootstrap (
fit_fun = None , ## fit function ( pdf , dataset , **fit_config )
accept_fun = None , ## accept function ( fit-result, pdf, dataset )
silent = True , ## silent processing?
progress = True , ## shpow progress bar?
progress = True , ## show progress bar?
logger = logger , ## use this logger
frequency = 500 ) :

Expand Down Expand Up @@ -1445,8 +1448,9 @@ def make_bootstrap (
from ostap.utils.progress_bar import progress_bar
## run bootstrapping
for i , ds in progress_bar ( enumerate ( data.bootstrap ( size , extended = extended ) ) ,
max_value = size ,
silent = not progress ) :
max_value = size ,
description = 'Sample:' ,
silent = not progress ) :

## 2. reset parameters of fit_pdf
pdf.load_params ( params = fix_fit_init , silent = True ) ## silent = silent )
Expand Down
2 changes: 1 addition & 1 deletion ostap/histos/histos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4764,7 +4764,7 @@ def _smear_ ( h1 , sigma , addsigmas = 5 , silent = True ) :

xmax = bin[0].value()+bin[0].error()

for ibin1 in progress_bar ( bins , silent = silent ) :
for ibin1 in progress_bar ( bins , silent = silent , description = 'Bins:' ) :

x1c = ibin1 [0].value ()
x1w = 2 * ibin1 [0].error ()
Expand Down
8 changes: 4 additions & 4 deletions ostap/trees/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _tc_call_ ( tree , first = 0 , last = LAST_ENTRY , cuts = None , progress =
else : ## trivial loop

## explicit loop over entries
for entry in progress_bar ( range ( firts , last ) , silent = not progress ) :
for entry in progress_bar ( range ( firts , last ) , silent = not progress , description = 'Entries:' ) :

ievt = tree.GetEntryNumber ( entry )

Expand Down Expand Up @@ -313,7 +313,7 @@ def _tt_rows_ ( tree , variables , cuts = '' , first = 0 , last = LAST_ENTRY , p

else : ## trivial loop

for event in progress_bar ( range ( first, last ) , silent = not progress ) :
for event in progress_bar ( range ( first, last ) , silent = not progress , description = 'Entries:' ) :

tt = getter.tree()

Expand Down Expand Up @@ -1744,7 +1744,7 @@ def _chain_add_new_branch ( chain ,
keep = name , function

import ostap.io.root_file
for fname in progress_bar ( files , len ( files ) , silent = not chain_verbose ) :
for fname in progress_bar ( files , len ( files ) , silent = not chain_verbose , description = 'Files:' ) :

logger.debug ('Add_new_branch: processing file %s' % fname )
with ROOT.TFile.Open ( fname , 'UPDATE' , exception = True ) as rfile :
Expand Down Expand Up @@ -1816,7 +1816,7 @@ def _chain_add_new_branch_array ( chain ,
tree_verbose = verbose and len ( files ) < 5
chain_verbose = verbose and 5 <= len ( files )

for i , fname in enumerate ( progress_bar ( files , len ( files ) , silent = not chain_verbose ) ) :
for i , fname in enumerate ( progress_bar ( files , len ( files ) , silent = not chain_verbose , description = 'Files:' ) ) :

logger.debug ('Add_new_branch: processing file %s' % fname )
with ROOT.TFile.Open ( fname , 'UPDATE' , exception = True ) as rfile :
Expand Down

0 comments on commit 1b70b2e

Please sign in to comment.