From c64cbe1b5f7ee1e62b2645b62709f3b5a010381c Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Tue, 20 Apr 2021 15:59:23 -0400 Subject: [PATCH] Restoring previous versions of nrtest files that work --- tools/nrtest-epanet/nrtest_epanet/__init__.py | 54 ++++++++++++++++--- tools/nrtest-epanet/setup.py | 2 +- tools/test-config.sh | 2 +- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/tools/nrtest-epanet/nrtest_epanet/__init__.py b/tools/nrtest-epanet/nrtest_epanet/__init__.py index 829a671..5c36f71 100644 --- a/tools/nrtest-epanet/nrtest_epanet/__init__.py +++ b/tools/nrtest-epanet/nrtest_epanet/__init__.py @@ -101,6 +101,8 @@ def epanet_mincdd_compare(path_test, path_ref, rtol, atol): Raises: ValueError() AssertionError() + + Modified by L. Rossman (4/20/21) ''' min_cdd = 100.0 @@ -114,14 +116,19 @@ def epanet_mincdd_compare(path_test, path_ref, rtol, atol): if np.array_equal(test[0], ref[0]): continue else: - diff = np.fabs(np.subtract(test[0], ref[0])) - idx = np.unravel_index(np.argmax(diff), diff.shape) + lre = _log_relative_error(test[0], ref[0]) + idx = np.unravel_index(np.argmin(lre), lre.shape) + if lre[idx] < min_cdd: + min_cdd = tmp; - if diff[idx] != 0.0: - tmp = - np.log10(diff[idx]) + #diff = np.fabs(np.subtract(test[0], ref[0])) + #idx = np.unravel_index(np.argmax(diff), diff.shape) - if tmp < min_cdd: - min_cdd = tmp; + #if diff[idx] != 0.0: + # tmp = - np.log10(diff[idx]) + + # if tmp < min_cdd: + # min_cdd = tmp; if np.floor(min_cdd) >= atol: return True @@ -129,6 +136,36 @@ def epanet_mincdd_compare(path_test, path_ref, rtol, atol): raise AssertionError('min_cdd=%d less than atol=%g' % (min_cdd, atol)) +def _log_relative_error(q, c): + ''' + Computes log relative error, a measure of numerical accuracy. + + Single precision machine epsilon is between 2^-24 and 2^-23. + + Reference: + McCullough, B. D. "Assessing the Reliability of Statistical Software: Part I." + The American Statistician, vol. 52, no. 4, 1998, pp. 358-366. + ''' + diff = np.subtract(q, c) + tmp_c = np.copy(c) + + # If ref value is small compute absolute error + tmp_c[np.fabs(tmp_c) < 1.0e-6] = 1.0 + re = np.fabs(diff)/np.fabs(tmp_c) + + # If re is tiny set lre to number of digits + re[re < 1.0e-7] = 1.0e-7 + # If re is very large set lre to zero + re[re > 2.0] = 1.0 + + lre = np.negative(np.log10(re)) + + # If lre is negative set to zero + lre[lre < 1.0] = 0.0 + + return lre + + def epanet_report_compare(path_test, path_ref, rtol, atol): ''' Compares results in two report files ignoring contents of header and footer. @@ -152,9 +189,12 @@ def epanet_report_compare(path_test, path_ref, rtol, atol): RunTimeError() ... ''' + +# Comparison of Status Report files turned off - L.Rossman (4/20/21) + + ''' HEADER = 10 FOOTER = 2 - ''' with open(path_test ,'r') as ftest, open(path_ref, 'r') as fref: for (test_line, ref_line) in it.izip(hdf.parse(ftest, HEADER, FOOTER)[1], diff --git a/tools/nrtest-epanet/setup.py b/tools/nrtest-epanet/setup.py index 65fea94..1bf357c 100644 --- a/tools/nrtest-epanet/setup.py +++ b/tools/nrtest-epanet/setup.py @@ -18,7 +18,7 @@ entry_points = { 'nrtest.compare': [ 'epanet allclose = nrtest_epanet:epanet_allclose_compare', #'epanet mincdd = nrtest_epanet:epanet_mincdd_compare', - #'epanet report = nrtest_epanet:epanet_report_compare', + 'epanet report = nrtest_epanet:epanet_report_compare', # Add entry point for new comparison functions here ] } diff --git a/tools/test-config.sh b/tools/test-config.sh index e94195b..f06e9dd 100644 --- a/tools/test-config.sh +++ b/tools/test-config.sh @@ -16,7 +16,6 @@ # Suggested Usage: # $ for file in .//*; do ./test-config.sh $file 1.0 > "${file%.*}.json"; done # -# "${name}.rpt": "epanet report", filename="$1" name="${filename%.*}" @@ -38,6 +37,7 @@ cat<