Ask Your Question
3

Is there a command like Mathematica's Dynamic[] in Sage?

asked 2016-09-28 05:34:44 +0100

barrybr gravatar image

updated 2016-09-28 05:37:01 +0100

I'm on a Mac with OS 10.11.6 and I'm using Sage 7.2's notebook interface. I did things in Mathematica that I want to check in Sage, but I'm a beginner at Sage. In Mathematica it's possible to keep track of the execution of my code, especially to detect when it's hanging, by using the Mathematica Dynamic[] command. Is there anything like this command in Sage, or is there perhaps another way to track the progress of the execution of a lengthy computation that will let me know in real time if and when it hangs? At the moment I insert print commands in my code that result in thousands of tuples of values of a tuple of variables streaming vertically down my screen. Messy. I'd rather see the values of such a tuple simply update in place as they do, say, on a digital clock. (This is what Dynamic[] achieves in Mathematica.)

edit retag flag offensive close merge delete

Comments

There is a "profiling" section in the tutorial http://doc.sagemath.org/pdf/en/tutori... which could be helpful.

Mafra gravatar imageMafra ( 2016-09-30 13:17:21 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-10-01 20:08:04 +0100

tmonteil gravatar image

updated 2016-10-01 21:47:24 +0100

Sage in written in Python, so you can benefit of any good things from it. Searching a couple of seconds on the web led me to the following:

sage: from time import sleep
sage: from sys import stdout
sage: for i in range(10):
....:     stdout.write("\rDoing thing %i" % i)
....:     stdout.flush()
....:     sleep(1)

There might even be dedicated libraries.

edit flag offensive delete link more

Comments

This is fine for the command line, but not effective in the notebook. Output on stdout is appended to the cell rather than replacing its contents.

paulmasson gravatar imagepaulmasson ( 2016-10-01 21:49:33 +0100 )edit

Hmm, indeed. It works in the jupyter notebook however.

tmonteil gravatar imagetmonteil ( 2016-10-01 22:43:02 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-09-28 05:34:44 +0100

Seen: 646 times

Last updated: Oct 01 '16