Summary
Create a python module with bindings into CoBRA that can be published to PyPi. Introduce: Python mappings into CoBRA's existing Exprs (using nanobind), expose some functions to allow for parsing strings to and from Exprs and introduce a reducer function that uses CoBRA to simplify expressions.
Architecture
lib/bindings/python
CobraPython.cpp - All code required to expose functions and classes to python
CobraPython.h
PythonInterface.cpp - Code that implements all the bindings (i.e. str <-> expr )
PythonInterface.h
pyproject.toml - Configuration required for pypi deployment
Python interface
-
PyExpr class that mimics that of Expr.h to make conversion trivial, we want to hide the specifics of requiring a seprate list to store the variable for equation re-construction hence we need a minimal wrapper around the Expr class.
-
to_expr(expr_string, max_vars=16) function to converts a provided string to an Expr in a similar manor to the cli's ParseToAst (This feels like something that should be re-factored into some form of shared library instead of being just in the CLI).
-
reduce(expr, bitwidth=64) runs the reduction on the expression, we can have it accept a string or a Expr to avoid creating code that looks like reduce(to_expr(foo)).
-
verify(original_expr, new_expr) using an optional dependency of Z3 (If were not forcing users to compile from source on pip install we should be ok here anyway?).
-
Some misc functions to interact with and modify an Expr.
Tasks
Summary
Create a python module with bindings into CoBRA that can be published to PyPi. Introduce: Python mappings into CoBRA's existing
Exprs (using nanobind), expose some functions to allow for parsing strings to and fromExprs and introduce a reducer function that uses CoBRA to simplify expressions.Architecture
Python interface
PyExprclass that mimics that ofExpr.hto make conversion trivial, we want to hide the specifics of requiring a seprate list to store the variable for equation re-construction hence we need a minimal wrapper around the Expr class.to_expr(expr_string, max_vars=16)function to converts a provided string to anExprin a similar manor to the cli'sParseToAst(This feels like something that should be re-factored into some form of shared library instead of being just in the CLI).reduce(expr, bitwidth=64)runs the reduction on the expression, we can have it accept a string or aExprto avoid creating code that looks likereduce(to_expr(foo)).verify(original_expr, new_expr)using an optional dependency of Z3 (If were not forcing users to compile from source on pip install we should be ok here anyway?).Some misc functions to interact with and modify an
Expr.Tasks
ExprExprto CoBRAsExprto make them easier to work with