HandyModRTransform.deriv3 is wrong for m > 2
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
The bug is in HandyModRTransform.deriv3 in grid/rtransform.py, in the first numerator term that uses 2 * two_m. Read that term against the symbolic third derivative of the transform, and check deriv3_inverse, which depends on it. Reproduce with the solve_ode_ivp snippet in the issue for m = 3 and 4. Done means deriv3 matches finite differences for m = 1 to 5 and the reproduction gives (x + 0.5)**3, with a regression test added.
Written by the indexing model from the issue text.
Description
HandyModRTransform.deriv3 returns the wrong third derivative whenever m >= 3. For m = 1 and m = 2 it is correct, which is the only range the current tests use.
The first term in the numerator is written as 2 * two_m * (m - 2) * (m - 1) * (1 - two_m + size_r) ** 2, but differentiating r(x) three times gives two_m**2 there, not 2 * two_m. The term is multiplied by (m - 1)(m - 2), so the mistake only shows up from m = 3 on.
Because deriv3 feeds deriv3_inverse and the transformed ODE solvers, those are off too. A small example with solve_ode_ivp on y''' = 6, y(-0.5) = y'(-0.5) = y''(-0.5) = 0, whose exact solution is (x + 0.5)**3:
import numpy as np
from grid.ode import solve_ode_ivp
from grid.rtransform import HandyModRTransform
xs = np.array([0.0, 0.25, 0.5])
for m in [2, 3, 4]:
tf = HandyModRTransform(0.1, 10.0, m)
sol = solve_ode_ivp((-0.5, 0.5), lambda x: 6 * np.ones_like(x), [0, 0, 0, 1],
[0.0, 0.0, 0.0], transform=tf, rtol=1e-10, atol=1e-10)
print(m, sol(xs)[0], (xs + 0.5) ** 3)
On master:
2 [0.125 0.421875 1. ] [0.125 0.421875 1. ]
3 [0.12976934 0.45091849 1.10383533] [0.125 0.421875 1. ]
4 [0.14209262 0.53001896 1.41016422] [0.125 0.421875 1. ]
Comparing deriv3 directly against the symbolic third derivative (sympy) of transform for rmin=0.1, rmax=10, the relative error is ~1e-15 for m = 1, 2 and 0.75, 0.87, 0.94 for m = 3, 4, 5.
The fix is a one-line change (2 * two_m to two_m**2) plus a test that checks deriv3 against finite differences for m = 1 to 5. I have a patch ready if that's fine.
- Dominant language
- Python
- Stars
- 102
- Forks
- 43
- Avg merge
- 6d 6h
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from theochem/grid
-
Radial Transformation UpdatesMay be free again @merreeves claimed this 32 days ago, and no pull request is open. Open
-
Splitting grid data from packageMay be free again @FarnazH claimed this 58 days ago, and no pull request is open. Open
-
Additional low-discrepancy sequences for (hyper)cubic integrationMay be free again @Zohaibcode740 claimed this 84 days ago, and no pull request is open. Open
-
Add full support for Ahrens-Beylkin gridsMay be free again @marco-2023 claimed this 127 days ago, and no pull request is open. Open
-
Parameter Study & Benchmarking Results for solve_poisson_bvp and solve_poisson_ivpMay be free again @marco-2023 claimed this 85 days ago, and no pull request is open. Open
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
FinanceFlash/unvibecode#577 · 1 comment ·
Maintainers usually reply within 1 day
-
area/test type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Clodmony/starship-coop#70 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
punitarani/fli#270 ·
-
🐛 Bug 🔔 Pending processing
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
jumpserver/jumpserver#17980 ·
Maintainers usually reply within 1 day
-
community enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day