Repository navigation
fix: MultiExp negative weights and inf/nan at end points (#265) - #345
Merged
Merged
Conversation
Transforms that reverse orientation, such as MultiExpRTransform which maps [-1, 1] to [infinity, rmin], have a negative dr/dx. transform_1d_grid multiplied the weights by the signed derivative, so every weight came out negative and integrals changed sign (see theochem#265). Use the absolute value of the derivative. The signed derivative itself is unchanged, since the inverse-derivative formulas rely on it. Tests: the existing integral consistency test used the signed derivative on both sides and so could not catch this. Use |dr/dx| there and add a test that checks positive weights and the analytic integral of exp(-r) for all valid transforms.
alok-108
marked this pull request as draft
October 24, 2026 00:31
…rm pairs MultiExpRTransform ignored trim_inf in its derivatives, so grids that include the end point x = -1 (Trapezoidal, Simpson, Clenshaw-Curtis, Gauss-Chebyshev-Lobatto, tanh-sinh) produced inf/nan weights. Apply _convert_inf to transform-adjacent deriv, deriv2 and deriv3 like the other transforms do, and silence the divide-by-zero warnings at the end point. Add a test over every 1D grid x radial transform combination from theochem#265 (finite, non-negative weights, sane integral) and a test for MultiExp derivatives at x = -1.
alok-108
marked this pull request as ready for review
October 24, 2026 04:08
PaulWAyers
requested review from
Ao-chuba,
FarnazH and
marco-2023
and
a balanced review from Copilot
October 29, 2026 06:10
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the MultiExp integration changes.
No open issues 🎉
What changed in this PR
This PR addresses the MultiExp integration problems reported in #265 by correcting transformed weight signs and handling infinite endpoint derivatives.
Changes:
- Uses the absolute derivative when computing transformed quadrature weights, while preserving signed derivative APIs.
- Applies infinity trimming to MultiExp derivatives and suppresses runtime warnings at singular endpoints.
- Adds regression tests for positive weights, analytic integrals, endpoint handling, and 66 grid/transform combinations.
| File | Description |
|---|---|
| src/grid/tests/test_transform.py | Updates integral consistency checks and adds weight, integration, and endpoint regression tests. |
| src/grid/rtransform.py | Corrects weight signs, trims MultiExp derivative infinities, and updates the weight formula documentation. |
Review effort: Balanced
marco-2023
approved these changes
Oct 29, 2026
marco-2023
left a comment
Collaborator
There was a problem hiding this comment.
I added a small fix to the documentation and tightened the handling of the zero divisions. It now looks good to me.
Contributor
Author
|
Thanks @marco-2023 for reviewing and polishing the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the
Multi Expproblems reported in #265.Problem 1: negative weights.
MultiExpRTransformmaps [-1, 1] to [infinity, rmin], so dr/dx is negative.BaseTransform.transform_1d_gridmultiplied the 1D weights by the signed derivative, so every radial weight was negative and integrals flipped sign (the Multi Exp rows in the issue have the same magnitude as Knowles, only negated).Problem 2: inf / nan at end points.
MultiExpRTransform.transform/deriv/deriv2/deriv3ignoredtrim_inf, so 1D grids that contain x = -1 (Trapezoidal, Simpson, Clenshaw-Curtis, Gauss-Chebyshev-Lobatto, tanh-sinh) gaveinf/nanweights, which are the-infandnanrows in the issue. Becke, Knowles and the others already trim the infinity.Changes
transform_1d_griduses|dr/dx|for the weights (unchanged for transforms that increase with x).derivitself is untouched since the inverse-derivative formulas rely on its sign. Docstring updated.MultiExpRTransformnow applies_convert_infwhentrim_inf=Trueand suppresses the divide-by-zero warning at the end point, like the other transforms.Result (issue script, Ne promolecule, 151 points,
r_max=4): all 66 grid/transform combinations are now finite, and Multi Exp gives the same errors as Knowles (best7.5e-5, Midpoint). No Multi Exp row is negative, inf or nan any more.About the other numbers in the issue
3.4e-3: withr_max=4they drop the charge beyond r=4, which is3.31e-3for this density. Withr_max=8or more they are about1.3e-4.1.3e-4floor of the best combinations is the dataset: a dense radial integral of the Gaussian Ne density gives9.99986794, not 10. It is independent of the angular grid and the number of radial points.Tests
test_transform_integral_consistencyused the signed derivative on both sides, so it passed with the bug; it now uses|dr/dx|.exp(-r)integral for every valid transform; all 11 1D grids x 6 transforms (finite, non-negative weights,r^2 exp(-r)integral); MultiExp derivatives at x = -1. These fail on unmodified master (16 failures).test_periodicgrid.py::test_get_itemfailures also occur on unmodified master. The one failed CI job was a flaky ODE test (test_ode, Python 3.10), which doesn't usetransform_1d_grid.