Ask Your Question
6

What is your favorite way to debug sage code?

asked 2010-10-13 17:42:44 +0200

Philipp Schneider gravatar image

How do you debug sage code?

My favorite way do debug Python code is to use pdb in GUD emacs-mode.

I split the window into two buffers; in one I interact with pdb, in the other I see the code I'm debugging with the current line highlighted. When I step into a function which is defined in a different file, this window automatically shows the content of the new file.

Is it possible to use pdb and GUD with sage? Or is it possible to achieve this effect in a different way?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2010-10-13 19:23:20 +0200

Mitesh Patel gravatar image

Here's one way to use Emacs' Grand Unified Debugger (GUD) with the Sage library:

  • Ensure sage is in the PATH.
  • cd SAGE_ROOT
  • cp local/lib/python/pdb.py .
  • Change the first line of pdb.py to #!/usr/bin/env sage
  • Run emacs and type M-x pdb + <ENTER>
  • Use Run pdb (like this): ./pdb.py foo.py to debug foo.py.

Caveats:

  • foo.py should contain a statement like from sage.all import *, in order to use Sage library code.
  • The code in foo.py should not require the Sage preparser. You'll need to use R = PolynomialRing(QQ, 'a,b,c'), for example, instead of R.<a,b,c> = QQ[].

I hope there's a better way! But with this approach, stepping into R = PolynomialRing(QQ, 'a,b,c') will make Emacs jump to the appropriate line of polynomial_ring_constructor.py.

edit flag offensive delete link more

Comments

Thanks. This is not a pretty solution, but it works. Also, instead of avoiding code that needs to be preparsed I can run sage -preparse foo.sage and then debug the resulting foo.py...

Philipp Schneider gravatar imagePhilipp Schneider ( 2010-10-13 20:12:39 +0200 )edit

I sometimes use the trace() function in Sage for a quick debugging job.

mvngu gravatar imagemvngu ( 2010-10-13 20:48:12 +0200 )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

Stats

Asked: 2010-10-13 17:42:44 +0200

Seen: 3,216 times

Last updated: Oct 13 '10