Skip to content

Commit

Permalink
Fix RawReport to handle all scientific notation
Browse files Browse the repository at this point in the history
- Due to error in pyyaml scientific notation floating
  point numbers without a decimal point are parsed as
  strings:  e.g. "1e+09".
- Fix is based on PR:
  <yaml/pyyaml#174>
  to the pyyaml project.

Change-Id: I5cc4afc0d6eecf204b92ba111185d8cc30dc6c5d
Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
  • Loading branch information
cmcantalupo committed Mar 25, 2020
1 parent e5f8ba9 commit 1bc66c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 16 additions & 1 deletion scripts/geopmpy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,22 @@ def __init__(self, path):
else:
out_fid.write(' {}'.format(line))
out_fid.seek(0)
self._raw_dict = yaml.load(out_fid, Loader=yaml.SafeLoader)
# Fix issue with python yaml module where it is confused
# about floating point numbers of the form "1e+10" where
# the decimal point is missing.
# See PR: https://github.com/yaml/pyyaml/pull/174
# for upstream fix to pyyaml
loader = yaml.SafeLoader
loader.add_implicit_resolver(
u'tag:yaml.org,2002:float',
re.compile(r'''^(?:[-+]?(?:[0-9][0-9_]*)\.[0-9_]*(?:[eE][-+]?[0-9]+)?
|[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
|\.[0-9_]+(?:[eE][-+]?[0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*
|[-+]?\.(?:inf|Inf|INF)
|\.(?:nan|NaN|NAN))$''', re.X),
list(u'-+0123456789.'))
self._raw_dict = yaml.load(out_fid, Loader=loader)

def raw_report(self):
return copy.deepcopy(self._raw_dict)
Expand Down
5 changes: 4 additions & 1 deletion scripts/test/TestIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def self_cleaning_app_output(*args, **kwargs):
dram-energy (joules): 2835.43
power (watts): 121.389
frequency (%): 50.0846
frequency (Hz): 1.05178e+09
frequency (Hz): 1e+09
network-time (sec): 0
count: 5500
requested-online-frequency: 1000000000.000000
Expand Down Expand Up @@ -494,6 +494,9 @@ def test_requested_online_frequency(self):
self.assertLess(region_runtime, total_runtime)
field_runtime = report.get_field(epoch, 'runtime')
self.assertEqual(runtime, field_runtime)
region = report.raw_region('mcfly11', 'sleep')
self.assertTrue(type(region['frequency (Hz)']) is float)
self.assertEqual(1e9, region['frequency (Hz)'])

def test_report(self):
""" Test that a file of concatenated reports can be extracted to
Expand Down

0 comments on commit 1bc66c3

Please sign in to comment.