While looking at fixing the GLPK scaling output I noticed that problem scaling actually did not take in the right place. The problem has to be scaled after it is fully built, however scaling was often performed before adding variables and constraints which has no effect. The best place to scale is before optimization as it ensures that the model is built and all changes are applied.
As a side effect that now also respects the verbosity output for scaling.
Example:
Python 3.10.5 (main, Jun 8 2022, 09:26:22) [GCC 11.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from cobra.io import load_model
In [2]: mod = load_model("textbook")
In [3]: mod.solver = "glpk"
In [4]: # note that there was no output here as before
In [5]: mod.solver.configuration.verbosity = 3
In [6]: mod.optimize()
Scaling...
A: min|aij| = 7.090e-02 max|aij| = 5.981e+01 ratio = 8.436e+02
GM: min|aij| = 1.856e-01 max|aij| = 5.389e+00 ratio = 2.904e+01
EQ: min|aij| = 3.443e-02 max|aij| = 1.000e+00 ratio = 2.904e+01
GLPK Simplex Optimizer 5.0
72 rows, 190 columns, 720 non-zeros
0: obj = -0.000000000e+00 inf = 1.006e+00 (5)
54: obj = -0.000000000e+00 inf = 1.274e-15 (0)
* 81: obj = 8.739215070e-01 inf = 2.428e-14 (0)
OPTIMAL LP SOLUTION FOUND
Out[6]: <Solution 0.874 at 0x7f3bfcb9c070>
In [7]: # note that there was actual scaling here, this did not happen before
While looking at fixing the GLPK scaling output I noticed that problem scaling actually did not take in the right place. The problem has to be scaled after it is fully built, however scaling was often performed before adding variables and constraints which has no effect. The best place to scale is before optimization as it ensures that the model is built and all changes are applied.
As a side effect that now also respects the verbosity output for scaling.
Example: