Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hkershaw-brown
Copy link
Member

Description:

Changes the tolerance on convergence in normal_distribution_mod::inv_cdf

Now a parameter and set to epsilon_exponent = 0.52_r8
Previous value of 0.75 leads to failure to converge for some compilers.
This pull request also adds a return early if the first guess is exact.

Fixes issue

fixes #873

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Performance fix really.

Documentation changes needed?

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.

Tests

Please describe any tests you ran to verify your changes.
jla testing on Dercho compilers.

Checklist for merging

  • Updated changelog entry
  • Documentation updated
  • Update conf.py

Checklist for release

  • Merge into main
  • Create release from the main branch with appropriate tag
  • Delete feature-branch

Testing Datasets

  • Dataset needed for testing available upon request
  • Dataset download instructions included
  • No dataset needed

@hkershaw-brown hkershaw-brown requested review from Copilot and jlaucar and removed request for jlaucar June 9, 2025 16:38
Copy link
Contributor

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

Adjust the convergence logic in first_guess for the inverse CDF computation to improve stability and add an early exit when the initial guess is exact.

  • Introduce a new epsilon_exponent parameter (0.52) to bound convergence instead of the hardcoded 0.75.
  • Add an early return if the preliminary quantile guess exactly matches the target.
  • Update the convergence check to use the new epsilon_exponent.
Comments suppressed due to low confidence (2)

assimilation_code/modules/assimilation/normal_distribution_mod.f90:405

  • Add a unit test to cover the branch where the preliminary guess exactly matches the quantile, ensuring the early return path is exercised.
if(del_q == 0.0_r8) then

assimilation_code/modules/assimilation/normal_distribution_mod.f90:358

  • [nitpick] The name epsilon_exponent could be more descriptive (e.g., convergence_epsilon_exponent) to better convey its purpose in the convergence check.
real(r8), parameter :: epsilon_exponent = 0.52_r8

Comment on lines +404 to +405
! If the preliminary guess is exact, no need to do iterative search below
if(del_q == 0.0_r8) then
Copy link

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

Avoid direct equality comparison on floating-point values as it can be unreliable; consider using a small tolerance (e.g., ABS(del_q) <= tol) to determine exact matches.

Suggested change
! If the preliminary guess is exact, no need to do iterative search below
if(del_q == 0.0_r8) then
! If the preliminary guess is sufficiently close, no need to do iterative search below
tol = 1.0e-12_r8 ! Define a small tolerance for floating-point comparison
if(ABS(del_q) <= tol) then

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I know copilot this is all over the code
-Wcompare-reals for distribution mods
#717 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

see #894 for list of real comparisons.

@hkershaw-brown hkershaw-brown changed the title Changed the tolerance on convergence in normal_distribution_mod::inv_cdfexponent Changed the tolerance on convergence in normal_distribution_mod::inv_cdf Jun 9, 2025
@hkershaw-brown hkershaw-brown added the QCEFF quantile conserving filters label Jun 13, 2025
@hkershaw-brown hkershaw-brown requested a review from jlaucar June 24, 2025 20:10
@hkershaw-brown
Copy link
Member Author

rebasing this pull request.

Jeffrey Anderson and others added 2 commits July 16, 2025 12:51
Tuned this value from 0.75 to 0.52 to avoid previous failure to converge error
messages.

This version passes the normal, beta and gamma developers tests for the
following compilers on Derecho with the standard mkmf files:
gcc 12.4.0
gcc 12.2.0
gcc 13.2.0
ifort 2024.2
ifx 2025.0.3
nvidia 24.11

It passed all tests except the second set of convergence tests for the
beta distribution for the Cray cce 17.0.1. That compiler crashed for the
second part of the beta tests, likely due to a compiler error.

It passed all three tests on a mac with gfortran 13.3.0 with -O0, -O1,
-O2 and -O3.
@hkershaw-brown
Copy link
Member Author

@jlaucar checking in on this, do you have an estimate of when you will get to the review?

Copy link
Contributor

@jlaucar jlaucar left a comment

Choose a reason for hiding this comment

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

This looks good to go. It does have potential to generate results that are not backwards compatible.

@hkershaw-brown
Copy link
Member Author

@mjs2369 can you click "approve" on this, see Jeff's "approve comment
#893 (review)

@jlaucar
Copy link
Contributor

jlaucar commented Aug 25, 2025

Approved.

@jlaucar
Copy link
Contributor

jlaucar commented Aug 25, 2025 via email

@hkershaw-brown
Copy link
Member Author

just need a click on approve:

Screenshot 2025-08-25 at 9 55 31 AM Screenshot 2025-08-25 at 9 55 34 AM

@hkershaw-brown hkershaw-brown added the release! bundle with next release label Aug 25, 2025
@hkershaw-brown hkershaw-brown merged commit 944059b into main Aug 27, 2025
4 checks passed
@hkershaw-brown hkershaw-brown deleted the norm-dist-exponent branch August 27, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QCEFF quantile conserving filters release! bundle with next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

normal_distribution_mod exponent 0.52 vs 0.75

3 participants