Ask Your Question
3

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

asked 8 years ago

barrybr gravatar image

updated 8 years ago

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.)

Preview: (hide)

Comments

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

Mafra gravatar imageMafra ( 8 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

tmonteil gravatar image

updated 8 years ago

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.

Preview: (hide)
link

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 ( 8 years ago )

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

tmonteil gravatar imagetmonteil ( 8 years ago )

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: 8 years ago

Seen: 819 times

Last updated: Oct 01 '16