GSoC 2016 Application Aravind Reddy: Classical Mechanics - sympy/sympy GitHub Wiki

ABOUT ME

UserName and Contact Information:

Name : Aravind Reddy Ayuluri

University : International Institute of Information Technology

Email : [email protected]

IRC handle : leokanna at freenode.net

Github user name : aravindkanna

Personal Background:

I am Aravind Reddy Ayuluri, a third year undergraduate student at IIIT-Hyderabad. I am pursuing my degree in Computer Science Engineering.

Currently I am working on Ubuntu 15.10 but by the time of start of program I will shift to Ubuntu 16.04 LTS. I use Sublime Text-2 as my primary editor to work as it is flexible to use on any OS with same features and yeah it has some nice features like Multiple Selections. It takes the massive plugin library built up around TextMate and extends it even further. Though it is not a free software, we can use its demo forever. I also use vim when I don't want to use a mouse as it can't be beaten by any editor I guess.

I am proficient in C++ and Python. I like Python because it takes less time to develop though slower than C++. Python has clean and straightforward syntax.It has a huge standard library. Compared to C++ there is no need to compile and no memory management. I made a Mini-Sql-Engine using Python which queries database and displays the output in standard format used by SQL. I made two games as well in Python. All these are uploaded there on my github repositiories.

I also have experience in using git. I have gone through the complete tutorial of git which clearly specifies the advantages which git provides compared to normal Version Control Systems. What I mostly like with git is the way it stores data.

CONTRIBUTIONS TO SYMPY

I started my contribution to sympy from February-2016. I have listed below all the merged and unmerged contributions in the order latest first.

Pull Requests

[unmerged] : #10843. This is a fix to issue 10841. The bug is in the function kanes_equations() which I am going to work this whole summer. This shows that I have already started understanding the code.

[merged] : #10827. After a long discussion with many developers I came to a decision of returning True for is_nilpotent() when applied on empty matrix.

[unmerged] : #10815. Previously there is no rebuild of a matrix from an Empty Matrix. This fix can do it successfully. Also it is a fix to the issue #10770.

[unmerged] : #10812. Previously berkowitz() function used to return an IndexError for Empty Matrix. Now it will return a tuple (1,).

[unmerged] : #10786. This fix modifies functions like berkowitz_eigenvals(), berkowitz_eigenvects() and berkowitz_minors(). Previously they used to raise an error when applied for an Empty Matrix. Now they will return an empty dictionary, an empty list and an empty tuple respectively.

[merged] : #10783. This fix modifies the function condition_number(). It returns a rational number formed with numerator and denominator as maximum and minimum values respectively of the tuple which is returned when function singular_values() is called. For an empty matrix singular_values() returns an empty tuple. So this raises the error. But by standard norms this should return 1 for an empty matrix. The issue #10782 is solved as part of this fix.

[closed] : #10772. This is a fix for issue #10719. But there is another pull request for the same issue which unfortunately I didn’t find. So closed the request.

[closed] : #10767. I thought there should be a property for matrix to check whether it is empty or not. So I added a property is_empty() for Matrices module. But after a clear discussion with the experienced I came to learn that it would be redundant to have such property when there is If container: way to check whether a container is empty or not. So this request is closed.

##Issues Reported [open] : #10785. This is an issue which I found as part of my contribution of cleaning the sympy codebase.

[closed] : #10782. This is the issue which I found and also resolved.

[open] : #10770. Matrices can be transformed to an empty matrix but they can't be rebuild again back to a matrix of real shape(which I mean to a non empty matrix) with the existing methods.

[closed] : #10768. singular_values() function is returning IndexError when applied for empty matrices. Later this issue was solved when the issue 10719 was fixed.

#About Project

I liked Sympy because of its idea of providing better libraries so as to make it easy to compute many mathematical and physical expressions. The main thing I like here is that everything is represented in symbols. Being a part of developing such a software will obviously help me a lot.

Problem Statement

For the project, I would like to specify how it is right now? What are the disadvantages? What the project does? What are the advantages this project provides to sympy?

Equations of Motion are the roots of Classical Physics as they describe a complete physical system using dynamic variables. Right now sympy is using two standard classes to generate Equations of Motion. They are class KanesMethod which uses Kane's method and class LagrangesMethod which uses Euler-Lagrange methods of generating Equations of Motion. It is calculating Equations of Motion for some standard problems of which I have taken N-Link Pendulum Problem for profiling the currently existing codebase.

As mentioned in the ideas page the time taken to generate EOM increases drastically with increase in degrees of freedom. A clear profiling can explain this in detail which I have done below. This project is intended to add a new method(a new class in programming perspective) of finding EOM, Newton-Euler Method , with a class name NewtonEulerMethod. Now it is better if we generalize the EOM generation classes by creating an abstract base class as it will help in future, in adding more methods to compute EOM easily. Also this project intends to speed up the existing methods(KanesMethod and LagrangesMethod).

The final output from this project would be like this. There will be a generalized class EOMMethod and 3 subclasses KanesMethod, LagrangesMethod and NewtonEulerMethod which inherit the main class EOMMethod. The advantage lies there that we can now add many methods of our choice just by inheriting the main class. After completing the implementation of new class NewtonEulerMethod, I will concentrate on implementing some sample models which can be used as testing and examples.

I had generated EOM for various degrees of freedom to profile the kanes_equations() function. I have used snakeviz for this purpose. With degrees of freedom(n) being 10, 20, 30 and 40 I have observed the following thing. The major time for the computation is being taken by _form_frstar() and _form_fr(). Now these two functions are of our interest to decrease the run time of generating EOM. As n increases the percent of run time that _form_frstar() takes, is increasing. So the plan is to first find the slow functions that are taking more time. Now the the time taken is more may be because, the called functions are out of sympy.physics package. Now observing all these functions, I will make particular decisions to decrease the run time complexity like probably a function is called more time even though it is not necessary.

Classes

As part of the project these are the classes I am planning on implementing.

  • EOMMethod
  • KanesMethod
  • LagrangesMethod
  • NewtonEulerMethod

We know that KanesMethod and LagrangesMethod exist already. I am thinking to implement them as new classes so that no problem arises. These two including NewtonEulerMethod will be the subclasses of the EOMMethod class. This is the basic structure of classes.

As of now, from the definitions of the two implemented methods the arguments should include:

  • Matrices of the generalized coordinates and speeds (Matrix).
  • Forcelist (Iterable)
  • Mass Matrix (Matrix)
  • Forcing (Matrix)
  • Mass Matrix Full (Matrix)
  • Forcing Full (Matrix) with the previous meanings as defined.

The properties which are common in both classes are:

  • mass_matrix()
  • mass_matrix_full()
  • forcing()
  • forcing_full()
  • q()
  • u()
  • force_list()

##Motivation
The main motivation behind this is it gives me a large Object Oriented Programming experience. Here not only my technical but also my other qualifications like my experience in physics are also being tested.

Tentative Shedule

I have divided the work for each week with a total working time of 40 hrs. I have mentioned clearly what work need to be done when and how much time it can take.

###Community Bonding Period:
April 22nd - May 22nd
My semester will end on May 6th. From May 9th, Monday, I will be starting the project. I try to get a clear knowledge of KanesMethod and LagrangesMethod classes. 10 - 15 hrs will be spent on understanding each class. This includes analyzing the arguments they take, analyzing the output by changing the inputs and to have a look at tests. Also I will try to understand the recursive algorithms proposed by Roy Featherstone. This initial period is totally dedicated to this work as this will boost my work and help me speed up.

[Week-1]

May 23rd - May 29th
By this time I will be ready with the necessary initial knowledge. As the implementation of each class is understood by then, I will be focusing on finding the common things which these two classes have. Then I will start building the basic implementation of the class EOMMethod. The basic implementation includes creating the class with useful attributes, its constructor and various other functions.

[24 hrs] Finding the common things and analyse on the attributes which the class EOMMethod should have.
[16 hrs] With the attributes got by now, basic implementation of class.
[1 hr] Write a clear documentation of the week's work.

###[Week-2]
May 30th - June 5th
By this time a basic infrastructure of the class will be created. Now I will work to analyze on time taking functions. This includes finding the slow functions which can be rewritten or modified, discussing with the mentor about the optimization of the respective functions, finding various other methods to reduce time. Here I can't specify exact time for each task but aim to complete in particular time span. Then another task of the week is to create two subclasses KanesMethod and LagrangesMethod with EOMMethod as superclass. This includes the basic implementation of both the subclasses(I will try to optimize the methods of both classes in parallel).

[8 hrs] Profiling the current code and find the time taking functions.
[16 hrs] Complete discussion with the mentor about the implementation details and doubts(This implementation details are not of the classes but of the other methods especially time taking functions which the methods of these classes call).
[8 hrs] Spend time on finding the fast methods and algorithms to accomplish generation of EOM faster than the previous work.
[8 hrs] Basic implementation of both the subclasses.
[1 hr] Write a clear documentation of the week's work.

###[Week-3]
June 6th - June 12th
This week will be mainly dedicated to complete the base class structure. As I mentioned above, the basic implementation will be implemented till this instant. Now the main work starts. The complete implementation of both the classes will be completed. I will also check for any bugs by running them in parallel.

[32 hrs] Complete implementation of the two subclasses.
[8 hrs] This is the complete time which can be dedicated for finding and fixing the bugs.
[1 hr] Write a clear documentation of the week's work.

###[Week-4]
June 13th - June 19th
I will continue the completion of the implementation of base class and the two subclasses to this week also as I think it should need some more time, so that the output will be a neat, understandable and correct code. Though I usually write comments while writing the code, I may be wrong w.r.t the norms sympy follow. As the mid evaluations time will be getting closer, I will start writing comments wherever required.

[32 hrs] Complete implementation of the two subclasses.
[8 hrs] Time dedicated for fixing bugs and commenting.
[1 hr] Write a clear documentation of the week's work.

###[Week-5]
June 20th - June 26th
This will be the week to submit my patch for mid evaluations. So I will complete the implementations and create a pull request by the 2nd day of the week. Then based on the guidance of mentor I will make changes to the code. Along with the code I will also submit my documentations till then so that the mentor assigned will get a clear overview of the work I have done till then easily.
[8 hrs] To check and complete any incomplete things.
[32 hrs] To correct the code, so that it passes all the checks and is able to merge.
[1 hr] Write a clear documentation of the week's work.

###[Week-6]
June 27th - July 3rd
By this time I will be having three classes which are functioning correctly. Now I again check for speed issues. I will also have a look at Newton-Euler method to find the EOM and compare it with Kane's and Lagranges' methods. So I will have a better understanding of how the method can be implemented. This includes what are the maximum possible arguments it may take.

[8 hrs] Profiling the code.
[24 hrs] To understand the Newton-Euler method.
[8 hrs] A small study to see how it can be implemented as a class.
[1 hr] Write a clear documentation of the week's work.

###[Week-7]
July 4th - July 10th
The major part of this week is also given to study how to implement the class. To decide what all functions are needed. If necessary I should also have to talk with the developers who implemented both the KanesMethod and LagrangesMethod, to get to know what all safety measures they have taken while completing the implementation.

[40 hrs] The whole week is dedicated to make a clear understanding and a basic subclass(NewtonEulerMethod) will be implemented from already implemented EOMMethod class.
[1 hr] Write a clear documentation of the week's work.

###[Week-8]
July 11th - July 17th
Now the work will be to complete the implementation of the class. I will also check for ways to reduce the time complexity for computing Equations of Motion in parallel. This includes all the discussions with mentor and others also.

[40 hrs] Complete time is dedicated for building the NewtonEulerMethod class.
[1 hr] Write a clear documentation of the week's work.

###[Week-9]
July 18th - July 24th
This week is half dedicated to complete the class implementation. Then I start implementing test files for the method. After the class implementation there will be one patch submission here.

[24 hrs] Complete the class implementation
[16 hrs] Understand the type of tests and start implementing them.
[1 hr] Write a clear documentation of the week's work.

###[Week-10]
July 25th - July 31st
This week, the major work will be to complete the tests. Then I will head towards implementing at least one model using NewtonEulerMethod. After tests completion, one more patch will be submitted.

[32 hrs] Completion of tests.
[8 hrs] Implement models.
[1 hr] Write a clear documentation of the week's work.

###[Week-11]
August 1st - August 7th
The last two weeks will be dedicated to complete any pending works. This include any undone works, bugs found by my mentor or others or by me and to improvise the code. Now with this work in parallel I will concentrate on the speed issues. Regularly keep an eye on the complexity issue. The project also deals with simplification of the EoM.

[24 hrs] pending works
[16 hrs] Speeding up and simplification.
[1 hr] Write a clear documentation of the week's work.

###[Week-12]
August 8th - August 14th

[20 hrs] pending works
[20 hrs] Speeding up and simplification
[1 hr] Write a clear documentation of the week's work.

###[Week-13]
August 15th - August 23rd

This whole week is dedicated to make a clear documentation. 20 hours will be spent to make the documentation and 5 hours will be to recheck any misspells. Once shown to mentor, I will request the mentor to have a look at it and ask for any changes. Changes will be made accordingly. And finally the deliverable and documentation will be provided or submitted on 22nd August one day prior to the deadline. Also all the possible changes to improve the code will be done in this week.

Final Deliverables

This project will finally complete the EOMMethod class. Then there will be three subclasses inheriting from this main class. They are NewtonEulerMethod, KanesMethod and LagrangesMethod. These three can then generate the Equations of Motion for multibody systems with efficient time complexity. Also some models will be generated using the NewtonEulerMethod subclass.

#Post GSoC Contribution

I will continue my contribution to Sympy even after GSoC. My desire is to become one of the mentors in the next GSoC. Though I may not do a great job, I can actively participate in testing part of the Software, that is I try my max to solve the bugs which can be solved with my level of knowledge.

#References and Related Issues

https://en.wikipedia.org/wiki/Newton%E2%80%93Euler_equations
https://github.com/sympy/sympy/pull/7790