8000 perf: faster aqueous equilibrium solve, results bit-identical by rafatahmed · Pull Request #338 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

perf: faster aqueous equilibrium solve, results bit-identical - #338

Merged
rafatahmed merged 1 commit into
mainfrom
perf/aqueous-solver
Nov 26, 2026
Merged

rafatahmed merged 1 commit into
mainfrom
perf/aqueous-solver

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Closes #337

plan_ratio_recipe spends 99% of its time in 6,600 aqueous_model.solve calls. This speeds up each solve without changing any float.

  • linear: no per-pivot lambda, row slices instead of indexed inner loops.
  • evaluate: species indices and coefficients are built once per component set (itemgetter + sum(map(mul, ...)), same terms in the same order, so sum keeps its compensated behaviour on 3.12+, see Results differ in the last digits between Python 3.11 and 3.12+ (the built-in sum changed) #334); phase vectors and log10(water) hoisted; the exponent clamp is a conditional with the same NaN result as max(-300, min(100, e)).
  • model_qualification is computed once per pattern of positive ligands and metals and returned as copies.
  • Derived data is cached per chemistry dataset object, so the model-qualification tests that substitute altered chemistry still see their change.

Evidence

  • Bit-exact: sha256 of the repr of every returned float over 49 fixture solves (4 PHREEQC fixtures, 7 pH values, ionic-strength and warm-start chains, nitric target) and 400 recorded ratio-verification solves is identical before and after.
  • Solve speed 3.5 -> 3.0 ms (paired runs); test_feasible_1_0 about 250 s -> 122 s.
  • 214 non-heavy test modules pass locally; the nine heavy modules run in CI (run records in outputs/test-runs/2026-11-26-perf-solver/, local).
  • No chemistry values change, so no PHREEQC fixture re-capture applies.

Not in this PR

A warm start across the pH grid in refine_ph would be 2.2x faster on the same 400 solves, but results change in the last digits (max SI difference 2.8e-10, inside the solver tolerance). That changes numbers, so it needs your decision.

@rafatahmed rafatahmed added the enhancement New feature or request label Nov 26, 2026
@rafatahmed rafatahmed self-assigned this Nov 26, 2026
@codecov
codecov Bot commented Nov 26, 2026 •
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (906d29b) to head (b067b00).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #338   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          148       148           
  Lines        17446     17507   +61     
  Branches      3542      3550    +8     
=========================================
+ Hits         17446     17507   +61     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@rafatahmed
rafatahmed marked this pull request as ready for review November 26, 2026 23:55
@rafatahmed
rafatahmed merged commit 062beb3 into main Nov 26, 2026
29 checks passed
@rafatahmed
rafatahmed deleted the perf/aqueous-solver branch November 26, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: ratio uncertainty check spends 100 s in 6,600 aqueous solves; the equilibrium core is slow per solve

1 participant

0