8000 fix: state a limit for each value of the two reduced-model PHREEQC fixtures by rafatahmed · Pull Request #509 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

fix: state a limit for each value of the two reduced-model PHREEQC fixtures - #509

Merged
rafatahmed merged 2 commits into
mainfrom
fix/fixture-tolerances-504
Dec 5, 2026
Merged

rafatahmed merged 2 commits into
mainfrom
fix/fixture-tolerances-504

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Summary

Closes #504

assert_reference_result
  for each reference value
    allowed = expected.tolerances[name]   # new, optional: {"absolute": a} or {"relative": r}
              else expected.absoluteTolerance

In both fixtures absoluteTolerance goes from 0.05 to 0, so a value without its own limit must match exactly (only pH, and ionic strength where it is an input). Every other value has a limit: 1.2 × the difference measured today, rounded up to two significant figures. The reason is written in each fixture as toleranceBasis.

target_ph_nitric_dose.json, legacy solver against PHREEQC 3.8.6:

Value Measured difference Limit
free sulfate 13.12 % 16 %
nitric acid 10.00 % 12 %
free magnesium 8.80 % 11 %
ionic strength 4.69 % 5.7 %
free phosphate 3.67 % 4.5 %
free carbonate 0.93 % 1.2 %
free calcium / bicarbonate 0.46 / 0.38 % 0.55 / 0.46 %
HPO4-2 / H2PO4- 0.24 / 0.20 % 0.29 / 0.24 %
SI calcite / gypsum / hydroxyapatite 0.0044 / 0.046 / 0.030 0.0054 / 0.056 / 0.037

ca_mg_phosphate_complexation.json, calcium_magnesium_phosphate_speciation against PHREEQC 3.8.9:

Value Measured difference Limit
free Ca / Mg 0.048 / 0.124 % 0.058 / 0.15 %
free phosphate 0.84 % 1.1 %
HPO4-2 / H2PO4- 0.68 / 0.16 % 0.83 / 0.19 %
SI hydroxyapatite 0.031 0.038

No reference value or PHREEQC input changes. The two pinned hashes in tests/reference_inventory.json change with the files. The separate 0.0005 mol/kgw acid assertion is removed: the fixture limit (0.00025) is tighter.

Evidence

  • Before: the new tests give 28 failures: a zero molality passes both fixtures, and so do the H2PO4- and HPO4-2 values of the solver before the phosphate balance correction.
    After: all pass. Run against the earlier solver source (77b506a0), the new limits reject it: H2PO4- 8.8020e-4 against 8.6018e-4 ± 2.1e-6.
  • 25 affected and documentation test modules pass; ruff check and ruff format --check pass.
  • PHREEQC 3.8.6-17100: both fixture inputs re-run into a new directory. All stored target-pH values match exactly; the 3.8.9 Ca/Mg/P values agree within their stated figures except SI hydroxyapatite, 3.1464 here against 3.15. Product re-capture: 58 files same, 0 differ; the live replay modules test_product_phreeqc and test_acid_reference pass (6 tests).

Remaining limit

  • The wide limits record how far the reduced model is from PHREEQC; they do not make it closer. In the PHREEQC species table, MgSO4, NaSO4- and KSO4- total 1.15e-4 mol/kgw, against a free sulfate difference of 1.09e-4; MgSO4 and MgHCO3+ total 8.0e-5, against a free magnesium difference of 7.8e-5. The legacy solver has none of these pairs.
  • The nitric acid limit is wide because of the open planner defect bug: the legacy nitric planner leaves the phosphate complexes out of alkalinity #507. It should be tightened when that is corrected; nothing forces it.
  • No cause is established for the hydroxyapatite saturation index differences.
  • A change that moves a result closer to PHREEQC passes; the limits do not tighten themselves.

Checked against earlier work

#503 and #508: the solver values that #508 corrected are now rejected by this fixture. #507 stays open. No other open pull request.

Merge Danger

Door: two-way

Blast Radius: small. reference_fixtures gains an optional field; fixtures without it behave as before. A later chemistry change that moves these two models by more than about 20 % of their present gap fails the tests.

…xtures

One absolute tolerance of 0.05 accepted a zero molality and the earlier
unconserved phosphate balance. Fixtures can now give an absolute or
relative limit per value; each is 1.2 times the measured difference.
Reference values and PHREEQC inputs are unchanged.

Closes #504
@rafatahmed rafatahmed added the bug Something isn't working label Dec 5, 2026
@rafatahmed rafatahmed self-assigned this Dec 5, 2026
@read-the-docs-community
read-the-docs-community Bot commented Dec 5, 2026 •
Copy link
Copy Markdown

📖 2 files modified


Preview · build overview · Flahax · built Dec. 5, 2026, 9:54 a.m. UTC

@codecov
codecov Bot commented Dec 5, 2026 •
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (047edcd) to head (5495e67).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #509   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          155       155           
  Lines        18403     18417   +14     
  Branches      3719      3723    +4     
=========================================
+ Hits         18403     18417   +14     
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 December 5, 2026 11:26
@rafatahmed
rafatahmed merged commit 053c693 into main Dec 5, 2026
28 checks passed
@rafatahmed
rafatahmed deleted the fix/fixture-tolerances-504 branch December 5, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: two PHREEQC fixtures compare molalities with an absolute tolerance of 0.05

1 participant

0