Week 12

And finally we are here, the most awaited Week 12, the last week of my GSoC project. Week 12 was quite fruitful for me as I was able to address almost all of the left over work for completion of my project. If y’all remember where we had left off, during week 11 I was working towards finishing the first part of the symbolic ASR pass. The first part involved being able to support assignment and print statements for symbolic functions and operations. I was able to do this successfully. But then we had to cover a few functionalities to address during week 12 as mentioned below:

  • Support print statements without assigning the symbolic functions/operations to any prior variables.
  • Support chaining of operators and creating complex symbolic expressions.
  • Support assert statements through a visit_Assert function.
  • Support freeing of all basic variables through the basic_new_stack function.

The first 3 functionalities were added through #2255 and #2263. Support for freeing the variable was added through #2268.An example demonstrating these would be as follows

from sympy import Symbol, pi, S
from lpython import S

def test_chained_operations():
    x: S = Symbol('x')
    y: S = Symbol('y')
    z: S = Symbol('z')
    a: S = Symbol('a')
    b: S = Symbol('b')
    
    # Chained Operations
    w: S = (x + y) * ((a - b) / (pi + z))
    result: S = (w ** S(2) - pi) + S(3)
    
    # Print Statements
    assert(result == S(3) + (a -b)**S(2)*(x + y)**S(2)/(z + pi)**S(2) - pi)
    print(result)
    
    # Additional Variables
    c: S = Symbol('c')
    d: S = Symbol('d')
    e: S = Symbol('e')
    f: S = Symbol('f')
    
    # Chained Operations with Additional Variables
    x = (c * d + e) / f
    y = (x - S(10)) * (pi + S(5))
    z = y ** (S(2) / (f + d))
    result = (z + e) * (a - b)
    
    # Print Statements
    assert(result == (a - b)*(e + ((S(5) + pi)*(S(-10) + (e + c*d)/f))**(S(2)/(d + f))))
    print(result)
    assert(x == (e + c*d)/f)
    print(x)
    assert(y == (S(5) + pi)*(S(-10) + (e + c*d)/f))
    print(y)
    assert(z == ((S(5) + pi)*(S(-10) + (e + c*d)/f))**(S(2)/(d + f)))
    print(z)

test_chained_operations()

(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython --enable-symengine --backend=llvm symbolics.py
3 + (a - b)**2*(x + y)**2/(z + pi)**2 - pi
(a - b)*(e + ((5 + pi)*(-10 + (e + c*d)/f))**(2/(d + f)))
(e + c*d)/f
(5 + pi)*(-10 + (e + c*d)/f)
((5 + pi)*(-10 + (e + c*d)/f))**(2/(d + f))

(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython --enable-symengine --backend=c symbolics.py
3 + (a - b)**2*(x + y)**2/(z + pi)**2 - pi
(a - b)*(e + ((5 + pi)*(-10 + (e + c*d)/f))**(2/(d + f)))
(e + c*d)/f
(5 + pi)*(-10 + (e + c*d)/f)
((5 + pi)*(-10 + (e + c*d)/f))**(2/(d + f))

There were a few other things, we had to look into which were the following.

  • Make sure all symbolic integration tests pass through the llvm_sym, c_sym, cpython_sym backends. Initially we were able to support all these tests because we had added support for symbolic operations in the C backend but now we wanted the symbolic ASR pass to be responsible for executing these tests, hence as we finished implementing the pass , it was essential to test the tests out. Demonstrating the results , everything worked as expected.
(lf) anutosh491@spbhat68:~/lpython/lpython/integration_tests$ ./run_tests.py -b llvm_sym
Configuration results
---------------------
C compiler      : /usr/bin/cc
Build type: Debug
C compiler flags      : -g
Installation prefix: /usr/local
KIND: llvm_sym
FAST: no
PYTHON_LIBS_REQ: yes
LPYTHON: /home/anutosh491/lpython/lpython/src/bin/lpython
LPYTHON_RTLIB_DIR: /home/anutosh491/lpython/lpython/src/libasr/runtime
LPYTHON_RTLIB_LIBRARY: /home/anutosh491/lpython/lpython/src/runtime/liblpython_runtime_static.a
-- Configuring done
-- Generating done
-- Build files have been written to: /home/anutosh491/lpython/lpython/integration_tests/_lpython-tmp-test-llvm_sym
+ make -j8
[ 12%] Generating symbolics_02.o
[ 12%] Generating symbolics_01.o
[ 18%] Generating symbolics_06.o
[ 25%] Generating symbolics_04.o
[ 31%] Generating symbolics_08.o
[ 37%] Generating symbolics_05.o
[ 43%] Generating symbolics_07.o
[ 50%] Generating symbolics_03.o
[ 56%] Linking C executable symbolics_01
[ 62%] Linking C executable symbolics_07
[ 75%] Linking C executable symbolics_02
[ 75%] Linking C executable symbolics_08
[ 81%] Linking C executable symbolics_03
[ 87%] Linking C executable symbolics_06
[ 93%] Linking C executable symbolics_04
[100%] Linking C executable symbolics_05
[100%] Built target symbolics_07
[100%] Built target symbolics_03
[100%] Built target symbolics_01
[100%] Built target symbolics_02
[100%] Built target symbolics_08
[100%] Built target symbolics_05
[100%] Built target symbolics_06
[100%] Built target symbolics_04
+ ctest -j8 --output-on-failure
Test project /home/anutosh491/lpython/lpython/integration_tests/_lpython-tmp-test-llvm_sym
    Start 1: symbolics_01
    Start 2: symbolics_02
    Start 3: symbolics_03
    Start 4: symbolics_04
    Start 5: symbolics_05
    Start 6: symbolics_06
    Start 7: symbolics_07
    Start 8: symbolics_08
1/8 Test #3: symbolics_03 .....................   Passed    0.01 sec
2/8 Test #4: symbolics_04 .....................   Passed    0.02 sec
3/8 Test #2: symbolics_02 .....................   Passed    0.02 sec
4/8 Test #1: symbolics_01 .....................   Passed    0.02 sec
5/8 Test #5: symbolics_05 .....................   Passed    0.02 sec
6/8 Test #7: symbolics_07 .....................   Passed    0.02 sec
7/8 Test #8: symbolics_08 .....................   Passed    0.01 sec
8/8 Test #6: symbolics_06 .....................   Passed    0.02 sec

100% tests passed, 0 tests failed out of 8

Label Time Summary:
c_sym          =   0.14 sec*proc (8 tests)
cpython_sym    =   0.14 sec*proc (8 tests)
llvm_sym       =   0.14 sec*proc (8 tests)

Total Test time (real) =   0.05 sec
  • Removed redundant symbolic support from the C backend through #2260
  • Refactored to symbolic ASR pass to reduce code duplication/repetetion through #2263

I think another level of refactoring could be added to reduce code duplication through the macros defined in intrinsic_registry.h . Once this is done, the pass would look for structured and presentable overall. That would mostly complete everything that was mentioned in my GSoC proposal.

During the weekly meet with my mentors, we did have a small discussion about the future work involved and also created a github issue out of it (#2262). Something that stands out here and would need some investigation is that the symbolic integration tests work with the FAST flag but only with the c_sym backend and not the llvm_sym backend. As of now, we have disabled the FAST flag for our tests but we would like support this in future. This would be somthing I would like to investigate

As my GSoC journey comes to an end, I am happy and sad at the same time. I am happy because 3 months back when Ondřej Čertík introduced this project to me, I was quite skeptical and wasn’t sure if I could do justice to the project as it was something that had to be worked on from scratch and there wasn’t a concrete roadmap in place when we started out. Hence I would like to thank everyone from the organization who helped me out during these 12 weeks. I am sad because this was my 2nd time as a GSoC mentee and I won’t be allowed to take part a third time as per GSoC guidelines. Although you could expect me as a mentor for LPython/LFortran :)

Thank You for going through my series of blogs. I hope you liked my work. Bye untill next time !!!

Address

Mumbai, Maharashtra, India