Skip to content

GSoC 2021 Report: Mohit Balwani Refactor the ODE module and make it fast

Mohit Balwani edited this page Aug 18, 2021 · 3 revisions

This report summarizes the work done in my GSoC 2021 project, Refactor the ODE module and make it fast with SymPy. Blog posts with step by step development of the project are available at my medium profile.

About Me

I am Mohit Balwani and I have completed my undergraduate course in Information and Communication Technology from Adani Institute of Infrastructure Engineering.

Overview

The goal of the project is to organise each of the solvers into a class with a consistent interface. Then the main part of dsolve can loop over these classes rather than having a monolothic matching function. This will make the code easier to maintain, understand and eliminate the need for global variables. My mentors were Aaron Meurer (Primary) and Oscar Benjamin.

Work Completed

Here is a list of PRs which were opened during the span of GSoC:

  • (Merged) #21555: Refactor liouville solver

  • (Merged) #21569: Refactor separable solver

  • (Merged) #21578: Refactor separable reduced

  • (Merged) #21588: Refactor dep-div-indep hint

  • (Merged) #21609: Refactor(dsolve): nth order reducible

  • (Megred) #21630: Refactor hypergeometric solver

  • (Merged) #21654: Refactor const homogenous hints

  • (Merged) #21692: Refactor euler solvers

  • (Merged) #21706: Refactor bessel solver

  • (Merged) #21722: Refactor lie group solver

  • (Merged) #21743: Improve dsolve

  • (Merged) #21816: Reorder hints in dsolve

We had an important discussion regarding our initial approach on issue #18348

After PR #21743 speed of test suite got much better :

  1. bin/doctest sympy/solvers/ode took 233.06 seconds before PR and 195.56 seconds after PR.

  2.  In [2]: import sympy
     In [3]: %time sympy.test('sympy/solvers/ode/tests/test_ode.py')   #on master
     CPU times: user 644 µs, sys: 7.56 ms, total: 8.2 ms
     Wall time: 1min 51s
     ***************************************************************************************************
     In [2]: %time sympy.test('sympy/solvers/ode/tests/test_ode.py')   #on this Branch
     CPU times: user 1.43 ms, sys: 8.07 ms, total: 9.5 ms
     Wall time: 1min 25s
  3.  In [2]: import sympy
     In [3]: %time sympy.test('sympy/solvers/ode/tests/test_single.py')   #on master
     CPU times: user 0 ns, sys: 9.96 ms, total: 9.96 ms
     Wall time: 25min 39s
     ***************************************************************************************************
     In [2]: %time sympy.test('sympy/solvers/ode/tests/test_single.py')   #on this Branch
     CPU times: user 4.75 ms, sys: 4.29 ms, total: 9.04 ms
     Wall time: 24min 43s

These doesn't include examples marked as XFAIL or Slow.

After PR #21816 dsolve became 10x faster as it improved from 1.26±0s to 129±0.2ms

Future Work

  • Overall code has been improved a lot in classify_ode, only the series solvers are left which needs to be taken care. Ultimately they should be moved out of the dsolve and there will be separate user function dsolve_series or there can be kind of flag in dsolve for the user if he wants the series solutions.

  • After refactoring of series solvers, dependancy of classify_ode can be removed from dsolve.

  • Currently the code in odesimp doesn't do much simplification, there are explicit conditions for solvers which ideally shouldn't be the case. So, the odesimp code can also be improved.

Conclusion

This summer has been a great learning experience. In terms of development I explored various aspects from writing functionality to testing and debugging. I would like to thank Aaron Meurer and Oscar Benjamin for their valuable suggestions and being readily available for discussions. They were always very friendly and helpful.

I would definitely stick around after the GSoC period as well and continue contributing to SymPy, hopefully, exploring the other modules as well.

Clone this wiki locally