ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 22 Sep 2021 03:25:41 +0200Suppress mixed integer programming outputhttps://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/I am running code on a remote server in which I solve many small mixed integer programs(using the `.solve()` method). I tested my code on my local machine with no issues. However, when I run it remotely it seems that the Sage installation there does not suppress output from `.solve()`. I get many, many prints to the console which look like:
glp_exact: 224 rows, 196 columns, 588 non-zeros
GNU MP bignum library is being used
0: infsum = 2 (11)
47: infsum = 0 (11)
* 47: objval = 1.39285714285714 (12)
* 205: objval = 0.660714285714286 (5)
OPTIMAL SOLUTION FOUND
It would be very helpful to not have Sage constantly printing to the console; is there a way to suppress this output? Some sort of flag, maybe, when I run Sage?
EDIT: In response to David Coudert's comment, here is the kind of behavior I'm seeing, on a relevant snippet:
sage: def opt(x):
....: mip = MixedIntegerLinearProgram(maximization=False, solver="GLPK/exact")
....: mip.add_constraint(mip[0]+mip[1] <= 1)
....: mip.add_constraint(mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]+mip[1] <= 1)
....: mip.set_objective(mip[0]+x*mip[1])
....: return mip.solve()
....:
sage: [opt(n) for n in range(3)]
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 1: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -2 (0)
OPTIMAL SOLUTION FOUND
[-1.0, -1.0, -2.0]
I would only like to have the final line of output printed to the console, yet am also finding the three pieces from GLPK put there too.
EDIT 2: I realized I forgot to mention that I'm running Sage 7.4 and that I may have trouble installing CPLX or Gurobi on the server since I do not have admin privileges there. These appear to be the only solvers which allow for the `"logfile"` approach.Mon, 20 Sep 2021 06:38:57 +0200https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/Comment by zjs for <p>I am running code on a remote server in which I solve many small mixed integer programs(using the <code>.solve()</code> method). I tested my code on my local machine with no issues. However, when I run it remotely it seems that the Sage installation there does not suppress output from <code>.solve()</code>. I get many, many prints to the console which look like: </p>
<pre><code>glp_exact: 224 rows, 196 columns, 588 non-zeros
GNU MP bignum library is being used
0: infsum = 2 (11)
47: infsum = 0 (11)
* 47: objval = 1.39285714285714 (12)
* 205: objval = 0.660714285714286 (5)
OPTIMAL SOLUTION FOUND
</code></pre>
<p>It would be very helpful to not have Sage constantly printing to the console; is there a way to suppress this output? Some sort of flag, maybe, when I run Sage? </p>
<p>EDIT: In response to David Coudert's comment, here is the kind of behavior I'm seeing, on a relevant snippet: </p>
<pre><code>sage: def opt(x):
....: mip = MixedIntegerLinearProgram(maximization=False, solver="GLPK/exact")
....: mip.add_constraint(mip[0]+mip[1] <= 1)
....: mip.add_constraint(mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]+mip[1] <= 1)
....: mip.set_objective(mip[0]+x*mip[1])
....: return mip.solve()
....:
sage: [opt(n) for n in range(3)]
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 1: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -2 (0)
OPTIMAL SOLUTION FOUND
[-1.0, -1.0, -2.0]
</code></pre>
<p>I would only like to have the final line of output printed to the console, yet am also finding the three pieces from GLPK put there too.</p>
<p>EDIT 2: I realized I forgot to mention that I'm running Sage 7.4 and that I may have trouble installing CPLX or Gurobi on the server since I do not have admin privileges there. These appear to be the only solvers which allow for the <code>"logfile"</code> approach.</p>
https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59119#post-id-59119@David Coudert, thank you very much! The following indeed seems to work (inserted immediately following the declaration of the `MixedIntegerLinearProgram`):
mip.solver_parameter("simplex_or_intopt", "simplex_only")
mip.solver_parameter("verbosity_simplex", "GLP_MSG_OFF")
@tmonteil I am not sure if I will be able to upgrade Sage on the server because I do not have admin privileges.Wed, 22 Sep 2021 03:25:41 +0200https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59119#post-id-59119Comment by tmonteil for <p>I am running code on a remote server in which I solve many small mixed integer programs(using the <code>.solve()</code> method). I tested my code on my local machine with no issues. However, when I run it remotely it seems that the Sage installation there does not suppress output from <code>.solve()</code>. I get many, many prints to the console which look like: </p>
<pre><code>glp_exact: 224 rows, 196 columns, 588 non-zeros
GNU MP bignum library is being used
0: infsum = 2 (11)
47: infsum = 0 (11)
* 47: objval = 1.39285714285714 (12)
* 205: objval = 0.660714285714286 (5)
OPTIMAL SOLUTION FOUND
</code></pre>
<p>It would be very helpful to not have Sage constantly printing to the console; is there a way to suppress this output? Some sort of flag, maybe, when I run Sage? </p>
<p>EDIT: In response to David Coudert's comment, here is the kind of behavior I'm seeing, on a relevant snippet: </p>
<pre><code>sage: def opt(x):
....: mip = MixedIntegerLinearProgram(maximization=False, solver="GLPK/exact")
....: mip.add_constraint(mip[0]+mip[1] <= 1)
....: mip.add_constraint(mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]+mip[1] <= 1)
....: mip.set_objective(mip[0]+x*mip[1])
....: return mip.solve()
....:
sage: [opt(n) for n in range(3)]
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 1: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -2 (0)
OPTIMAL SOLUTION FOUND
[-1.0, -1.0, -2.0]
</code></pre>
<p>I would only like to have the final line of output printed to the console, yet am also finding the three pieces from GLPK put there too.</p>
<p>EDIT 2: I realized I forgot to mention that I'm running Sage 7.4 and that I may have trouble installing CPLX or Gurobi on the server since I do not have admin privileges there. These appear to be the only solvers which allow for the <code>"logfile"</code> approach.</p>
https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59113#post-id-59113I can not reproduce your issue with Sage `9.5.beta1`, i do not have any such noise. Perhaps could you just upgrade your version of Sage.Tue, 21 Sep 2021 17:00:25 +0200https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59113#post-id-59113Comment by David Coudert for <p>I am running code on a remote server in which I solve many small mixed integer programs(using the <code>.solve()</code> method). I tested my code on my local machine with no issues. However, when I run it remotely it seems that the Sage installation there does not suppress output from <code>.solve()</code>. I get many, many prints to the console which look like: </p>
<pre><code>glp_exact: 224 rows, 196 columns, 588 non-zeros
GNU MP bignum library is being used
0: infsum = 2 (11)
47: infsum = 0 (11)
* 47: objval = 1.39285714285714 (12)
* 205: objval = 0.660714285714286 (5)
OPTIMAL SOLUTION FOUND
</code></pre>
<p>It would be very helpful to not have Sage constantly printing to the console; is there a way to suppress this output? Some sort of flag, maybe, when I run Sage? </p>
<p>EDIT: In response to David Coudert's comment, here is the kind of behavior I'm seeing, on a relevant snippet: </p>
<pre><code>sage: def opt(x):
....: mip = MixedIntegerLinearProgram(maximization=False, solver="GLPK/exact")
....: mip.add_constraint(mip[0]+mip[1] <= 1)
....: mip.add_constraint(mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]+mip[1] <= 1)
....: mip.set_objective(mip[0]+x*mip[1])
....: return mip.solve()
....:
sage: [opt(n) for n in range(3)]
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 1: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -2 (0)
OPTIMAL SOLUTION FOUND
[-1.0, -1.0, -2.0]
</code></pre>
<p>I would only like to have the final line of output printed to the console, yet am also finding the three pieces from GLPK put there too.</p>
<p>EDIT 2: I realized I forgot to mention that I'm running Sage 7.4 and that I may have trouble installing CPLX or Gurobi on the server since I do not have admin privileges there. These appear to be the only solvers which allow for the <code>"logfile"</code> approach.</p>
https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59111#post-id-59111Since you use `"GLPK/exact"`, can you try `mip.solver_parameter("verbosity_simplex", "GLP_MSG_OFF")`.
You can find the list of parameters you can modify at https://doc.sagemath.org/html/en/reference/numerical/sage/numerical/backends/glpk_backend.html
I checked the interfaces we other solvers and currently we can only set the log file for `cplex` and `gurobi`.Tue, 21 Sep 2021 15:28:08 +0200https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59111#post-id-59111Comment by zjs for <p>I am running code on a remote server in which I solve many small mixed integer programs(using the <code>.solve()</code> method). I tested my code on my local machine with no issues. However, when I run it remotely it seems that the Sage installation there does not suppress output from <code>.solve()</code>. I get many, many prints to the console which look like: </p>
<pre><code>glp_exact: 224 rows, 196 columns, 588 non-zeros
GNU MP bignum library is being used
0: infsum = 2 (11)
47: infsum = 0 (11)
* 47: objval = 1.39285714285714 (12)
* 205: objval = 0.660714285714286 (5)
OPTIMAL SOLUTION FOUND
</code></pre>
<p>It would be very helpful to not have Sage constantly printing to the console; is there a way to suppress this output? Some sort of flag, maybe, when I run Sage? </p>
<p>EDIT: In response to David Coudert's comment, here is the kind of behavior I'm seeing, on a relevant snippet: </p>
<pre><code>sage: def opt(x):
....: mip = MixedIntegerLinearProgram(maximization=False, solver="GLPK/exact")
....: mip.add_constraint(mip[0]+mip[1] <= 1)
....: mip.add_constraint(mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]+mip[1] <= 1)
....: mip.set_objective(mip[0]+x*mip[1])
....: return mip.solve()
....:
sage: [opt(n) for n in range(3)]
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 1: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -2 (0)
OPTIMAL SOLUTION FOUND
[-1.0, -1.0, -2.0]
</code></pre>
<p>I would only like to have the final line of output printed to the console, yet am also finding the three pieces from GLPK put there too.</p>
<p>EDIT 2: I realized I forgot to mention that I'm running Sage 7.4 and that I may have trouble installing CPLX or Gurobi on the server since I do not have admin privileges there. These appear to be the only solvers which allow for the <code>"logfile"</code> approach.</p>
https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59106#post-id-59106@David Coudert, I have added a code snippet and output sample to the main post. Just to be totally certain, changing `.solver_parameter` will only do so for the GLPK output, yes? Since I am still interested in printing other content to the console.Mon, 20 Sep 2021 19:16:22 +0200https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59106#post-id-59106Comment by David Coudert for <p>I am running code on a remote server in which I solve many small mixed integer programs(using the <code>.solve()</code> method). I tested my code on my local machine with no issues. However, when I run it remotely it seems that the Sage installation there does not suppress output from <code>.solve()</code>. I get many, many prints to the console which look like: </p>
<pre><code>glp_exact: 224 rows, 196 columns, 588 non-zeros
GNU MP bignum library is being used
0: infsum = 2 (11)
47: infsum = 0 (11)
* 47: objval = 1.39285714285714 (12)
* 205: objval = 0.660714285714286 (5)
OPTIMAL SOLUTION FOUND
</code></pre>
<p>It would be very helpful to not have Sage constantly printing to the console; is there a way to suppress this output? Some sort of flag, maybe, when I run Sage? </p>
<p>EDIT: In response to David Coudert's comment, here is the kind of behavior I'm seeing, on a relevant snippet: </p>
<pre><code>sage: def opt(x):
....: mip = MixedIntegerLinearProgram(maximization=False, solver="GLPK/exact")
....: mip.add_constraint(mip[0]+mip[1] <= 1)
....: mip.add_constraint(mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]-mip[1] <= 1)
....: mip.add_constraint(-mip[0]+mip[1] <= 1)
....: mip.set_objective(mip[0]+x*mip[1])
....: return mip.solve()
....:
sage: [opt(n) for n in range(3)]
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 1: objval = -1 (0)
OPTIMAL SOLUTION FOUND
glp_exact: 4 rows, 2 columns, 8 non-zeros
GNU MP bignum library is being used
* 0: objval = 0 (0)
* 2: objval = -2 (0)
OPTIMAL SOLUTION FOUND
[-1.0, -1.0, -2.0]
</code></pre>
<p>I would only like to have the final line of output printed to the console, yet am also finding the three pieces from GLPK put there too.</p>
<p>EDIT 2: I realized I forgot to mention that I'm running Sage 7.4 and that I may have trouble installing CPLX or Gurobi on the server since I do not have admin privileges there. These appear to be the only solvers which allow for the <code>"logfile"</code> approach.</p>
https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59105#post-id-59105Can you give a (minimal) example of the kind of code you use ? Also, have you tried to set the log filename `p.solver_parameter("logfile", "/path/to/some/logfile.txt")` or `p.solver_parameter("logfile", "/dev/null")` ? it seems that the output you get is what should be in the log file.Mon, 20 Sep 2021 18:20:47 +0200https://ask.sagemath.org/question/59104/suppress-mixed-integer-programming-output/?comment=59105#post-id-59105