Intruduction, debugging codegen generated code

35 views
Skip to first unread message

Christian Friedl

unread,
Jan 17, 2020, 7:12:56 AM1/17/20
to sy...@googlegroups.com
Hello everyone!

Introduction
===
Here is a short introduction as suggested by
https://github.com/sympy/sympy/wiki/Introduction-to-contributing

- level of familiarity with python
Somewhat, mostly for small personal projects.

- mathematical education level
Msc.

- particular expertise
Physics.

- level of familiarity with symbolic math systems
Somewhat. Tried some, got frustrated, resorted to pen and paper. Tried
again when using a lot of paper got even more frustrating.

- your familiarity with SymPy
I used it mostly to solve small examples (e.g. tedious integrals) or
calculating derivatives of complicated expressions.
===
Question about codegen

When debugging generated code it is often not immediately clear, what
part of a symbolic sympy expression is responsible for which line of
C/Fortran code. This is a problem that basically all compiled/transpiled
languages have. In compilers this is solved by annotating "debugging
symbols", in javascript transpilers there are so called "source maps"
that allow to track what part of the expression written is actually
executed. Is there a similar annotating functionality in the 'codegen'
module? Can anybody think of a way to do the annotating manually?

Kind regards,
Christian

Aaron Meurer

unread,
Jan 17, 2020, 12:16:16 PM1/17/20
to sympy
I haven't thought of this before. I think one could add support for
it. It would require adding some bookkeeping to the code printers.

Another idea would be to wrap expressions with some function that
codegens into no-op backreferences.

Finally, we could codegen comments giving the str() form of an
expression above each line of code.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/a3f18892-66a2-80f5-b2aa-e1167c99ceaa%40gmx.at.

Christian Friedl

unread,
Feb 5, 2021, 2:49:44 PM2/5/21
to sy...@googlegroups.com
I found out recently that the C preprocessor has a feature called
"Line Control" https://gcc.gnu.org/onlinedocs/cpp/Line-Control.html

If the code is generated from a python file, then this could be used to
indicate where from which line in this python file the code came from.

This is how other preprocessors including f2c handle this situation.

Christian
Reply all
Reply to author
Forward
0 new messages