Closed vloncar closed 1 year ago
This is now ready for review. I've added a basic test (we already tested many, many expressions). I am still thinking to add a page in the docs, perhaps as part of a docs PR for the new release. There will also be a notebook added to hls4ml-tutorial
repo. Since this introduces a new dependency (sympy
) that is rarely used in regular ML, I've added an extra installation target that will install it. For example, doing pip install hls4ml[sr]
will include main hls4ml + sympy. Still not sure if pysr
should be listed, since one feature is to register LUT functions with it, but in theory, the origin of expressions doesn't have to be PySR (they are just strings).
Description
This PR adds the ability to generate HLS code to evaluate symbolic expressions in hls4ml for people wanting to play with symbolic regression. It is very simple, it is implemented as a simple backend, leveraging everything from Vivado. The math operations come from
hls_math.h
. Expression handling itself and producing code is done with SymPy. There are still many things to improve, like the precision handling, accumulator types, using our lookup table-based implementations of math functions etc. But most of the expressions produced by PySR already work.Type of change
For a new feature or function, please create an issue first to discuss it with us before submitting a pull request.
Note: Please delete options that are not relevant.
Tests
The main function to convert is called
convert_from_symbolic_expression
, it takes a sympy expression, or a string from which a sympy expression can be built. This can also come from aPySRRegressor
. For example:Checklist