Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic error in CanteraTest.assertNear #1120

Merged
merged 7 commits into from
Oct 17, 2021
Merged

Conversation

speth
Copy link
Member

@speth speth commented Oct 17, 2021

Changes proposed in this pull request

This fixes an issue I found while trying to explore the changes in #1101 where I realized that some problems weren't getting caught by the tests even though they were clearly covered by the test cases.

  • Fix logic error in assertNear and assertArrayNear functions that caused inf and nan inputs to unexpectedly pass
  • Modify tests that were failing as a result of this

Plus two more minor updates:

  • Fix exception specification of Transport::CKMode in Cython module
  • Fail after the first problem adding a reaction when compiling with optimizations disabled

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

The behavior of collecting errors related to trying to add all
reactions before reporting them can make it hard to diagnose some
problems. Since disabling optimizations is usually an early step in
the debugging process, this will make such problems apparent at that
time.
ctml2yamlTest.test_water_IAPWS95_thermo was trying to calculate
transport properties in a region where the underlying model (which
assumes liquid water) wasn't valid, resulting in NaNs.
Using chained getter/setter notation to set the rate of a Plog
reaction doesn't work because the 'rate' getter always returns a copy
of the PlogRate object, and modifying this object doesn't update the
parent Reaction object.
@codecov
Copy link

codecov bot commented Oct 17, 2021

Codecov Report

Merging #1120 (421bb7a) into main (be95118) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1120   +/-   ##
=======================================
  Coverage   73.45%   73.45%           
=======================================
  Files         364      364           
  Lines       47882    47884    +2     
=======================================
+ Hits        35170    35172    +2     
  Misses      12712    12712           
Impacted Files Coverage Δ
src/kinetics/KineticsFactory.cpp 96.84% <100.00%> (ø)
src/kinetics/RxnRates.cpp 88.15% <100.00%> (+0.10%) ⬆️
src/thermo/PengRobinson.cpp 88.26% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a27eb1f...421bb7a. Read the comment docs.

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Looks good - I noticed the NaN passing as well and changed some of the tests in #1101 for that reason; thanks for tracking the root cause down! Also, noting the chained setter issue: this should be addressed once I get to #1051 at the latest.

@ischoegl ischoegl merged commit f46c3bb into Cantera:main Oct 17, 2021
Copy link
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

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

Thanks @speth. Just a small comment for clarity.

@@ -70,7 +70,7 @@ def tearDownClass(cls):

def assertNear(self, a, b, rtol=1e-8, atol=1e-12, msg=None):
cmp = 2 * abs(a - b)/(abs(a) + abs(b) + 2 * atol / rtol)
if cmp > rtol:
if not cmp < rtol:
Copy link
Member

Choose a reason for hiding this comment

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

I can never remember the priority order of not versus comparisons. I think it'd make sense to group the comparison for clarity, although it's not required. Also if you can add a comment here as to why the comparison is done this way, I think that'd help too. The previous version is more intuitive.

Copy link
Member

Choose a reason for hiding this comment

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

Oops - should have waited longer before merging. I thought the logic made sense. I can add the comment in #1101.

@ischoegl ischoegl mentioned this pull request Oct 17, 2021
5 tasks
@speth speth deleted the fix-assertNear branch July 23, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants