Screening temperature derivatives do not differentiate the returned value
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 72/100
Research direction
Start with util/microphysics_autodiff.H:398-402 and util/approx_math/approx_math.H:20-94 to compare the derivative rule with the implemented value, then inspect the affected expressions and derivative interfaces in screening/screen.H. Run the README.md harness using the stated hydrogen screening case, and validate both screening methods across ion pairs and thermodynamic states. Done means automatic derivatives agree with finite differences and branch continuity is tested.
Written by the indexing model from the issue text.
Description
Summary
The automatic derivative of fast_atan(x) is defined as 1/(1+x*x),
which differentiates exact atan(x). Its value is instead evaluated
using a piecewise polynomial approximation. Consequently, the Chabrier
and Chugunov 2009 screening temperature derivatives disagree with finite
differences even away from approximation branch boundaries.
Suggested priority: medium. Reaction Jacobians receive an inconsistent
screening contribution. Solver convergence failures were not established.
Affected code
util/microphysics_autodiff.H:398-402:FastAtanOpderivative rule.util/approx_math/approx_math.H:20-94: actual approximated value.screening/screen.H:461,553: affected free-energy expressions.screening/screen.H:663-672,697-706: derivative output interfaces.
Reviewed commit: e4b401b7637894a3db5ffa1e4b401509a332a1d6.
The derivative rule is attributed to commit bbe8723a1, PR #1593.
Reproduction
Run the harness described in README.md. Use pure hydrogen,
rho = 100 g/cm^3, a proton-proton screening pair, and
T = 13408146.05173284 K. Disable Debye-Huckel skipping and the optional
Chabrier quantum correction.
Seed the temperature of plasma_state_t<autodiff::dual>, then compare
actual_log_screen's derivative with a centered finite difference of the
real-valued routine, using delta_T = 1.e-5 * T.
Method Automatic dh/dT Finite-difference dh/dT
chabrier1998 -4.246705441041109e-9 -4.280877898758545e-9
chugunov2009 -3.490568036519522e-9 -3.519126114425965e-9
The relative disagreements are approximately 0.798% and 0.812%,
respectively. These samples are away from the 0.378 branch transition.
The same inconsistency propagates through actual_screen via exp(h).
Expected behavior
Automatic differentiation should differentiate the screening function
actually returned to callers. If an approximate Jacobian is intentional,
its accuracy and purpose should be explicitly documented and validated.
Proposed fix
Replace both screening uses of admath::fast_atan with admath::atan.
This also removes the value discontinuity documented separately in
02-free-energy-discontinuity.md.
Alternatively, differentiate each implemented polynomial exactly. For
the small-argument branch the derivative is 1 - x^2 + x^4; for the
other polynomial it is 5*A*x^4 + 3*B*x^2 + C. Apply the chain rule for
the reciprocal branches and handle the constant large-argument branch.
That change alone does not remove the branch discontinuities.
Validation
Compare automatic derivatives with finite differences across both
screening methods, multiple ion pairs, and a range of thermodynamic
states. Vary the finite-difference step to distinguish truncation error
from a persistent derivative mismatch. Test branch continuity separately.
- Dominant language
- C++
- Stars
- 44
- Forks
- 46
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 9
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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 AMReX-Astro/Microphysics
-
bug GPU
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
AMReX-Astro/Microphysics#2115 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
AMReX-Astro/Microphysics#2104 · 3 comments ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 55/100
AMReX-Astro/Microphysics#2097 · 1 comment ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 66/100
AMReX-Astro/Microphysics#2095 · 1 comment ·
Maintainers usually reply within 1 day
-
ai-code-audit nse
Difficulty 3/5 1-2 days Newbie friendliness 68/100
AMReX-Astro/Microphysics#2075 ·
Maintainers usually reply within 1 day
All issues in AMReX-Astro/Microphysics
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ROCm/rocm-libraries#14027 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Qiskit/qiskit-aer#2487 ·
Maintainers usually reply within 1 day
-
GUI
Difficulty 1/5 Under an hour Newbie friendliness 78/100
qbittorrent/qBittorrent#25104 ·
Maintainers usually reply within 2 days
-
P2: A timed rotation maneuver does nothing on a ship that had an earlier timed lateral maneuverOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
scp-fs2open/fs2open.github.com#7914 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days