bksahu's Blog

GSoC Wrap-up - Blog Post #6

bksahu
Published: 08/22/2019

Hello everyone!

GSoC 2019 has almost come to an end! It's the time to wrap up this mega event started back in May 2019. Under the mentorship of Mentor Hayen, my learning experience has undergone a roller-coaster ride and it has not only boosted my growth as a developer but also as an individual. Over the last 3 months the followings are my major contributions to this project:

Built-ins Optimizations

The following are in progress: * "max" and "min": PR #442 <https://github.com/Nuitka/Nuitka/pull/442> * "zip": PR #462 <https://github.com/Nuitka/Nuitka/pull/462>

Test suite

Documentation

And other minor doc fixes are added with their respective pull requests.

Over this period of time I have learnt a lot, starting from how to add new nodes to Nuitka and optimize them to optimization using reformulations. I plan to keep learning and contributing to Nuikta,

 

Thanks for stopping by!

bksahu

View Blog Post

Weekly Check-in #6

bksahu
Published: 08/14/2019

1. What did you do this week?

This week I added support for Python 3 <tt>zip()</tt> built-in and added git workflow in the developer manual which can be found here: https://github.com/Nuitka/Nuitka/pull/485.  And also worked on the remnants of Python 2 support for the same.

2. What is coming up next?

Now that support for keyword only arguments has been added in Nuitka, I will finish the remaining of optimizations support  for min() and max() built-ins.

3. Did you get stuck anywhere?

Yes, I was stuck on reformulation of zip() for Python2.

View Blog Post

Blog Post #5

bksahu
Published: 08/10/2019

Hi, welcome to my blog post #5!

Today we will see how are exception messages are displayed while working with Reformulations in Nuitka. The following is an example try block which is trying to assign iter() to the arguments if supported else throw an type error.

makeTryExceptSingleHandlerNode(
                tried=makeStatementsSequence(
                    statements=[
                        StatementAssignmentVariable(
                            variable=zip_iter_variable,
                            source=ExpressionBuiltinIter1(
                                value=ExpressionTempVariableRef(
                                    variable=zip_arg_variable, source_ref=source_ref
                                ),
                                source_ref=source_ref,
                            ),
                            source_ref=source_ref,
                        )
                        for i, zip_iter_variable, zip_arg_variable in zip(
                            range(len(call_args)), zip_iter_variables, zip_arg_variables
                        )
                    ],
                    allow_none=False,
                    source_ref=source_ref,
                ),
                exception_name="TypeError",
                handler_body=StatementRaiseException(
                    exception_type=ExpressionBuiltinExceptionRef(
                        exception_name="TypeError", source_ref=source_ref
                    ),
                    exception_value=makeConstantRefNode(
                        constant="zip argument #%d must support iteration" % (i + 1),
                        source_ref=source_ref,
                    ),
                    exception_trace=None,
                    exception_cause=None,
                    source_ref=source_ref,
                ),
                source_ref=source_ref,
            )

You can see there that I'm calling create a StatementRaiseException with a template i.e "zip argument #%d must support iteration" in our case, which is basically to handle cases like for example: zip(1, [1,2,3]).

Thanks for reading

View Blog Post

Weekly Checkin #5

bksahu
Published: 08/01/2019

1. What did you do this week?

I'm still going on with zip reformulation and at the same time also working on the keyfun parameter of the min and max builtin. To be completely honest this week has not be that productive because I am studying for an upcoming exam. But I'm hoping to get back on track in a next couple of days.

2. What is coming up next?

I will keep working on both them until they are ready to be merged.

3. Did you get stuck anywhere?

Yes I was stuck with zip reformulations for a while but with the help of my mentor everything is back on track. 

View Blog Post

Blog Post #4

bksahu
Published: 07/22/2019

Hi, welcome to my 4th blog post !

Last time we saw how reformulations of `min` and `max` works. This time we will drive in how reformulation of `zip` (only in Py27) works. If I were to implement `zip` using Python 2 it were to look something like this:

def _zip(*iterables):
     # zip('ABCD', 'xy') --> Ax By
     # import ipdb; ipdb.set_trace()
     sentinel = object()
     iterators = [iter(it) for it in iterables]
     zipped = []
     for _ in xrange(len(iterators)):
         result = []
         for it in iterators:
             elem = next(it, sentinel)
             if elem is not sentinel:
                 result.append(elem)
         if len(result) == len(iterators):    
             zipped.append(tuple(result))
     return zipped

But on reformulation, some things need to be changed. We also have to take define new temp variables inside the scope and release it when we are done. One more major optimizations that we have to do is to use one loop instead to two loops as seen above. So, finally our reformulation pseudo-code will look something like this:

def _zip(a, b, c, ... ):
   # First assign, to preserve order of execution,
   # the arguments might be complex expressions.
   tmp_arg1 = a
   tmp_arg2 = b
   tmp_arg3 = c
   ...

   tmp_iter_1 = iter(tmp_arg1)
   tmp_iter_2 = iter(tmp_arg2)
   tmp_iter_3 = iter(tmp_arg3)
   ...

   # could be more
   tmp_result = []
   try:
       while 1:
           tmp_result.append(
               (
                    next(tmp_iter_1),
                    next(tmp_iter_2),
                    next(tmp_iter_3),
                    ...
               )
            )
      except StopIteration:
          pass

   return tmp_result

In this way we can optimize the zip nodes in Nuitka.

Thank you for reading :) 

View Blog Post
DJDT

Versions

Time

Settings from gsoc.settings

Headers

Request

SQL queries from 1 connection

Static files (2312 found, 3 used)

Templates (28 rendered)

Cache calls from 1 backend

Signals

Log messages