Anutosh's Blog

Week 2

Anutosh
Published: 06/05/2023

What did I do this week?

During the second week of GSoC, the focus was on adding support for symbolic expressions in the `visit_print` and `visit_assignment` functions. Initially, an attempt was made to implement this using the LLVM backend but encountered strict limitations. As a result, the decision was made to switch to the C backend, which offers advantages such as simpler code generation and compatibility with existing C-based tools. Progress was made in implementing the necessary functions and generating C code to handle symbolic expressions.More detailed information can be found on my person blog here GSoC: Week 02

What will I be doing the next week ?

Tasks for the upcoming week include addressing details, introducing binary operators for symbolic expressions, and implementing casting functions.
 

Did I get stuck somewhere ?

My project does involve a lot of trial and error, hence I am bound to get stuck trying to figure the correct approach but there were no hard blockers as such and I was able to find workarounds wherever I got stuck .

 

View Blog Post

Week 1

Anutosh
Published: 06/01/2023

As I had discussed with Ondřej, my goal for the first couple of weeks would be to get a basic assignment and print statement working for a`SymbolicExpression` for instance the `Symbol` class from SymPy. So I had to support something like the following

from lpython import S
from sympy import Symbol

def main0():
   x: S = Symbol('x')
   print(x)

main0()

 

This task would comprise of the following few steps

  * Supporting imports from `SymPy` for `CPython`

  * Introducing the `SymbolicExpression` ttype

  * Introducing `SymbolicSymbol` as an intrinsic function

  * Adding support in `visit_print` and `visit_assignment` to handle symbolic expressions


I managed to raise a pull request 1846 and address the first 3 steps and I am halfway through with the 4th step. Hence we currently have a decent Abstract Semantic Representation (ASR) of our program above. It goes as follows:

[(=
    (Var 2 x)
    (IntrinsicFunction
        SymbolicSymbol
        [(StringConstant
            "x"
            (Character 1 1 () [])
        )]
        0
        (SymbolicExpression)
        ()
    )
    ()
)
(Print
    ()
    [(Var 2 x)]
    ()
    ()
)]

Well as of now, I can't claim that I have cracked the solution for the 4th step. As discussed in my weekly meeting with Ondřej, we are still not fully sure as to how we could support the above program in the backend. We are still exploring the most probable and easily achievable approaches . While framing my GSoC proposal, we were more inclined towards framing a pass which would make function calls to `SymEngine's C interface`. But as we were brainstorming during our meet we realized some potential downsides to this approach and hence we tried framing a somewhat newer approach for the same, which goes as follows:

  * Skip implementing `instantiate_SymbolicSymbol` and the pass to replace the intrinsic function node.

  * Take inspiration from how assignment statements work for the `Complex` ttype in LPython and try extending the `visit_assignment` function for symbolic expressions accordingly.

  * Introduce `symengine_str` function similar to how `print_f` for handling print statements.

I am halway through this approach and I feel this would be the correct way to go. I will try to resolve these in the 2nd week of my coding period.Finally, I would like to point out some tasks which need to be addressed in Week 2 or the upcoming weeks

  * Finish `generate_SymbolicSymbol` function implementation (kept as TODO for now)

  * Finish `SymbolicSymbol::verify_args` function implementation (kept as TODO for now)

  * Finish `eval_SymbolicSymbol` function implementation (kept as TODO for now)

Thank You for going through the blog. I hope you like it. Stick around for what's next to come. Moving into Week 2!

View Blog Post