Skip to content

Commit 9debc30

Browse files
authored
Merge pull request #3434 from jack-morrison/jackm/2857
[feat] Support reference values of zero
2 parents 20fed5d + 6067bc8 commit 9debc30

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

reframe/core/pipeline.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,13 @@ def pipeline_hooks(cls):
672672
#: performance variables defined in :attr:`perf_patterns` and scoped under
673673
#: the system/partition combinations.
674674
#: The reference itself is a four-tuple that contains the reference value,
675-
#: the lower and upper thresholds and the measurement unit.
675+
#: the lower and upper thresholds, and the measurement unit.
676+
#:
677+
#: For non-zero reference values, lower and upper thresholds are
678+
#: percentages -/+ from the reference value in decimal form.
679+
#:
680+
#: When a reference value of ``0`` is expected, lower and upper
681+
#: thresholds are interpreted as absolute values.
676682
#:
677683
#: An example follows:
678684
#:
@@ -690,7 +696,7 @@ def pipeline_hooks(cls):
690696
#: }
691697
#:
692698
#: To better understand how to set the performance reference tuple, here
693-
#: are some examples with both positive and negative reference values:
699+
#: are some examples with positive, negative, and zero reference values:
694700
#:
695701
#: ============================== ============ ========== ===========
696702
#: **Performance Tuple** **Expected** **Lowest** **Highest**
@@ -700,13 +706,14 @@ def pipeline_hooks(cls):
700706
#: ``(-100, -0.01, 0.02, 'C')`` -100 C -101 C -98 C
701707
#: ``(-100, -0.01, None, 'C')`` -100 C -101 C inf C
702708
#: ``(-100, None, 0.02, 'C')`` -100 C -inf C -98 C
709+
#: ``(0, -2, 5, 'C')`` 0 C -2 C 5 C
703710
#: ============================== ============ ========== ===========
704711
#:
705712
#: During the performance stage of the pipeline, the reference tuple
706713
#: elements, except the unit, are passed to the
707714
#: :func:`~reframe.utility.sanity.assert_reference` function along with the
708-
#: obtained performance value in order to actually assess whether the test
709-
#: passes the performance check or not.
715+
#: obtained performance value to assess whether the test
716+
#: passes or fails the performance check.
710717
#:
711718
#: :type: A scoped dictionary with system names as scopes, performance
712719
#: variables as keys and reference tuples as values.

reframe/utility/sanity.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,13 @@ def assert_reference(val, ref, lower_thres=None, upper_thres=None, msg=None):
550550
lower and upper thresholds do not have appropriate values.
551551
'''
552552
if lower_thres is not None:
553-
lower_thres_limit = -1 if ref >= 0 else None
553+
if ref > 0:
554+
lower_thres_limit = -1
555+
elif ref == 0:
556+
lower_thres_limit = -math.inf
557+
else:
558+
lower_thres_limit = None
559+
554560
try:
555561
evaluate(assert_bounded(lower_thres, lower_thres_limit, 0))
556562
except SanityError:
@@ -559,7 +565,13 @@ def assert_reference(val, ref, lower_thres=None, upper_thres=None, msg=None):
559565
) from None
560566

561567
if upper_thres is not None:
562-
upper_thres_limit = None if ref >= 0 else 1
568+
if ref > 0:
569+
upper_thres_limit = None
570+
elif ref == 0:
571+
upper_thres_limit = math.inf
572+
else:
573+
upper_thres_limit = 1
574+
563575
try:
564576
evaluate(assert_bounded(upper_thres, 0, upper_thres_limit))
565577
except SanityError:
@@ -577,11 +589,16 @@ def calc_bound(thres):
577589

578590
return ref*(1 + thres)
579591

580-
lower = calc_bound(lower_thres)
592+
if ref != 0:
593+
lower = calc_bound(lower_thres)
594+
upper = calc_bound(upper_thres)
595+
else:
596+
lower = lower_thres
597+
upper = upper_thres
598+
581599
if lower is None:
582600
lower = -math.inf
583601

584-
upper = calc_bound(upper_thres)
585602
if upper is None:
586603
upper = math.inf
587604

unittests/test_sanity_functions.py

+8
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,14 @@ def test_assert_reference():
448448
assert sn.assert_reference(-0.9, -1, upper_thres=0.1)
449449
assert sn.assert_reference(-0.9, -1)
450450

451+
# Check reference values of 0
452+
assert sn.assert_reference(0, 0, 0, 0)
453+
assert sn.assert_reference(-1, 0, -2, 2)
454+
assert sn.assert_reference(2, 0, -2, 2)
455+
with pytest.raises(SanityError, match=r'3 is beyond reference value 0 '
456+
r'\(l=-10, u=1\)'):
457+
sn.evaluate(sn.assert_reference(3, 0, -10, 1))
458+
451459
# Check upper threshold values greater than 1
452460
assert sn.assert_reference(20.0, 10.0, None, 3.0)
453461
assert sn.assert_reference(-50.0, -20.0, -2.0, 0.5)

0 commit comments

Comments
 (0)