Skip to content

Commit 5f7755e

Browse files
author
Kevin Dungs
committed
Major upgrade.
More documentation. Additional functionality and so on.
1 parent 0b3334e commit 5f7755e

File tree

5 files changed

+70
-35
lines changed

5 files changed

+70
-35
lines changed

__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# A small library that helps doing timing measurements.
2+
#
3+
# Author: Kevin Dungs <kevin.dungs@cern.ch>
4+
# Version: 2.0
5+
# Date: 2014-03-10

analysor.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
# Useful functions for analysing studies.
2+
# Helps by calculating means as ufloats.
13
#
2-
#
3-
#
4+
# Author: Kevin Dungs <kevin.dungs@cern.ch>
5+
# Version: 2.0
6+
# Date: 2014-03-10
47

58

69
def mean_and_error(xs):
7-
from scipy.stats import sem
8-
from uncertainties import ufloat
910
"""
1011
Calculate mean and SEM of a numpy array xs.
1112
1213
Returns a ufloat.
1314
"""
15+
from scipy.stats import sem
16+
from uncertainties import ufloat
1417
return ufloat(xs.mean(), sem(xs))
1518

1619

@@ -19,4 +22,8 @@ def means_and_errors(timings):
1922
return {
2023
key: mean_and_error(np.array([t[key] for t in timings]))
2124
for key in timings[0].keys()
22-
}
25+
}
26+
27+
28+
def total(timing):
29+
return sum(timing.values())

extractor.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# A small library that helps doing timing measurements.
1+
# Helpers for extracting information from logfiles generated from Gaudi output.
22
#
3-
# Author: Kevin Dungs <kevin.dungs@cern.ch>
4-
# Date: 2014-02-17
3+
# Author: Kevin Dungs <kevin.dungs@cern.ch>
4+
# Version: 2.0
5+
# Date: 2014-03-10
56

67

78
def timings_from_file(filename):
@@ -18,23 +19,24 @@ def timings_from_file(filename):
1819
))
1920

2021

21-
def extract_relevant(timings):
22+
def extract_relevant(timings, relevant=None):
2223
"""
2324
Extract relevant information from a timing dictionary that has been
2425
obtained from timings_from_file().
2526
"""
26-
relevant = { # Relevant information, list elements are summed over.
27-
'VELO tracking': ['FstVPDecoding', 'FstPixel'],
28-
'PV finding': ['HltPVsPV3D'],
29-
'VELO-UT tracking': ['CreateUTLiteClusters', 'PrVeloUT'],
30-
'Forward tracking': ['FTRawBankDecoder', 'FstForward'],
31-
}
27+
if not relevant:
28+
relevant = { # Relevant information, list elements are summed over.
29+
'VELO tracking': ['FstVPDecoding', 'FstPixel'],
30+
'PV finding': ['HltPVsPV3D'],
31+
'VELO-UT tracking': ['CreateUTLiteClusters', 'PrVeloUT'],
32+
'Forward tracking': ['FTRawBankDecoder', 'FstForward'],
33+
}
3234
return {k: sum(float(timings[t]) for t in v) for k, v in relevant.items()}
3335

3436

35-
def extract_multiple(filenames):
37+
def extract_multiple(filenames, relevant=None):
3638
"""
3739
For a list of filenames, extracts the relevant information from them and
3840
returns a list of dictionaries containing the timings.
39-
"""
40-
return [extract_relevant(timings_from_file(f)) for f in filenames]
41+
"""
42+
return [extract_relevant(timings_from_file(f), relevant) for f in filenames]

printor.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
# Prints a readymade LaTeX table of a timing study for use in publications.
12
#
2-
#
3-
#
3+
# Author: Kevin Dungs <kevin.dungs@cern.ch>
4+
# Version: 2.0
5+
# Date: 2014-03-10
6+
47

58
def latex(study, significant_digits=None):
9+
from TimingTools import analysor
10+
formatstring = '{:L}'
11+
if significant_digits:
12+
formatstring = '{:.' + str(significant_digits) + 'L}'
613
for k, v in study.items():
7-
if significant_digits:
8-
print(('{} & {:' + str(significant_digits) + 'L}').format(
9-
k.ljust(30), v
10-
))
11-
else:
12-
print('{} & {:L}'.format(k.ljust(30), v))
14+
print(('{} & ' + formatstring).format(k.ljust(30), v))
15+
print(('{} & ' + formatstring).format('Total'.ljust(30), analysor.total(study)))

study.py

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1+
# Quickly load whole studies.
12
#
2-
#
3-
#
3+
# Author: Kevin Dungs <kevin.dungs@cern.ch>
4+
# Version: 2.0
5+
# Date: 2014-03-10
46

57

6-
def load_study(path, runs=10):
7-
"""
8+
def load_study(path, runs=10, prefix='', relevant=None):
9+
""" Load a study from {path} with {runs} runs.
10+
Additional dictionary of {relevant} algorithms can be used and is
11+
passed to the extractor.
812
"""
913
from os.path import join
10-
import analysor
11-
import extractor
12-
return analysor.means_and_errors(extractor.extract_multiple(
13-
[join(path, '{}.log'.format(i)) for i in range(1, runs+1)]
14-
))
14+
from TimingTools import (
15+
analysor,
16+
extractor
17+
)
18+
return extractor.extract_multiple(
19+
[join(path, '{}{}.log'.format(prefix, i)) for i in range(1, runs+1)],
20+
relevant
21+
)
22+
23+
24+
def load_means(path, runs=10, prefix='', relevant=None):
25+
""" Load the means for a study from {path} with {runs} runs.
26+
Additional dictionary of {relevant} algorithms can be used and is
27+
passed to the extractor.
28+
"""
29+
from TimingTools import (
30+
analysor
31+
)
32+
return analysor.means_and_errors(load_study(path, runs, prefix, relevant))

0 commit comments

Comments
 (0)