Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Screening temperature derivatives do not differentiate the returned value

Open
#2,096 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend, testing

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

ai-code-audit screening

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: FastAtanOp derivative 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AMReX-Astro/Microphysics

All issues in AMReX-Astro/Microphysics

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.