Skip to content

Check IIP level equations relative to their total rate - #3828

Merged
jvshields merged 4 commits into
tardis-sn:masterfrom
andrewfullard:scaled-level-residuals
Nov 16, 2026
Merged

jvshields merged 4 commits into
tardis-sn:masterfrom
andrewfullard:scaled-level-residuals

Conversation

@andrewfullard

@andrewfullard andrewfullard commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

📝 Description

Type: 🪲 bugfix

The level solve accepted a population when every residual of the normalized rate equations was below an absolute 1e-10. That limit depends on the unit of time and on how fast each level is populated, and sits at the precision the root finder reaches, so accepted states could fail final closure at 1.0-2.3e-10. Each residual is now divided by the total rate of its equation (the sum of the magnitudes of the rates into and out of the level) and closes at the fraction LEVEL_RESIDUAL_LIMIT = 1e-10. A test checks that the relative residual does not depend on the rate unit.

The terminal level residual, re-evaluated at the charge-solved electron density, is removed. It was a diagnostic only, and rebuilt the bound-bound rates on every evaluation.

📌 Resources

Examples, notebooks, and links to useful references.

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

The level solve accepted a population when every residual of the normalized
rate equations was below an absolute 1e-10. That limit depends on the unit
of time and on how fast each level is populated, and sits at the precision
the root finder reaches, so accepted states could fail final closure at
1.0-2.3e-10. Each residual is now divided by the gross rate of its equation,
the sum of the magnitudes of the rates into and out of the level, and closes
at LEVEL_RESIDUAL_LIMIT = 1e-10 of it. A metamorphic test checks that the
relative residual does not depend on the rate unit.

The terminal level residual, re-evaluated at the charge-solved electron
density, is removed. It was a diagnostic only, and rebuilt the bound-bound
rates on every evaluation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tardis-bot

tardis-bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and I noticed that your email is not associated with an ORCID ID in our database.

Please add your email and ORCID ID to the .orcid.csv file in your current branch and push the changes to this pull request.

If you don't have an ORCID ID yet, you can create one for free at orcid.org. ORCID IDs help ensure you get proper credit for your scientific contributions.

The format should be:

email,orcid
your.email@example.com,0000-0000-0000-0000

Runs: ORCID check · comment publisher

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.36%. Comparing base (aeb5993) to head (35a0420).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3828      +/-   ##
==========================================
+ Coverage   71.35%   71.36%   +0.01%     
==========================================
  Files         207      207              
  Lines       15983    15997      +14     
==========================================
+ Hits        11404    11417      +13     
- Misses       4579     4580       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

npt.assert_allclose(perturbed_q_ratio, 0.125)


def test_relative_level_residual_does_not_depend_on_rate_unit() -> None:

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.

I couldn't really make sense of what this was trying to test. Codex review found some issues and explained them better than just my general confusion:

  • This test bypasses the production normalization helper. Line 285 computes residual / total_rate inside the test. Breaking calculate_relative_level_residual would leave this test passing.

  • This test never exercises acceptance. Reverting the solver to its old absolute-residual stopping criterion would also leave this test passing. That criterion is the central behavior this PR changes.

  • This test does not establish that the denominator is correct. Omitting recombination from total_rate, for example, still produces a denominator that scales linearly with every rate. Both assertions would pass.

jvshields
jvshields previously approved these changes Nov 10, 2026
@jvshields

Copy link
Copy Markdown
Contributor

There is a merge conflict to be fixed

@jvshields
jvshields merged commit eff3729 into tardis-sn:master Nov 16, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants