GSoC 2016 Rajith Vidanaarachchi: Ruby Wrappers for SymEngine - rajithv/symengine.rb GitHub Wiki


Ruby Wrappers for SymEngine

1. Contact information.
2. Why do you like Ruby, and why do you want to work on SciRuby?

I had my first experience with Ruby couple of years ago, and was amazed with the ease it provides to the programmer with the flexible syntax and the famed pragmatism. Ruby simplifies life for us, who would have otherwise ended with writing complex code for simple tasks. Writing complex code is also fun in its own flavour (such as the code required for this proposed GSoC project), but the simplicity enables the spread of the language, enabling multitudes of people to use the language. As a person who comes with a mathematics-oriented background, I understand the importance of the work of SciRuby, enabling science libraries in Ruby itself. Giving something to the Ruby community through the contributions to the SymEngine Ruby Wrapper is my aim in presenting this proposal.

3. What do you like about science and why? What area do you like best?

I am a student of computer science. I like computer sciences because, as someone put it, "it's the art of speaking with machines". I enjoy the challenges it poses, and the satisfaction of solving a problem.

4. Describe your experience with the following: Ruby, C, C++, other languages.
  • C/C++ : (13+ years) I first started programming with C, and then moved on to C++. I have mainly done competitive algorithmic problem solving tasks with C++ since 2005. These competitions include IEEEXtremes and IOIs.

  • Ruby : (2+ years) I have developed a start-up product with Ruby on Rails, (www.audinary.lk).

5. Describe your educational background (school, degree plan, major, past degrees, research area, publications, etc.).

I am a student of Computer Science & Engineering at University of Moratuwa, Sri Lanka. Currently I am a final year undergraduate, awaiting results of final exams, and will be graduated in August, 2016.

  • Research : My final year project was on Virtual Reality.

Publications :

  • Quantitative and Qualitative Evaluation of Performance and Robustness of Image Stitching Algorithms. Dissanayake, V. ; Herath, S. ; Rasnayaka, S. ; Seneviratne, S. ; Vidanaarachchi,R. ; Gamage, C., in Digital Image Computing : Techniques and Applications (DICTA) 2015 International Conference, Nov. 2015

  • Real-time Gesture Prediction Using Mobile Sensor Data for VR Applications. Dissanayake, V. ; Herath, S. ; Rasnayaka, S. ; Seneviratne, S. ; Vidanaarachchi,R. ; Perera, A.S ; Gamage, C., in International Conference on Machine Learning and Computing (ICMLC) 2016, Feb. 2016

6. Have you offered any pull requests for SciRuby or contributed in other ways? Please provide links, if possible. Past contributions are required, and must be in the form of code. Documentation contributions are also beneficial.

I have 2 merged PRs and 1 WIP PR at symengine/symengine.rb

I have 1 merged PR at symengine/symengine

7. What other commitments do you have this summer aside from GSoC? What obstacles do you foresee this summer as far as contributing the full forty hours per week during thehttps://github.com/symengine/symengine.rb/pull/17 GSoC period?

I have no other formal commitments in the summer. As I am awaiting graduation in August, 2016 I have no school work, nor professional work during this time.

8. Are you planning any fun vacations this summer?

No.

9. How many classes are you taking this summer?

None.

10. Do you have any other employment this summer?

No.

11. Please talk a bit about any past GSoC projects in which you have participated. If you've done GSoC before, how could we reach your mentor(s)?

I have not taken GSoC projects in the past.

12. Please propose a project you would like to work on. Successful proposals will require advanced planning, communication with the project administrators and mentors, and likely a great deal of research on specific methods for achieving your project goals (e.g., what algorithms will you use? What frameworks?). A good place to start is the Ideas Page. You should also consider lurking on our IRC channel (#sciruby on FreeNode). Participation in listserv discussions is strongly recommended.
Adding Ruby Wrappers for SymEngine

This is the abstract as shown in the Ideas Page

A project started by the SymPy organisation, SymEngine is a standalone fast C++ symbolic manipulation library. It solves mathematical problems the same way a human does, but way more quickly and precisely. The motivation for SymEngine is to develop the Computer Algebra System once in C++ and then use it from other languages rather than doing the same thing all over again for each language that it is required in. The project for Ruby bindings has already been setup at symengine.rb. Few things that the project involves are:

  • Extending the C interface of SymEngine library.
  • Wrapping up the C interface for Ruby using Ruby C API, including error handling.
  • Designing the Ruby interface.
  • Integrating IRuby with symengine gem for better printing and writing IRuby notebooks.
  • Integrating the gem with existing gems like gmp, mpfr and mpc.
  • Making the installation of symengine gem easier.

More details on the proposal is given below, after this questionnaire.

13. Please provide a specific timeline for your project from application period until pencils-down. What benchmarks will you set for yourself? The greater the detail on this question and the previous, the better.

A detailed outline of the timeline is given after this questionnaire.

14. What is one long-term vision for something you'd like scientific software to be able to do. Think big picture, not necessarily realistic in the short term.

A long term vision for scientific software would be, for scientists to express their ideas with ease at a higher level of abstraction without worrying too much about the low level specifics.

15. What are your hobbies, aside from coding? Tell us a little about yourself that isn't reflected in the rest of your application. What do you want to do with your life (if you have any idea)?

Aside from coding, these days I am learning German. I believe life is to be lived to the full, with self-satisfaction and service to the society.

16. Bonus question: One aim of the Ruby Science Foundation (SciRuby) is to increase diversity in open source science software development. How do we get more women interested in open source software development and science? How do we get more people from underrepresented groups involved?

I believe the first step for more female and under-represented groups' involvement is to create an environment which welcomes them, to let them get involved in challenging tasks, for them to reach for help when they are stuck, and finally to appreciate their involvement in a more prominent way.

Tools

The main tool which will be used in the Ruby C API

Timeline (tentative)

Pre GSoC

I have been working on some PRs already. The first step ahead is to complete the Ruby Wrappers for the Trigonometric and Hyperbolic Functions and to write the necessary tests.

Next, the NTheory CWrappers can be wrapped into Ruby. This too will be done before the GSoC period starts.

I have got to know some of the contributors of SymEngine, from the PRs and on gitter. I hope to know more above the SymEngine community and to get to know other contributors during the pre-GSoC period.

In the following weeks, the idea is to write the CWrappers in the SymEngine/symengine project, (including writing the tests), and then writing the Ruby Wrappers with the Ruby C API in the SymEngine/symengine.rb project (again, including the tests). So for each topic, the actual work will be in four steps. This I plan to spread out through the week, Monday to Thursday, and to keep Friday (and if needed the weekend) for wrapping up each PR, and conflict resolving.

To summarize the steps again during a working week,

  • Writing the CWrappers
  • Writing the tests for the CWrappers
  • Writing the Ruby Wrappers
  • Writing the tests for the Ruby Wrappers
  • Wrap up the Pull Request
  • Write weekly blog post

Week 1 (23rd May - 27th May)

  • Complex Numbers & Floating Points

Complex Numbers in the SymEngine can be of three different types.

  • Complex Double
  • Complex Int
  • Complex mpc

Apart from wrapping these three different types into Ruby, this part will also include converting between the SymEngine Complex types and the Ruby Complex types.

Like wise, for floating point representation there are two types:

  • Real Double
  • Real mpfr

These classes will be wrapped during this week of the project, as well as converting between these types and Ruby's Float and BigDecimal data types.

Week 2 (30th May - 3rd June)

  • Complex Numbers & Floating Points (Continued)

This week will be a continuation from last week.

Week 3 (6th June - 10th June)

  • Derivatives, Substitutions, Abs, Series, Polynomials

Under derivatives, the main task will be to wrap the different overloaded diff functions given in derivative.cpp. The necessary types will also be implemented together with this, together with the class structure.

For Substitutions and Abs, the types together with the class structure will be implemented.

For Series, series method and SeriesCoeffInterface class will be wrapped.

For Polynomials, The UnivariatePolynomial Type together with the class structure will be implemented. Apart from this, functions for adding, subtracting, multiplying and negating univariate polynomials will be wrapped.

Week 4 (13th June - 17th June)

  • Matrices

Matrices will be a major part of the project, spanning for a three week time period. I expect this part to be challenging and, thus am already reading about possible incorporation of nMatrix into the implementation of SymEngine matrices in Ruby.

Implementing the types for Matrices, Dense Matrices and Sparse Matrices together with the relevant class structure will be a part of this stage.

Functions to be wrapped at this stage include:

  • Matrix Constructor
  • Getters and Setters for elements
  • Rank
  • Determinant
  • Inversion
  • Matrix Addition
  • Matrix Multiplication
  • Adding a Scalar
  • Multiplying by a Scalar
  • Transpose
  • Submatrix
  • LU-Factorization
  • LDL-Factorization
  • Jacobian
  • Row/Column Operations
  • Gaussian Elimination
  • Matrix Decomposition
  • NumPy functions

Week 5 (20th June - 24th June)

  • Matrices (continued)
  • Mid-term evaluation due next week.

Week 6 (27th June - 1st July)

  • Matrices (continued)

Week 7 (4th July - 8th July)

  • Parser
  • LaTex Printer

The parser is used to parse SymEngine expressions in string format into Basic objects. This is already written in the SymEngine, and needs to be wrapped into C, and then into Ruby.

The LaTex Printer will be a new component, which will output LaTex strings for the expressions in SymEngine formats. The user interface for this functionality would be a function which accepts a Basic object and returns a string, which is LaTex compliant.

Week 8 (11th July - 15th July)

  • Lambdify

This module would provide convenient functions to transform SymEngine expressions to lambda functions which can be used to calculate numerical values very fast. In Ruby lambda functions are objects. So, after completing this section, it should be able to call Lambdify with a SymEngine expression which returns a Lambda function for that expression. The said lambda function should take as parameters, the values for variables and return the numerical value.

Week 9 (18th July - 22nd July)

  • Exception Handling

Though SymEngine throws various exceptions, in Ruby, the engine stalls at any exception/error sans feedback. The task under this section is to capture the thrown errors from SymEngine, and to display them in Ruby. Although it is too early to predict the exact approach for Exception Handling, it will definitely contain creating the Exception Class structure within Ruby, identifying the exception thrown during the C call, and finally throwing the relevant exception at the Ruby level.

Week 10 (25th July - 29th July)

  • Exception Handling (Continued)

Week 11 (1st August - 5th August)

  • Interfacing with Ruby gmp, mpfr, mpc gems

GMP is a library for arbitrary precision arithmatics. The ruby gem gmp provides ruby bindings to the GMP library. During this week, interfaces will be created in SymEngine.rb for converting to and from GMP arbitrary precision signed integers, rational numbers and floating point numbers.

MPFR is a library for multiple precision floating point computations with correct rounding. The ruby gem mpfr provides bindings to this C library. As with the gmp, interfaces will be created for converting between SymEngine floating point numbers and mpfr floating point numbers during the course of this week.

MPC is a C library for multiple precision complex number calculations. The ruby gem mpc provides the bindings to this library. Similar to above, interfaces will be created for converting between SymEngine complex number types and mpc complex numbers.

Week 12 (8th August - 12th August)

  • Buffer period for any lagging work

Week 13 (15th August - 19th August)

  • For writing examples on IRuby Notebooks.

Working examples are always helpful for the users. Hence, at the end of the project IRuby notebooks will be created with fully functioning examples for each section described above.

Blog

The weekly progress will be updated in a blog. (This is yet to be setup)

Post GSoC

I hope to continue contributing to the SymEngine and the SymEngine Ruby Wrapper in fixing bugs and improving the gem.