Skip to content

Conversation

mahf708
Copy link
Contributor

@mahf708 mahf708 commented May 27, 2025

inverts comparison logic in property checks to use IEEE 754 (NaN < value returns false; NaN > value returns false) to carefully account for the existence of NaN values in comparisons instead of silently ignoring them.

Fixes #7384

[BFB]

@mahf708 mahf708 requested review from bartgol and Copilot May 27, 2025 22:50
@mahf708 mahf708 added bug fix PR EAMxx Issues related to EAMxx labels May 27, 2025
@mahf708 mahf708 linked an issue May 27, 2025 that may be closed by this pull request
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR inverts the comparison logic in the min/max value checks, replacing direct </> operations with negated >=/<= expressions across multiple dimensional lambdas.

  • Swapped v(...) < result.min_val to not v(...)>=result.min_val
  • Swapped v(...) > result.max_val to not v(...)<=result.max_val
  • Applied change consistently for 1D through 6D views
Comments suppressed due to low confidence (2)

components/eamxx/src/share/property_checks/field_within_interval_check.cpp:99

  • The expression not v(i)>=result.min_val is parsed as (not v(i)) >= result.min_val, which is almost certainly not the intended logic. Use !(v(i) >= result.min_val) or revert to v(i) < result.min_val for correctness.
if (not v(i)>=result.min_val) {

components/eamxx/src/share/property_checks/field_within_interval_check.cpp:103

  • Similarly, not v(i)<=result.max_val is parsed as (not v(i)) <= result.max_val, which does not implement the intended v(i) > result.max_val. Consider !(v(i) <= result.max_val) or v(i) > result.max_val.
if (not v(i)<=result.max_val) {

@mahf708 mahf708 force-pushed the mahf708/eamxx/fieldwithininternal-check-bugfix branch from 112821b to 9b222b9 Compare May 27, 2025 23:33
@mahf708 mahf708 requested a review from Copilot May 27, 2025 23:33
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR inverts the comparison logic used in the min/max value checks across all dimensional variants of the FieldWithinIntervalCheck parallel reductions.

  • Replaces direct </> checks with negated >=/<= expressions for min/max comparisons.
  • Applies this change consistently for 1D through 7D fields.
  • No change in overall algorithmic behavior (BFB).
Comments suppressed due to low confidence (2)

components/eamxx/src/share/property_checks/field_within_interval_check.cpp:99

  • [nitpick] Using an inverted not (v(i) >= result.min_val) reduces readability compared to a direct v(i) < result.min_val. Consider reverting to the simpler form for clarity.
if (not (v(i) >= result.min_val)) {

components/eamxx/src/share/property_checks/field_within_interval_check.cpp:103

  • [nitpick] Using an inverted not (v(i) <= result.max_val) reduces readability compared to a direct v(i) > result.max_val. Consider using the direct comparison.
if (not (v(i) <= result.max_val)) {

@singhbalwinder
Copy link
Contributor

@mahf708 : Does the Kokkos::isnan() function work for detecting NaNs?

@mahf708
Copy link
Contributor Author

mahf708 commented May 28, 2025

@mahf708 : Does the Kokkos::isnan() function work for detecting NaNs?

yeah, should work; note we use ekat::is_invalid() for the specific FieldNaNCheck, see components/eamxx/src/share/property_checks/field_nan_check.cpp.

Here, the goal is to ensure the FieldWithinIntervalCheck is sound (nan cannot really be in any bounded internval [a, b] by definition, or at least by any reasonable assumption). The problem was that we were silently ignoring the possibility of nan in [a, b] when where were checking the values... thus nan ending up circumventing the check altogether :/

@mahf708 mahf708 changed the title EAMxx: invert comparison logic in min/max value checks EAMxx: handle potential nan in within-interval checks May 28, 2025
@bartgol bartgol added the BFB PR leaves answers BFB label May 28, 2025
bartgol added a commit that referenced this pull request May 28, 2025
…xt (PR #7385)

Inverts comparison logic in property checks to use IEEE 754
(NaN < value returns false; NaN > value returns false)
to carefully account for the existence of NaN values in
comparisons instead of silently ignoring them.

Fixes #7384

[BFB]
@bartgol bartgol merged commit b955d26 into master May 28, 2025
19 of 20 checks passed
@bartgol bartgol deleted the mahf708/eamxx/fieldwithininternal-check-bugfix branch May 28, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BFB PR leaves answers BFB bug fix PR EAMxx Issues related to EAMxx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EAMxx: bug in fieldwithininternal check
3 participants