8000 fix: use measured stock solubility and the A/B tank layout (G15-G22) by rafatahmed · Pull Request #230 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ each release, with numbers, sources and decisions, are in

- EC is a range, never refused. Its low end counts the species with a coefficient; its high end adds 80 per charge for those without, for phosphate beyond its fit domain and for unrecorded charge. `status` is `estimated` or `range`, with no midpoint. Removed: `partial`, the assay-residual and phosphate-fit refusals. `--ec` compares a requested EC (G6–G9, #224).

- Stock solubility compares each product with its own measured value, in the value's basis, with the source and tank temperatures shown and nothing interpolated (decisions G15-G19, #226). Order: the catalogue's waterSolubility, the historical table, none. Statuses are `ok`, `exceeds` (blocks) and `not_checked`; `screening_only`, `inconclusive` and `assumed_density_floor` are removed.
- Tanks follow the A/B layout (decisions G20-G22, #227): calcium and every micronutrient product in tank A, phosphates, magnesium sulfate and macro sulfates in tank B. The magnesium-phosphate rule is removed and the calcium-sulfate reason is reworded. A batch needing a third tank names the pair and the rule.

### Fixed

- Capture the PHREEQC product fixtures from the packaged catalogue (Micro Combi Mix 2 replaces the retired CH - micro; the citrate case is dropped as no catalogue product holds citrate), so the golden test runs the engine's label reconciliation without a patch (#222).
Expand Down
2 changes: 2 additions & 0 deletions docs/releases/0.7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The full text of every change in 0.7.0, as recorded when each was merged, newest
- A water analysis is taken as measured (decisions G10 and G11, #216). `balance_water_analysis` no longer rejects an imbalance (the 5 % limit and `charge_imbalance_exceeded`), no longer closes on Cl-, Na+ or an adjusted carbonate (`balance_ion`, `maximum_imbalance_percent`, `balance_ion_uncertainty_percent` and `fixed` are removed, as are `missing_balance_ion`, `fixed_balance_ion`, `reconciliation_out_of_bounds` and `closed_on_alkalinity`), and returns `imbalance_percent` and `residual_charge_eq`, which the pH solves, the pH-adjustment planner and the joint problem's reference charge carry. Carbon taken from a titrated alkalinity stays, because it comes from a measurement. `calculate_ec_from_totals` takes `residual_charge_eq_per_kgw` for its calculated-pH mode, and a reagent search that leaves the activity model's range gives the pH-adjustment stage `not_calculated`. A water file with `balance_ion` or `balance_ion_uncertainty_percent` is refused with `unknown_field`. The 0.1 % initial-charge gates of the acid-option and delivery planners (`charge_imbalance`) are removed because their doses are found from charge differences. The formula-imbalance flag `exceedsWarning` and `ION_BALANCE_WARNING_PCT` are removed; `recommend` states the imbalance as "The formula's declared ions are not balanced: cations {c} vs anions {a} meq/L ({p} %)." and never claims no salt combination meets the targets.
- Precipitation is reported by evidence and never refuses a candidate or a plan (decisions G12–G14, #221). `assess_saturation(state)` returns `risk` (the readily forming phases `CaHPO4:2H2O`, `Gypsum` and `Calcite` above saturation, and any allocated solid), `information` (every other supersaturated phase with the basis of its constant: MnHPO4 is an unmeasured constant, Plummer et al. 1976 program data; the rest are database constants, minteq.v4, not individually reviewed), `advisories` (Iron(II) is held at a fixed oxidation state; in an aerated tank it oxidizes.) and `solids`. Gypsum is detected only as the by-product of bad mixing and is never an input, a product, a reference value or a remedy. Removed: the `blocks`, `blocking`, `review`, `thermodynamic` and `applicability` keys, the `conditions`, `evidence` and `si_uncertainty` parameters, the `precipitation_risk` rejection in the acid, pH-reagent and delivery planners, and `mixing_approved`. The summary carries `chemistry.risk` and `chemistry.information`; `statuses.phase` is `requires_review` with a risk and `assessed` without. A risk reads "The recipe carries a precipitation risk: CaHPO4:2H2O SI 0.16."
- EC is a range, never refused and never blocking (decisions G6–G9, #224). `calculate_ec_from_totals` returns `ec25_range_ms_cm = (low, high)`: `low` is the sum over the species with a conductivity coefficient; `high` is `low` plus `|z| × 80 × m` (`LAMBDA_MAX_PER_CHARGE = 80.0`) for each species without one, for H2PO4- and HPO4-2 beyond the phosphate fit ionic strength, and for the charge a supplied pH leaves unbalanced. `ec25_ms_cm` is `low` only when `low == high`, otherwise `None`; there is no midpoint in any output. `status` is `estimated` or `range`; only a state the activity model cannot solve is `not_supported`. The assay charge residual is reported in the result and never changes the status. Removed: the `partial` status, the `assay_charge_residual_too_large`, `ionic_strength_outside_phosphate_fit`, `missing_species_contributions` and `unrecorded_counterions` reasons of `calculate_ec_from_totals`, and the 0.1 % assay gate. The qualifier of every result is now "Model: McCleskey et al. (2012); its reported accuracy (-0.7 ± 5 %) is for natural waters, not fertilizer solutions. Measure EC after mixing." `flahax batch --ec` and `summarize_batch(requested_ec_ms_cm=...)` compare a requested EC25 with the range: "compatible with the estimated range; target attainment unverified", or "requested {r:.2f} mS/cm is {d:.2f} mS/cm from the estimated range". The report card, the batch sheet and the mix sheet show the range as low to high.
- Stock solubility uses measured data (decisions G15-G19, #226). `check_stock_solubility(tanks, ratio, temperature_c, *, table=None, product_grades=None, products=None)` compares each stock g/L with the product's `physicalProperties.waterSolubility` (catalogue records passed as `products`), then with the historical table, then reports `not_checked` with reason "no solubility data". The comparison is in the source's own basis, with no conversion and no solution density assumed; a value in an unknown unit is `not_checked`. Each row states `basis`, `source_temperature_c` and `tank_temperature_c` and there is no interpolation (a table uses its nearest point, the lower on a tie). Statuses: `ok`, `exceeds` (blocks), `not_checked`. Removed: `screening_only`, `inconclusive`, `assumed_density_floor`, the `screening_g_per_l` field, the review, grade and interpolation-review qualification of limits. Every row and the sheet say "single-product check; the mixed tank is not assessed".
- Tanks use the A/B layout (decisions G20-G22, #227). `CLASS_RULES` keeps calcium-phosphate and calcium-sulfate for macro products only; the magnesium-phosphate rule is deleted, and the calcium-sulfate reason reads "calcium and sulfate precipitate in a concentrate". A micronutrient product (every nutrient in `MICRONUTRIENTS`) goes to tank A and is screened against phosphate only. A batch that needs more tanks than are available is blocked with "needs a third tank: P cannot share with Q (rule)".
- A target is met only within the numerical tolerance (decision G25, validated 2026-10-24): 1e-5 relative for a positive target, 1e-6 mg/L for a declared zero, 1e-4 pH units, in the new module `flahax.requirement_fit` (`met`, `RELATIVE_TOLERANCE`, `ZERO_TARGET_TOLERANCE_MG_PER_L`, `PH_TOLERANCE`) (#210). It replaces the ±1 % band (`engine.TOLERANCE_PCT`, removed) in `feasible`, in the short-target recovery, in the target-only diagnosis and in `unmetTargets`. `feasible` is every declared requirement met and no declared maximum exceeded. Every deviation is reported: in `plan_fertilizer_workflow` the formulation stage blocks (`infeasible_recipe`) only on a broken declared maximum; a missed target makes it `requires_review` with "targets missed: …" (each difference to three significant figures in fixed notation, for example +1400 %, before any incidental-nutrient review), and the batch, titration, nitric, acid and stock stages continue (`FinalSolutionRecipe.feasible` is true unless a declared maximum is broken). A deviation the formulation stage accepts never blocks a later stage, and `plan_equilibrium_delivery` plans an accepted empty recipe on the water alone (it formerly required a nonempty recipe): the titration, nitric (`plan_equilibrium_delivery`) and acid-selection (`plan_acid_options`) stages judge only the change their reagent makes. `maximum_nutrient_error_percent` is now optional with no default, and every stage rejects a declared value that is not finite and positive (`invalid_value`; the nitric adapter formerly accepted 0) (the titration stage formerly defaulted to 1 %, and each stage compared the whole deviation from the target); when given, it is a declared requirement on the reagent's own change to each positive target, measured from the recipe before the reagent, and a stage fails with `nutrient_tolerance_exceeded` only when that change exceeds it, or with `nutrient_limit_exceeded` when the reagent pushes a nutrient past a declared maximum. A declared zero is met within 1e-6 mg/L everywhere: in `limitViolations`, `requirementConflicts`, `unmetTargets` and on the sheets (5e-7 mg/L of urea from the water meets an absent or zero N_UREA; 2e-6 mg/L breaks it and blocks). The pH plan and the joint workflow use `PH_TOLERANCE` (1e-4) in place of the former 1e-3 in `ph_adjustment`; no tested pH result changed. A feed whose mixed pH is within 1e-4 of the target now reads "no pH reagent is needed" when no plan is selected, instead of asking for a base (#212). Because a target 0.0056 % short is now short, recovery admits a held-back product that is its only source: for Lettuce 2 (Howard Resh) on the packaged catalogue sodium molybdate replaces Micro Combi Mix 1 for Mo, which is then met exactly, sodium falls from 0.814 to 0.442 mg/L, and P finishes at 49.8384 mg/L for 50 (-0.323 %), a deviation the former band counted as met. The batch and mix sheets mark in red each target not met within the tolerance (formerly beyond 1 %), and the recovery warning reads "… stayed short of its target without it" (formerly "more than 1% short").
- N_NO3, N_NH4 and N_UREA are each their own fitted target (decision D1); total N is reported in `totalN` (target, final, difference, `fitted: false`) as the sum of the three forms and never fitted (#209, #201). An absent N_UREA is a declared zero, and urea-bearing products are not used unless the formula declares urea. N_NH4 absent or 0 is no ammonium requirement: no row and no ban (G24), so calcium nitrate stays usable. The ammonium the products bring is then held within min(10 % of total target N, 1.5 mmol/L NH4 = 21.01 mg/L N) (G23), with the basis "Dutch soilless practice (De Kreij, Voogt et al.)", reported in `ammoniumLimit` and shown on the batch summary, the report and the batch and mix sheets; a declared N_NH4 maximum replaces it and `max_ammonium_fraction=None` removes it. `solve_weights`, the coupled pH plan and the joint problem use the same nitrogen rows and allowance, and total N is recomputed after a pH reagent. For Cucumber (Howard Resh), N_NO3 140 and N_NH4 0, the allowance is 14 mg/L.
- The packaged catalogue is Flaha Agri Tech Analysis Ver 0.0 (Flaha Agri Tech, 2026-10-29; supplied by Flaha Agri Tech, not independent laboratory verification) (#206). `library.json` holds 29 products, 24 fertilizers and 5 pH products, 13 crop formulas and the 3 waters it held before. Every product carries the analysis review record (`analysisReview`), and the library records the analysis as a whole in `fertilizerAnalysis`. The pH products, all `role: ph_reagent` and never selected as nutrient salts, are Potassium Hydroxide (45% solution), Phosphoric Acid (75%), Nitric Acid (65% solution), Potassium Bicarbonate and Potassium Carbonate; `catalogue_ph_reagents()` returns all five, so `flahax batch` and `flahax mix` now evaluate the two packaged acids beside any acid given with `--acid`. New products: Nitric Acid (65% solution), Micro Combi Mix 1 and Micro Combi Mix 2. Removed products: Ammonium Dibasic Phosphate, Calcium Chloride (Dihydrate), CH - micro (kept as a retired reference in `retiredProductReferences`), Potassium Chloride, Potassium Citrate and Potassium Dibasic Phosphate; the packaged catalogue has no chloride product. Removed formulas: Chilli (maximumyield), Generic Bloom (maximumyield), Generic Dry Season (Howard Resh), Generic Grow (maximumyield), Generic Wet Season (Howard Resh), Generic for Berries (Growing Edge), Rice (Douglas Peckenpaugh) and Tropical Lettuce (Douglas Peckenpaugh). The catalogue Potassium Nitrate analysis is 2.57 % out of charge balance against KNO3, above the 1 % label limit, so chemistry stages that include it stop with `identity_inconsistent`; that limit is under review. NOTICE and the attribution test credit Flaha Agri Tech for the analysis.
Expand Down
17 changes: 9 additions & 8 deletions docs/site/agronomist/batch-command.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
> Historical example: the two-tank magnesium/phosphate waiver below is retired.
> Current assignments retain all separations, report required equipment, and do not
> approve unqualified stock mixtures. See [stock assignments](stock-assignments.md).
> The two-tank layout below is the current one: calcium and micronutrients in tank A,
> phosphates and magnesium sulfate in tank B. Assignments report any extra tank they
> need and do not approve a mixed stock. See [stock assignments](stock-assignments.md).

# A batch from files: `flahax batch`

Expand Down Expand Up @@ -120,9 +120,10 @@ Read it from top to bottom before you weigh anything.

2. **Quantities and assignments.** Product mass follows final batch volume. A blocked
sheet labels these as diagnostic and offers no preparation boxes. Assignments respect
separation constraints and may require more than two tanks; no magnesium/phosphate
separation is waived to fit equipment. Qualified solubility limits and unresolved
stock-mixture evidence remain visible.
separation constraints: micronutrients and calcium in tank A, the phosphates and
magnesium sulfate in tank B. If more than two tanks would be needed, the sheet names
the pair and the rule. Each product's single-product solubility check and the
unassessed mixed tank remain visible.

3. **pH.** Read the selected or rejected reagent diagnosis. Blocked quantities are not
instructions to add a reagent.
Expand Down Expand Up @@ -162,8 +163,8 @@ value on the sheet rather than relying on this arithmetic alone.
### Historical 0.6.0 figures

The following table and quoted doses are retained publication history, not current mixing instructions.
A current run of step 3 on the packaged catalogue (Flaha Agri Tech Analysis Ver 0.0) is
blocked; read the reasons on its sheet rather than the figures below.
A current run of step 3 on the packaged catalogue (Flaha Agri Tech Analysis Ver 0.0)
gives different figures; read the reasons on its sheet rather than the figures below.
Product chloride can contribute up to the explicit final chloride limit; the water-only
chloride value below is not necessarily the current final concentration.

Expand Down
30 changes: 13 additions & 17 deletions docs/site/agronomist/reading-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ warnings to read before mixing and blank lines for measured EC and pH.
The default grouping (`group_tanks`) follows Yara, *Fertilizantes para
fertirrigación*, page 65 mixing compatibility table, read with page 63. The
table's twelve "No" pairs are exactly three rules, applied to every product from
its elemental analysis. Calcium/phosphate, calcium/sulfate and
magnesium/phosphate separations remain hard constraints. Neither equipment count
nor a micronutrient's small dose waives them. These are conservative separation
its elemental analysis. Calcium/phosphate and calcium/sulfate separations among macro
products remain hard constraints, as does micronutrient/phosphate. Magnesium sulfate goes
with the phosphates in tank B. Neither equipment count nor a micronutrient's small dose
waives them. These are conservative separation
screens, not predictions of precipitation at every concentration.

`group_tanks` computes a minimum-tank layout under those constraints. Supply
Expand All @@ -115,20 +116,15 @@ interface, alternative search and approval boundary. Historical two-tank capture
are retained as historical evidence; they are not current preparation instructions.

The tank table states compatibility, not dissolution approval. The single-product
screen in `summary['solubility']` distinguishes qualified limits from conditional
screening floors. A floor exceedance is **inconclusive**, not proof that a product
will not dissolve. A comparison below a floor does not approve a mixed stock.
Unqualified comparisons keep the batch under review; other blocking findings
remain blocking.

The unchanged historical table contains 20 products, principally CRC-derived
values, plus CALCINIT and urea source values. Its density-one conversions are
conditional screening values, not measured limits. CALCINIT's source specifies
20 °C; the historical extension through 40 °C is no longer applied. Intermediate
temperatures require explicit interpolation review. Missing basis, grade, density
or temperature evidence is never silently supplied. See the
[qualification contract](solubility-qualification.md) for conversion equations,
source provenance and the caller-reviewed limit interface.
check in `summary['solubility']` compares each stock with that product's own
solubility value and states its basis and both temperatures. Above the value the batch
is blocked; a product without data is not checked and keeps the batch under review. No
comparison approves a mixed stock.

The catalogue's own solubility values come first, then the historical table of 20
products (principally CRC-derived values, plus CALCINIT and urea). Nothing is
interpolated and no missing value is supplied. See the
[solubility check](solubility-qualification.md) for the sources, bases and conversions.

Your own `compatibilityRule` records (`--rules`, or
`rules=` in Python) separate further products and override the micronutrient
Expand Down
Loading
Loading
0