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.Mon, 20 Sep 2021 06:38:57 +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.zjsMon, 20 Sep 2021 06:38:57 +0200https://ask.sagemath.org/question/59104/How to format the output of integrate() function when printing?https://ask.sagemath.org/question/57036/how-to-format-the-output-of-integrate-function-when-printing/ I want to compute the integral of a function like this:
fi = -0.000004*x^4*y^3+0.000015*x^4*y^2
print(integrate(fi,x))
It prints:
-(8e-07)*x^5*y^3 + (3e-06)*x^5*y^2
Is there a way to format the output so that:
- it uses normal decimal notation instead of exponential one (-0.0000008 instead of -(8e-07))
- it has a given precision (it will print 0.000001 instead of 0.000001111 for example)
I know how to do this with a single variable but not when displaying what the integrate() function returns.MichaelTheSlavSun, 09 May 2021 16:46:15 +0200https://ask.sagemath.org/question/57036/REPL-like outputhttps://ask.sagemath.org/question/46294/repl-like-output/Hello, Sage Community.
If I run the sage REPL in a terminal, and execute something like
for i in range(4):
print(i^2)
then we all know that Sage prints
0
1
4
9
In this case, I could create a class to intercept standard output to a variable, like:
class verboseBuffer:
def __init__(self):
self.buffer = ''
def write(self, s):
self.buffer += s
Then I just make
_verbOut_ = verboseBuffer()
sys.stdout = _verbOut_
and if I run the first chunk of code, then the integers will be stored in `_verbOut_.buffer`, instead of being printed to standard output as before. I finally can do
sys.stdout = sys.__stdout__
print(_verbOut_.buffer)
and this prints the contents of `_verbOut_.buffer`, i.e., the list at the beginning.
Now consider the same loop without the `print`:
for i in range(4):
i^2
Executed in the REPL, Sage will print exactly the same as before (even if I haven't specified to `print`), and I could do the same thing to redirect the standard output to a variable.
Now, on the other hand, I have a huge file for which I would like to print everything in the same way it is printed in the REPL. I can't add `print` to every single part of the file, so I have tried to redirect output to a variable as before, and print it in the last line. The problem is that, things like the last chunk of code, without an explicit `print` won't be stored in `_verbOut_.buffer` at the end of the execution.
My questions are:
1. Why does the Sage REPL prints all computations not assigned to a variable, like the `i^2` in the loop, but that doesn't happen if the code is in a file?
2. How can I obtain a REPL-like output without having to add `print` to everything in my long file?dsejasSun, 21 Apr 2019 05:10:21 +0200https://ask.sagemath.org/question/46294/How do i change the x and y steps of an plot?https://ask.sagemath.org/question/44237/how-do-i-change-the-x-and-y-steps-of-an-plot/So i want a coordinate system that has different steps for example.
i have this
plot(-1/2*x+1,(x,-2, 8), rgbcolor=('#00c147')) #h1
how can i change the steps at the x-axis, at the moment it prints the numbers at {-2,2,4,6,8}
and i want it to be {-2,-1,0,1,2,3,4,5,6,7,8}
how can i customize those steps at the x and y-axis and how can i make it printable that for example 1 step has the distance of 0.5cm+0.5cm on a plain A4 paper.
at the moment 1 is at 1.5cm, 2 at 3cm EDIT:(nvm the printer had the wrong settings)neorySun, 11 Nov 2018 15:03:26 +0100https://ask.sagemath.org/question/44237/Is it possible to get fortran code for an expression?https://ask.sagemath.org/question/41525/is-it-possible-to-get-fortran-code-for-an-expression/Hello, is it possible to get the fortran code for expressions in SageMath?
Here's what I mean:
sage: var('a b x y')
( a, b, x, y )
sage: eq = x^a + 3/2*y^b
sage: get_fortran(eq)
x**a + 3.0/2.0*y**b
Right now the best I can do as a workaround is:
sage: eq.__str__().replace('^', '**')
x**a + 3/2*y**b
but the numbers appear as integers, which makes the division be performed as integer division in Fortran, which forces me to manually change that. Is there a function I can use to get what I want?
Cheers
tomchoWed, 14 Mar 2018 02:55:01 +0100https://ask.sagemath.org/question/41525/Printing variable namehttps://ask.sagemath.org/question/40862/printing-variable-name/ How would I return a variable name in a function. E.g. If I have the function:
def mul(a,b):
return a*b
a = mul(1,2); a
b = mul(1,3); b
c = mul(1,4); c
This would return:
2
3
4
I would like it to return:
a = 2
b = 3
c = 4
How would I do this?pytonnoobMon, 29 Jan 2018 19:05:32 +0100https://ask.sagemath.org/question/40862/If I return a list from a function that is more than 26 elements, the list goes verticalhttps://ask.sagemath.org/question/37477/if-i-return-a-list-from-a-function-that-is-more-than-26-elements-the-list-goes-vertical/If I return a list from a function that is more than 26 elements, the list goes vertical instead of horizontal even if I turn pretty printing off. Is this normal, and can I turn it off? I'm just returning the list, not using print explicitly. i.e.
With range 26 in the testfunc it shows a horizontal list, but if I increase that to 27 it goes vertical:
def tester():
v=[]
for i in range(26):
v.append(3)
return vcybervigilanteMon, 01 May 2017 02:21:50 +0200https://ask.sagemath.org/question/37477/How to print equations and numbers on a single line:https://ask.sagemath.org/question/36183/how-to-print-equations-and-numbers-on-a-single-line/I am trying to print a string, an equation and a number on the same line using the following form:
B=var('B')
fce=var('fce', latex_name='f_{ce}')
fce=2.80e6 * B
values={B:1.0e5}
print "Electron Gyrofrequency=", show(fce) , "= %0.5e" % fce.substitute(values)
However the output does not show as a single line. Any help would be appreciated.lookin03820Wed, 04 Jan 2017 20:17:37 +0100https://ask.sagemath.org/question/36183/IPython/Jupyter extensionshttps://ask.sagemath.org/question/26586/ipythonjupyter-extensions/I would like to be able to print code objects in a markdown cell without having to completely regenerate them in markdown code or copy/paste values. Would it be possible to install the [IPython notebook extensions](https://github.com/ipython-contrib/IPython-notebook-extensions) on the Sage Math Cloud?
I've made a public notebook [here](https://cloud.sagemath.com/projects/b8cc072a-0bd7-46df-bed6-4d857c87721b/files/Pretty%20printing.html) so that anyone can see exactly what my problem is. It's a fairly thorough description, but it boils down to wanting to print values with pretty units. I would be willing to allow others to edit the notebook to fiddle around with fixing it.wlp2Sat, 18 Apr 2015 08:29:48 +0200https://ask.sagemath.org/question/26586/Print out notebook worksheethttps://ask.sagemath.org/question/10828/print-out-notebook-worksheet/Hi all.
When I try to click "Print" button on Sage Notebook Worksheet in Firefox, it just opens another browser window with HTML view of the Worksheet. Is there anyway I can send it to a printer or get a PDF file instead of HTML?amit112amitThu, 12 Dec 2013 18:28:34 +0100https://ask.sagemath.org/question/10828/Missing Jmol Images when printinghttps://ask.sagemath.org/question/8357/missing-jmol-images-when-printing/When I attempt to print a notebook worksheet using either Safari or Chrome containing four plot3D-Jmol images, several are black (not displayed). Is this a memory problem? Is there
a way to force the plots to be static images instead of live JMol applets.
Sorry to say this but if this is not fixed I won't be able to use Sage for undergraduate teaching as
I must be able to post PDF's of examples easily!
Prof. Adam Hausknecht
Department of Mathematics
UMass DartmouthahausknechtWed, 05 Oct 2011 00:11:17 +0200https://ask.sagemath.org/question/8357/