GSoC 2021 Project Report

GSoC 2021 Project Report

This blog is the final permalink for the work I've done for PyBaMM during Google Summer of Code 2021.

Project Summary

In PyBaMM, models are represented by expression trees. This allows the model to be defined independently of the user's choice of parameters, spatial discretization, numerical methods and so on, which are plugged in during model processing. The goal of this project was to use LaTeX to render the expression tree into a human-readable format using SymPy or other file formats (PNG, JPG, PDF and TeX), in addition to unit testing and documentation for each feature. This will make it easier for users to see the equations of the model that they are using.

Mentors

Selected Proposal

Link: drive.google.com/file/d/1JLQjzG5Tv6UZbbY31I..

What was done

I added to_equation in all the classes required to print the equations for Single Particle Model (SPM), Single Particle Model with electrolyte (SPMe) and Doyle-Fuller-Newman Model (DFN). It parses all the nodes in the expression tree and using recursion gets either the print_name or the value in all the leaf nodes, converts them into relevant SymPy objects and returns the LaTeX of the equation.

See Week 1, 2 and 3 - GSoC 2021 for further details.

Setting the print_name was automated to some extent using regex and python properties. Some edge cases related to printing the partial derivative of symbols was handled by overriding the _print_Derivative method of the SymPy printer.

See Week 4, 5 and 6 - GSoC 2021 for further details.

I added a latexify method in the class BaseModel. It takes the model and recursively converts all the model expression trees, adds initial and boundary equations, concatenation summaries, the voltage equation, parameters and variables used in the equations for reference. It converts everything to latex and returns a sympy object. If a filename is provided, it will save the latex representation of that sympy object in the file.

See Week 7, 8 and 9 - GSoC 2021 for further details.

PyBaMM Showcase and AMA

Link: youtu.be/eGVuPEfIlgw

GSoC Blogs

Link to all the blogs written during GSoC:

Pull Requests

Link to all pull requests: github.com/pybamm-team/PyBaMM/pulls?q=label..

What's left to do

nothin.gif

Final thoughts

This was the biggest project I've ever worked on. It was quite challenging as my project had me touch a large portion of the codebase but it also served as a great learning experience. The best part about being in PyBaMM is that you’re accepted as a team member rather than just a student. You are invited to weekly team meetings where everyone discusses their problems and gets inputs from other members. The mentors here are quite knowledgeable and always ready to guide you. I am thankful to everyone involved for providing me with such a wonderful experience. I’ve had a lot of fun working on this project and I would love to keep contributing to the organization in the future as well!