8000 Leave out products for a ceiling the water already exceeds (#86) by rafatahmed · Pull Request #87 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

Leave out products for a ceiling the water already exceeds (#86) - #87

Merged
rafatahmed merged 1 commit into
mainfrom
fix/unreachable-ceiling
Oct 22, 2026
Merged

rafatahmed merged 1 commit into
mainfrom
fix/unreachable-ceiling

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Closes #86.

recommend() raised NNLS did not reach optimality when the water alone already exceeded one declared maximum while another maximum was binding. Example: 9% of the station 104 well with Na and Cl maxima of 3 mmol/L. Reproduction, root cause and a table of failing cases are in #86.

Fix. _fit_within now detects a ceiling that the water background already reaches. Any product carrying that ion can only add to the violation, so the fit leaves those products out directly. That is the limit the old Lagrange search was approaching: its shift grew without bound and, with a second active ceiling, overflowed NNLS. The excess is still reported in limitViolations.

Evidence.

  • 312 cases (26 formulas × water shares 0/5/9/25% × Cl 106.35, Na 68.97 and Cl 70 maxima): recipes identical to main wherever main succeeded.
  • The previously failing case equals the reference fit without chloride products: same salts, same loss.
  • New regression test test_a_ceiling_the_water_already_breaks_is_reported_not_a_solver_failure: it fails on main with the NNLS error and passes here.

Validation.

  • FLAHAX_REQUIRE_PHREEQC=1 unittest: 424 tests OK
  • verify_distribution: PASS
  • sphinx -W: clean
  • API reference --check: ok
  • No CRLF

Found while writing the grower walkthrough (#80). That PR follows separately and builds on this one.

recommend() raised 'NNLS did not reach optimality' when the source water
alone exceeded one declared maximum while another was binding, for example
9% of the station 104 well with Na and Cl maxima of 3 mmol/L. A ceiling the
water already reaches cannot be met, so its Lagrange search (#68) never
closed its bracket and grew the shift on every step until the right-hand
side was about 2^60 times the limit; with a second active ceiling NNLS then
failed.

Any product carrying that ion only adds to the violation, so the fit now
leaves those products out directly, the infinite-multiplier limit the
search was approaching. The excess is still reported in limitViolations.
Over 312 formula x water share x ceiling cases the recipes are identical
wherever the old search succeeded; the failing cases equal the fit without
chloride products.
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 Flahax | 🛠️ Build #35326738 | 📁 Comparing e8ff078 against latest (76d1044)

  🔍 Preview build  

1 file changed
± changelog.html

@rafatahmed
rafatahmed merged commit 96981ed into main Oct 22, 2026
6 checks passed
@rafatahmed
rafatahmed deleted the fix/unreachable-ceiling branch October 22, 2026 13:55
@rafatahmed rafatahmed self-assigned this Oct 23, 2026
rafatahmed added a commit that referenced this pull request Nov 7, 2026
Leave out products for a ceiling the water already exceeds (#86)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

recommend() fails with an NNLS error when the water alone exceeds one maximum and another binds

1 participant

0