Skip to content

Create Python Bindings #17

Description

@platinumxy

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

  • Update CMAKE to support building the python lib
  • Investigate the z3 and other general requirements for pypi distribution
  • Implement python Expr
  • Implement conversions to and from pythons Expr to CoBRAs
  • Create reduction and verification interface
  • Add some methods and attributes to Expr to make them easier to work with
  • Test, test and test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions