buckbaskin / formak

https://buckbaskin.com/formak/generated/html/index.html
MIT License
3 stars 0 forks source link

Common Subexpression Elimination for Python, C++ #14

Closed buckbaskin closed 1 year ago

buckbaskin commented 1 year ago

FormaK aims to combine symbolic modeling for fast, efficient system modelling with code generation to create performant code that is easy to use.

The Five Key Elements the library provides to achieve this user experience are:

  1. Python Interface to define models
  2. Python implementation of the model and supporting tooling
  3. Integration to scikit-learn to leverage the model selection and parameter tuning functions
  4. C++ and Python to C++ interoperability for performance
  5. C++ interfaces to support a variety of model uses

This design provides an extension to the second of the Five Keys "Python implementation of the model..." and the fifth of the Five Keys "C++ interfaces to support a variety of model uses" to support the performance goals of the library: Common Subexpresion Elimination (CSE).

CSE is a transformation on the compute graph of the underlying model (for either Python or C++) to remove duplicate compuation at multiple scales. For example, if a sensor model computes a + b multiple times, CSE identifies this subexpression and computes it once. This could also apply to a more complicated expression like 9.81 * sin(theta + bias).

One of the nicest benefits of this transformation is that it will provide a performance benefit to the model without a compromise to the user interface.