Skip to content

Commit

Permalink
suggestion for addidn total times for all estimators
Browse files Browse the repository at this point in the history
  • Loading branch information
nbassler committed Apr 19, 2023
1 parent 4cdc8b9 commit 921e4e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pymchelper/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def __init__(self):
self.z = self.x

self.number_of_primaries = 0 # number of histories simulated
self.run_time = 0 # runtime in seconds
self.run_time_sim = 0 # run time in seconds excluding initialization header
self.total_number_of_primaries = 0 # number of histories simulated
self.total_run_time = 0 # runtime in seconds
self.total_run_time_sim = 0 # run time in seconds excluding initialization header
self.file_counter = 0 # number of files read
self.file_corename = "" # common core for paths of contributing files
self.file_format = "" # binary file format of the input files
Expand Down Expand Up @@ -131,9 +136,17 @@ def average_with_nan(estimator_list, error_estimate=ErrorEstimate.stderr):
# TODO add compatibility check
if not estimator_list:
return None

result = copy.deepcopy(estimator_list[0])

for n, estimator in enumerate(estimator_list, start=2):
result.total_number_of_primaries += estimator.number_of_primaries
result.total_run_time += estimator.run_time
result.total_run_time_sim += estimator.run_time_sim

for page_no, page in enumerate(result.pages):
page.data_raw = np.nanmean([estimator.pages[page_no].data_raw for estimator in estimator_list], axis=0)

result.file_counter = len(estimator_list)
if result.file_counter > 1 and error_estimate != ErrorEstimate.none:
# s = stddev = sqrt(1/(n-1)sum(x-<x>)**2)
Expand Down
4 changes: 4 additions & 0 deletions pymchelper/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def fromfilelist(input_file_list, error=ErrorEstimate.stderr, nan: bool = True):
# loop over all files with n running from 2
for n, filename in enumerate(input_file_list[1:], start=2):
current_estimator = fromfile(filename) # x
print("filename", filename, n)
result.total_number_of_primaries += current_estimator.number_of_primaries
result.total_run_time += current_estimator.run_time
result.total_run_time_sim += current_estimator.run_time_sim

# Running variance algorithm based on algorithm by B. P. Welford,
# presented in Donald Knuth's Art of Computer Programming, Vol 2, page 232, 3rd edition.
Expand Down
2 changes: 2 additions & 0 deletions pymchelper/readers/shieldhit/binary_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ class SHBDOTagID(IntEnum):
SHBDOTagID.user: 'user',
SHBDOTagID.host: 'host',
SHBDOTagID.rt_nstat: 'number_of_primaries',
SHBDOTagID.rt_time: 'run_time',
SHBDOTagID.rt_timesim: 'run_time_sim',
SHBDOTagID.number_of_pages: 'page_count',
SHBDOTagID.geo_unit_ids: 'geo_unit_ids',
SHBDOTagID.geo_units: 'geo_units',
Expand Down
3 changes: 3 additions & 0 deletions pymchelper/readers/shieldhit/reader_bdo2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def read_data(self, estimator, nscale=1):
page.error_raw /= np.float64(estimator.number_of_primaries)

estimator.file_format = 'bdo2019'
estimator.total_number_of_primaries = estimator.number_of_primaries
estimator.total_run_time = estimator.run_time
estimator.total_run_time_sim = estimator.run_time_sim

logger.debug("Done reading bdo file.")
return True

0 comments on commit 921e4e1

Please sign in to comment.