Skip to content

fix: MultiExp negative weights and inf/nan at end points (#265) - #345

Merged
marco-2023 merged 3 commits into
theochem:masterfrom
alok-108:fix-265-multiexp-weights
Oct 29, 2026
Merged

marco-2023 merged 3 commits into
theochem:masterfrom
alok-108:fix-265-multiexp-weights

Conversation

@alok-108

@alok-108 alok-108 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the Multi Exp problems reported in #265.

Problem 1: negative weights. MultiExpRTransform maps [-1, 1] to [infinity, rmin], so dr/dx is negative. BaseTransform.transform_1d_grid multiplied 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/deriv3 ignored trim_inf, so 1D grids that contain x = -1 (Trapezoidal, Simpson, Clenshaw-Curtis, Gauss-Chebyshev-Lobatto, tanh-sinh) gave inf/nan weights, which are the -inf and nan rows in the issue. Becke, Knowles and the others already trim the infinity.

Changes

  • transform_1d_grid uses |dr/dx| for the weights (unchanged for transforms that increase with x). deriv itself is untouched since the inverse-derivative formulas rely on its sign. Docstring updated.
  • MultiExpRTransform now applies _convert_inf when trim_inf=True and 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 (best 7.5e-5, Midpoint). No Multi Exp row is negative, inf or nan any more.

About the other numbers in the issue

  • The huge errors (1e5 to 1e75) for Becke/Handy/Knowles are gone on current master.
  • Linear Finite and Handy Mod stay at about 3.4e-3: with r_max=4 they drop the charge beyond r=4, which is 3.31e-3 for this density. With r_max=8 or more they are about 1.3e-4.
  • The 1.3e-4 floor of the best combinations is the dataset: a dense radial integral of the Gaussian Ne density gives 9.99986794, not 10. It is independent of the angular grid and the number of radial points.

Tests

  • test_transform_integral_consistency used the signed derivative on both sides, so it passed with the bug; it now uses |dr/dx|.
  • New: positive weights and the exact 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).
  • Full suite: 715 passed. The 6 test_periodicgrid.py::test_get_item failures also occur on unmodified master. The one failed CI job was a flaky ODE test (test_ode, Python 3.10), which doesn't use transform_1d_grid.

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
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 alok-108 changed the title fix: use |dr/dx| for weights in transform_1d_grid (MultiExp negative weights, #265) fix: MultiExp negative weights and inf/nan at end points (#265) Oct 24, 2026
@alok-108
alok-108 marked this pull request as ready for review October 24, 2026 04:08
@PaulWAyers
PaulWAyers requested review from Ao-chuba, FarnazH and marco-2023 and a balanced review from Copilot October 29, 2026 06:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 marco-2023 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I added a small fix to the documentation and tightened the handling of the zero divisions. It now looks good to me.

@marco-2023
marco-2023 merged commit 51683d0 into theochem:master Oct 29, 2026
10 checks passed
@alok-108

Copy link
Copy Markdown
Contributor Author

Thanks @marco-2023 for reviewing and polishing the fix!

@alok-108
alok-108 deleted the fix-265-multiexp-weights branch October 30, 2026 10:49
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