Articles on bksahu's Bloghttps://blogs.python-gsoc.orgUpdates on different articles published on bksahu's BlogenThu, 22 Aug 2019 14:42:31 +0000GSoC Wrap-up - Blog Post #6https://blogs.python-gsoc.org/en/bksahus-blog/gsoc-wrap-up-blog-post-6/<p>Hello everyone!</p> <p>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:</p> <h2>Built-ins Optimizations</h2> <ul> <li>"any": PR #246 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/246">https://github.com/Nuitka/Nuitka/pull/246</a>&gt; * Issue reported and closed Issue #349 &lt;<a href="https://github.com/Nuitka/Nuitka/issues/349">https://github.com/Nuitka/Nuitka/issues/349</a>&gt;</li> <li>"all": PR #407 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/407">https://github.com/Nuitka/Nuitka/pull/407</a>&gt;</li> <li>"abs": PR #419 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/419">https://github.com/Nuitka/Nuitka/pull/419</a>&gt;</li> </ul> <p>The following are in progress: * "max" and "min": PR #442 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/442">https://github.com/Nuitka/Nuitka/pull/442</a>&gt; * "zip": PR #462 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/462">https://github.com/Nuitka/Nuitka/pull/462</a>&gt;</p> <h2>Test suite</h2> <ul> <li>Search mode "All": PR #378 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/378">https://github.com/Nuitka/Nuitka/pull/378</a>&gt;</li> <li>Search mode "Only": PR #333 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/333">https://github.com/Nuitka/Nuitka/pull/333</a>&gt;</li> <li>Reported and closed Issue #334: PR #336 &lt;<a href="https://github.com/Nuitka/Nuitka/pull/336">https://github.com/Nuitka/Nuitka/pull/336</a>&gt;</li> </ul> <h2>Documentation</h2> <ul> <li>Nuitka git work flow: PR #485 <a href="https://github.com/Nuitka/Nuitka/pull/485">https://github.com/Nuitka/Nuitka/pull/485</a></li> </ul> <p>And other minor doc fixes are added with their respective pull requests.</p> <p>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,</p> <p> </p> <p>Thanks for stopping by!</p> <p>bksahu</p>bablusahoo16@gmail.com (bksahu)Thu, 22 Aug 2019 14:42:31 +0000https://blogs.python-gsoc.org/en/bksahus-blog/gsoc-wrap-up-blog-post-6/Weekly Check-in #6https://blogs.python-gsoc.org/en/bksahus-blog/weekly-check-in-6-6/<h2><strong>1. What did you do this week?</strong></h2> <p>This week I added support for Python 3 <code>&lt;tt&gt;zip()&lt;/tt&gt;</code> built-in and added git workflow in the developer manual which can be found here: <a href="https://github.com/Nuitka/Nuitka/pull/485">https://github.com/Nuitka/Nuitka/pull/485</a>.  And also worked on the remnants of Python 2 support for the same.</p> <h2><strong>2. What is coming up next?</strong></h2> <p>Now that support for keyword only arguments has been added in Nuitka, I will finish the remaining of optimizations support  for <code>min()</code> and <code>max()</code> built-ins.</p> <h2><strong>3. Did you get stuck anywhere?</strong></h2> <p>Yes, I was stuck on reformulation of <code>zip()</code> for Python2.</p>bablusahoo16@gmail.com (bksahu)Wed, 14 Aug 2019 14:07:41 +0000https://blogs.python-gsoc.org/en/bksahus-blog/weekly-check-in-6-6/Blog Post #5https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-5/<p>Hi, welcome to my blog post #5!</p> <p>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 <code>iter()</code> to the arguments if supported else throw an type error.</p> <div style="background: #eeeeee; border: 1px solid #cccccc; padding: 5px 10px;">makeTryExceptSingleHandlerNode(<br>                 tried=makeStatementsSequence(<br>                     statements=[<br>                         StatementAssignmentVariable(<br>                             variable=zip_iter_variable,<br>                             source=ExpressionBuiltinIter1(<br>                                 value=ExpressionTempVariableRef(<br>                                     variable=zip_arg_variable, source_ref=source_ref<br>                                 ),<br>                                 source_ref=source_ref,<br>                             ),<br>                             source_ref=source_ref,<br>                         )<br>                         for i, zip_iter_variable, zip_arg_variable in zip(<br>                             range(len(call_args)), zip_iter_variables, zip_arg_variables<br>                         )<br>                     ],<br>                     allow_none=False,<br>                     source_ref=source_ref,<br>                 ),<br>                 exception_name="TypeError",<br>                 handler_body=StatementRaiseException(<br>                     exception_type=ExpressionBuiltinExceptionRef(<br>                         exception_name="TypeError", source_ref=source_ref<br>                     ),<br>                     exception_value=makeConstantRefNode(<br>                         constant="zip argument #%d must support iteration" % (i + 1),<br>                         source_ref=source_ref,<br>                     ),<br>                     exception_trace=None,<br>                     exception_cause=None,<br>                     source_ref=source_ref,<br>                 ),<br>                 source_ref=source_ref,<br>             )</div> <p>You can see there that I'm calling create a <code>StatementRaiseException</code> with a template i.e <code>"zip argument #%d must support iteration" </code>in our case, which is basically to handle cases like for example: <code>zip(1, [1,2,3]).</code></p> <p>Thanks for reading</p>bablusahoo16@gmail.com (bksahu)Sat, 10 Aug 2019 10:16:07 +0000https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-5/Weekly Checkin #5https://blogs.python-gsoc.org/en/bksahus-blog/weekly-checkin-5/<h2><strong>1. What did you do this week?</strong></h2> <p>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.</p> <h2><strong>2. What is coming up next?</strong></h2> <p>I will keep working on both them until they are ready to be merged.</p> <h2><strong>3. Did you get stuck anywhere?</strong></h2> <p>Yes I was stuck with zip reformulations for a while but with the help of my mentor everything is back on track. </p>bablusahoo16@gmail.com (bksahu)Thu, 01 Aug 2019 10:09:22 +0000https://blogs.python-gsoc.org/en/bksahus-blog/weekly-checkin-5/Blog Post #4https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-4/<p>Hi, welcome to my 4th blog post !</p> <p>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:</p> <div style="background: #eeeeee; border: 1px solid #cccccc; padding: 5px 10px;"> <pre>def _zip(*iterables): # zip('ABCD', 'xy') --&gt; 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</pre> </div> <p>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:</p> <div style="background: #eeeeee; border: 1px solid #cccccc; padding: 5px 10px;"> <pre>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 </pre> </div> <p>In this way we can optimize the zip nodes in Nuitka.</p> <p>Thank you for reading :) </p>bablusahoo16@gmail.com (bksahu)Mon, 22 Jul 2019 14:50:27 +0000https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-4/Optimizing "map" and "zip" - Weekly check in #4https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-map-and-zip-weekly-check-in-4/<h2><strong>1. What did you do this week?</strong></h2> <p>This week I started up with optimizing "map" built-in but later realised that I first need to optimize "zip" as there is no support on Nuitka for it as "map" is dependent on it. Initially I implemented the C backend for Python2 "zip" function but after discussing with my mentor we decided to keep only C backend for Python3 "zip" and depend on re-formulation for Python2 "zip" built-in.</p> <h2><strong>2. What is coming up next?</strong></h2> <p>Next up I will optimize zip for Python 3 and then get back to optimize "map" built-in.</p> <h2><strong>3. Did you get stuck anywhere?</strong></h2> <p>Well, I wouldn't say I was stuck anywhere but I had a lot of discussions on developing an optimization approach for the built-in mentioned above. </p> <p> </p> <p>Thanks!</p> <p>Batakrishna</p>bablusahoo16@gmail.com (bksahu)Mon, 15 Jul 2019 14:08:00 +0000https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-map-and-zip-weekly-check-in-4/Blog post #3https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-3/<p>Hello everyone! Welcome to my 3rd blog post.</p> <p>So, I am very happy to inform that I have passed my first evaluations with flying colors and now working on phase 2.</p> <p>I learned a new way of optimization for Nuitka that doesn't need any CPython code replication. The idea is very simple i.e to build on top of existing nodes on Nuitka. Consider the following example, below is the optimization for <code>min()</code> built-in</p> <div style="background: #eeeeee; border: 1px solid #cccccc; padding: 5px 10px;"><code>makeStatementConditional(<br>     condition=ExpressionComparisonGt(<br>         left=ExpressionTempVariableRef(<br>             variable=min_result_variable, source_ref=source_ref<br>         ),<br>         right=ExpressionTempVariableRef(<br>             variable=min_arg_variable, source_ref=source_ref<br>         ),<br>         source_ref=source_ref,<br>     ),<br>     yes_branch=StatementAssignmentVariable(<br>         variable=min_result_variable,<br>         source=ExpressionTempVariableRef(<br>             variable=min_arg_variable, source_ref=source_ref<br>         ),<br>         source_ref=source_ref,<br>     ),<br>     no_branch=None,<br>     source_ref=source_ref,<br> )</code></div> <p>The above is equivalent to (in Python):</p> <div style="background: #eeeeee; border: 1px solid #cccccc; padding: 5px 10px;"><code>min_result_variable if min_result_variable > min_arg_variable else None</code></div> <p>In this way we can optimize reusing existing nodes. Now the only difficulty is in the case when there is more than one argument. Such type of problems are handled in Nuitka using something called reformulation. So, by using reformulation our problem will decomposed in to a simpler problem. For example:</p> <div style="background: #eeeeee; border: 1px solid #cccccc; padding: 5px 10px;"><code>min(1, 2, 3) ---(reformulation)---> min(min(1, 2), 3)</code></div> <p>Hence, in this way we can optimize in an efficient way.</p> <p>Thank you for stopping by! <br> <a href="https://bksahu.github.io/">Batakrishna</a></p>bablusahoo16@gmail.com (bksahu)Sun, 07 Jul 2019 13:37:48 +0000https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-3/Optimizing "max" and "min" - Weekly check in #3https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-max-and-min-weekly-check-in-3/<h2><strong>1. What did you do this week?</strong></h2> <p>Finally I was successfully able to optimize the max and min built-in with my new understanding of Nuitka internals. Apart from that did some refactoring for my algorithm for BUILTIN_ALL optimization. It is almost ready to be merged to the main code base.</p> <h2><strong>2. What is coming up next?</strong></h2> <p>This is I will spend time on fixing bugs if any in the "abs", "min" and "max" optimization. Also, I will start with a new built-in optimization. </p> <h2><strong>3. Did you get stuck anywhere?</strong></h2> <p>Nope, I didn't get stuck anywhere. </p>bablusahoo16@gmail.com (bksahu)Tue, 02 Jul 2019 14:56:13 +0000https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-max-and-min-weekly-check-in-3/Blog post #2https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-2/<p>Hello. Welcome to my second blog post.</p> <p>The first evaluations have started. When I look back into last month, I realize that I have learnt a lot and grown into a better developer. So, I am glad that I'm a part of this program and organisation.</p> <p>So, as discussed in the last blog post I am proud to inform that I have successfully created the IterationHandles module that take care of the iteration needs. And the best past about this module is that it is not limited to any() built-in optimization but can be reused in many other built-in optimizations as well. This module made my job very easy while optimizing "all" built-in.</p> <p>abs() built-in optimization: While going through the original CPython implementations of this function I noticed that it is has a nb_absolute member which stores the absolute value of a variable, which means I had to manually add slots for every shapes (Eg. int, float). Now, this optimization needs a final touch up after review.</p> <p>I am hoping to see those optimizations in next release.</p> <p>Thank you for reading!</p> <p>Batakrishna </p>bablusahoo16@gmail.com (bksahu)Tue, 25 Jun 2019 06:25:37 +0000https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-2/Optimizing "abs" - Weekly Check-in #2https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-abs-weekly-check-in-2/<p>Welcome to my third weekly check-in!</p> <h2><strong>1. What did you do this week?</strong></h2> <p>This week I spent time on optimizing the "abs" built-in and understanding the "operators" module.</p> <h2><strong>2. What is coming up next?</strong></h2> <p>Next up, I will be working on adding support for "max" and "min" built-in after discussing potential optimizations with my mentors.</p> <h2><strong>3. Did you get stuck anywhere?</strong></h2> <p>Yes, I was stuck while implementing the "BUILTIN_ABS" CPython implementation for Nuitka. I have fixed it by doings the version checks.</p> <p> </p> <p>Thank you for reading!</p>bablusahoo16@gmail.com (bksahu)Wed, 19 Jun 2019 11:04:48 +0000https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-abs-weekly-check-in-2/Blog post #1https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-1/<p>Hello everyone! Welcome to my first blog post.</p> <p>There are a total of 69 built-ins in Python 3 and ​76 built-in in Python 2 out of which 27 built-ins are yet to be optimized in Nuitka​. My aim is to optimize those missing built-ins in Nuitka. This will make Nuitka a lot faster while working with CPython built-ins.</p> <p>The first built-in that I'm going to start with is "any" built-in. I have already implemented a generic algorithm for the optimization for cases like any([0] * 10000). But there is problem with this algorithm i.e it doesn't have support for Dict and Sets datatypes because they are non-indexable. A solution to problem is embracing the fact that python internally uses iter() and next() while working with loops. Using these we can easily iterate over the elements in the dictionary and set datatypes. The idea is to have a limit for the number of elements we will iterate through and try to predict the True value, for example any([0]) or any([0]*100) is always going to be False. In the same way any([0]*1000000) is also False but it's too expensive to iterate of all the million elements and find their truth value that's why we need to a limit. This solutions will also be helpful with future optimization that need to iterate through every element.</p> <p> </p> <p>Thank you for reading :)</p>bablusahoo16@gmail.com (bksahu)Sun, 09 Jun 2019 05:49:34 +0000https://blogs.python-gsoc.org/en/bksahus-blog/blog-post-1/Optimizing "all" - Weekly Check-in #1https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-all-weekly-check-in-1/<p>Welcome to my second weekly check-in!</p> <h2><strong>1. What did you do this week?</strong></h2> <ul> <li>optimized the "all" built-in</li> <li>refractored the "IterationHandles" class</li> </ul> <h2><strong>2. What is coming up next?</strong></h2> <p>Next up, I will be working on adding support for "abs" built-in after discussing potential optimizations with my mentors.</p> <h2><strong>3. Did you get stuck anywhere?</strong></h2> <p>No nowhere because all built-in is almost similar to any built-in.</p> <p> </p> <p>Thank you for reading!</p> <p><a href="http://bksahu.github.io">Batakrishna Sahu</a></p>bablusahoo16@gmail.com (bksahu)Sun, 02 Jun 2019 07:25:15 +0000https://blogs.python-gsoc.org/en/bksahus-blog/optimizing-all-weekly-check-in-1/Welcome blog posthttps://blogs.python-gsoc.org/en/bksahus-blog/welcome-blog-post/<p>Hello, world. Welcome to my first of many upcoming blog posts. I will be working on optimizing Python 2 and Python 3 built-ins for Nuitka this summer.  </p> <p>Thank you for stopping by!</p> <p><a href="http://bksahu.github.io">Batakrishna Sahu</a></p>bablusahoo16@gmail.com (bksahu)Tue, 28 May 2019 05:46:11 +0000https://blogs.python-gsoc.org/en/bksahus-blog/welcome-blog-post/