Sage Scripts

40 lượt xem
Chuyển tới thư đầu tiên chưa đọc

nkulmati

chưa đọc,
01:23:42 10 thg 4, 201110/4/11
đến sage-support
Hi All, I am a newbie to Sage. My main purpose is to write scripts
(algorithms). That is, I am not interested in the "answer-question"
approach of the notebook, but I want to write and execute ".sage"
files using sage just as I do with ".m" files using Matlab, for
example.

So I found this page: http://www.sagemath.org/doc/tutorial/programming.html

However, when I use "load test.sage", everything works (variables get
created and computed) but there is no output like the one I get by
entering my algorithm line-by-line directly.

For example, the command "G.plot()" gets totally ignored by the "load'
function.

How can I use sage to run scripts that involve real-time plotting and
other output?

Kelvin Li

chưa đọc,
01:49:42 10 thg 4, 201110/4/11
đến sage-support
On Apr 9, 10:23 pm, nkulmati <kulmatits...@gmail.com> wrote:
> Hi All, I am a newbie to Sage. My main purpose is to write scripts
> (algorithms). That is, I am not interested in the "answer-question"
> approach of the notebook, but I want to write and execute ".sage"
> files using sage just as I do with ".m" files using Matlab, for
> example.
>
> So I found this page:http://www.sagemath.org/doc/tutorial/programming.html
>
> However, when I use "load test.sage", everything works (variables get
> created and computed) but there is no output like the one I get by
> entering my algorithm line-by-line directly.
>
> For example, the command "G.plot()" gets totally ignored by the "load'
> function.
>

"load" is not ignoring "G.plot()". The function is actually executed,
but the return value is lost. It can be assigned to a variable with:

my_plot_object = G.plot()

There's a couple of things you can do to see your output.

In the case of "G.plot()", that function returns a graphics object. To
save your plot as an image, you can do something such as:

G.plot.save("my_plot.png")

See: [http://www.sagemath.org/doc/reference/sage/plot/
plot.html#sage.plot.plot.Graphics.save]
for more information.

In the Sage notebook, if "G.plot()" is not the last line of a cell,
the return value is similarly thrown away. In the notebook,
additionally, the output can be directly shown with:

G.plot().show()

See: [http://www.sagemath.org/doc/reference/sage/plot/
plot.html#sage.plot.plot.Graphics.show]
for more information.

If you want to output some line of text, you'll need to use the print
statement. If "my_result" is the variable containing the result of
your computation, you can use:

print my_result

Same story for the notebook as explained above.

> How can I use sage to run scripts that involve real-time plotting and
> other output?

I'm not sure what you mean by this. You can try looking at the
@interact decorator in the Sage notebook.

As an unrelated side note, you can also run sage scripts directly from
the command line with:

sage my_sage_script.sage

This will work if you add your sage installation directory to your
$PATH variable. See "sage --help" for more info.

Hope this answers some of your questions.

-- Kelvin

Kelvin Li

chưa đọc,
01:51:56 10 thg 4, 201110/4/11
đến sage-support
> In the case of "G.plot()", that function returns a graphics object. To
> save your plot as an image, you can do something such as:
>
>     G.plot.save("my_plot.png")

Oops, that should be

G.plot().save("my_plot.png")

-- Kelvin

Justin C. Walker

chưa đọc,
02:55:43 10 thg 4, 201110/4/11
đến sage-s...@googlegroups.com

To enlarge on what Kelvin tells you, there are some differences between executing commands at the command prompt, and executing them from a script.

If you just list the commands in the script and then load it, some "side effects" (like invoking a program to display a plot) don't happen.

One way to do what you want is to assign the results of the graphics operations to variables, and then display them after the file is loaded.

Another approach is to return one or more graphics from a procedure you define in your script. For example, if your script looked like

E=EllipticCurve("389a1")
E.plot()

then loading the script will not produce a plot. Instead, make your script look like this:

def DoIt():
E=EllipticCurve("389a1")
return E.plot()

Then the "return values" that Kelvin mentions don't get lost. With this in your script, at the sage prompt (after loading your script), use either

DoIt()

to get the plot displayed immediately, or

g = DoIt()

to save the plot for later use. If you want to deal with multiple "values" that seem to be getting lost, return them all:
return g1, g2, g3

These will be returned as a list, and you can invoke your function as

G=DoIt() # G will be the list [g1,g2,g3]

or

g1,g2,g3=DoIt()

Others on the list may be able to shed more light.

HTH

Justin

--
Justin C. Walker, Curmudgeon at Large
Director
Institute for the Enhancement of the Director's Income
-----------
Nobody knows the trouble I've been
-----------

nkulmati

chưa đọc,
22:57:09 16 thg 4, 201116/4/11
đến sage-support
Thanks for your replies! They helped.

However, I had a major disappointment. I wrote a short script, and it
is apparently too much for sage/python to handle when I am running a
virtual machine from Win 7. I use process monitor and it goes like
this: when I run my script, both the CPU and RAM usage (in virtual
machine) SHOOT up to 100%, and then swapping begins, after two minutes
or so the CPU falls back to around 0 but the memory never gets
released back from 100%, and my whole ubuntu, the whole virtual
machine, freezes. (While the system monitor still shows steady 100%
usage of memory). I have to restart the VM.

This is frustrating! Is sage really NOT to be used under Windows??
Even without my script, the notebook is pretty slow (like everything
in the virtual machine). This whole "python-under virtual-machine"
idea renders sage impossible to use!! So is this really a matlab/etc
substitute?? :( So disappointed.

Dan Drake

chưa đọc,
19:54:15 17 thg 4, 201117/4/11
đến sage-s...@googlegroups.com
On Sat, 16 Apr 2011 at 07:57PM -0700, nkulmati wrote:
> This whole "python-under virtual-machine" idea renders sage impossible
> to use!!

Actually, it renders Sage "possible to use" for many people. Remember
that you can always use one of the public Sage servers or set up one of
your own -- as those work in web browsers, they'll be fine if you use
Windows.

> So is this really a matlab/etc substitute?? :( So disappointed.

Right now the Windows situation isn't so great, but we're trying to
improve that. If you know how to work with Cygwin, you could help move
the Cygwin port along.


Dan

--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------

signature.asc

Simon King

chưa đọc,
09:26:57 18 thg 4, 201118/4/11
đến sage-support
On 17 Apr., 04:57, nkulmati <kulmatits...@gmail.com> wrote:
> However, I had a major disappointment. I wrote a short script, and it
> is apparently too much for sage/python to handle when I am running a
> virtual machine from Win 7. I use process monitor and it goes like
> this: when I run my script, both the CPU and RAM usage (in virtual
> machine) SHOOT up to 100%, and then swapping begins, after two minutes
> or so the CPU falls back to around 0 but the memory never gets
> released back from 100%, and my whole ubuntu, the whole virtual
> machine, freezes. (While the system monitor still shows steady 100%
> usage of memory). I have to restart the VM.

I never worked with a virtual machine in Windows, so, I am not really
an expert. However, I thought it should be possible to use something
like ulimit in order to prevent the VM from freezing (simply because
the application is killed before the VM freezes)?

Cheers,
Simon

A. Jorge Garcia

chưa đọc,
10:19:37 18 thg 4, 201118/4/11
đến sage-s...@googlegroups.com
I tried VMs years ago (not for SAGE) and I REALLY did not like how many
resources are needed to run the simplest app.

I tend to run natively now (I use Ubuntu Linux for SAGE). If you are
stuck with Windows, you may have to increase your RAM. How much RAM are
you using?

In any case, I would recommend Linux boxes....

HTH,
A. Jorge Garcia
Applied Math and CompSci
http://shadowfaxrant.blogspot.com
http://www.youtube.com/calcpage2009

Cheers,
Simon

--
To post to this group, send email to sage-s...@googlegroups.com
To unsubscribe from this group, send email to
sage-support...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


achrzesz

chưa đọc,
11:50:08 18 thg 4, 201118/4/11
đến sage-support
Hello nkulmati

If you want to get rid of virtualization
maybe you should try Linux version without instalation
burning Live-CD first
The present version fits into memory and after (rather long)
start process the CD can be removed

It works quite satisfactory (if you have >=2GB RAM)

The native Linux version is much much better

Andrzej Chrzeszczyk

On 18 Kwi, 16:19, "A. Jorge Garcia" <calcp...@aol.com> wrote:
> I tried VMs years ago (not for SAGE) and I REALLY did not like how many
> resources are needed to run the simplest app.
>
> I tend to run natively now (I use Ubuntu Linux for SAGE). If you are
> stuck with Windows, you may have to increase your RAM. How much RAM are
> you using?
>
> In any case, I would recommend Linux boxes....
>
> HTH,
> A. Jorge Garcia
> Applied Math and CompScihttp://shadowfaxrant.blogspot.comhttp://www.youtube.com/calcpage2009
Trả lời tất cả
Trả lời tác giả
Chuyển tiếp
0 tin nhắn mới