Optimizing solutions¶
Using optimizer¶
Hydrosolver includes mathematical optimization for solutions based on projected gradient descent method on a simplex. The following example utilizes a high-level enduser interface hydrosolver.optimization.optimize
which takes over the formulation of the optimization problem with the standard weighet least squares objective functional and runs the optimization process with default parameters.
>>> from hydrosolver.solution import Solution
>>> from hydrosolver.composition import Composition
>>> from hydrosolver.optimization import optimize
>>> from hydrosolver.database import pure, compo, chelates, howard_resh
>>> composition_target = howard_resh['Resh composition for peppers']
>>> compositions = [
... compo['Hakaphos Basis 2'],
... pure['Calcium-ammonium nitrate decahydrate'],
... pure['Magnesium sulfate heptahydrate'],
... chelates['Fe-EDTA 13.3%'],
... chelates['Zn-EDTA 15%'],
... pure['Boric acid'],
... ]
>>> solution_init = Solution.dissolve(
... 150,
... Composition(name='RO water'),
... compositions,
... )
>>> solution_optimal = optimize(solution_init, composition_target)
>>> solution_optimal
Composition Amount in kg Amount in g
------------------------------------ -------------- -------------
Hakaphos Basis 2 0.153874 153.874
Calcium-ammonium nitrate decahydrate 0.148834 148.834
Magnesium sulfate heptahydrate 0.0579563 57.9563
Fe-EDTA 13.3% 0.00390307 3.90307
Zn-EDTA 15% 0.000175686 0.175686
Boric acid 0.000194851 0.194851
RO water 149.635 149635
Total: 150 150000
Composition: Resulting composition
Nutrient Ratio Amount mg/kg
---------- ----------- --------------
N (NO3-) 0.000172246 172.246
N (NH4+) 1.28593e-05 12.8593
P 4.02928e-05 40.2928
K 0.000340636 340.636
Mg 6.28412e-05 62.8412
Ca 0.000184008 184.008
S 5.02674e-05 50.2674
Fe 4.99947e-06 4.99947
Zn 3.2956e-07 0.32956
B 3.29649e-07 0.329649
Mn 5.12913e-07 0.512913
Cu 2.05165e-07 0.205165
Mo 1.02583e-08 0.0102583