Abstract:E-graphs have emerged as a versatile data structure with applications in synthesis, optimization, and verification through techniques such as equality saturation. This paper introduces Python bindings for the experimental egglog library (previously called egg-smol), which aims to bring the benefits of e-graphs to the Python ecosystem. The bindings offer a high-level, Pythonic API providing an accessible and familiar interface for Python users. By integrating e-graph techniques with Python, we hope to enable collaboration and innovation across various domains in the scientific computing and machine learning communities. We discuss the advantages of using Python bindings for both Python and existing egg-smol users, as well as possible future directions for development.
What problem does this paper attempt to address?
This paper introduces a library called Egg-smol Python, which is a Python interface for the E-graph data structure. E-graphs have wide applications in areas such as synthesis, optimization, and verification through equality saturation techniques. Currently, existing E-graph implementations such as eggRust primarily utilize Rust libraries and macros, while the goal of Egg-smol Python is to bring E-graph technology into the Python ecosystem to facilitate collaboration and innovation in scientific computing and machine learning.
The paper points out that Python, being the preferred language for scientific computing and machine learning, can benefit developers and researchers by integrating E-graph technology. Some existing Python libraries like Quiche and snake-egg provide support for E-graphs, but the authors aim to improve usability with a more "Pythonic" API. The Egg-smol Python binding library is built using the PyO3 library, which provides a high-level API built upon the low-level API of the Rust library, enabling Python users to utilize E-graphs for expression modeling and rewriting.
Advantages of the Python bindings include:
1. Providing familiar constructs to Python users such as functions, classes, and methods, making the library more accessible and easy to use.
2. Leveraging the performance of the Rust library while allowing Python users to benefit from the latest advancements in the E-graph domain.
3. Compared to the existing snake-egg API, the Egg-smol Python bindings are more restrictive but help ensure consistency of rewrite rules across different libraries.
For existing Egg-smol users, the Python interface may be more verbose, but leveraging Python's operator overloading for mathematical expressions can lead to more concise code. Additionally, Python's static type checking, autocompletion, and interactive environments like Jupyter provide more convenience for E-graph operations.
Future directions of work include supporting the embedding of existing Python types, simplifying the API, collaborating with upstream libraries' prototypes, importing and exporting E-graph descriptions, and utilizing Python's state management and module system. These improvements aim to enhance the applicability and user experience of Egg-smol Python in practical applications, while promoting the adoption and interdisciplinary collaboration of E-graph technology in the Python community.