OpenCyphal / pydsdl

Cyphal DSDL processing front end implemented in Python
https://opencyphal.org
MIT License
10 stars 9 forks source link

Use analytical solver for BitLengthSet instead of numerical computation #66

Closed pavel-kirienko closed 3 years ago

pavel-kirienko commented 3 years ago

Fixes #23

This change request slightly alters the BitLengthSet API by adding handles for the underlying solver but the old entries are kept in place to not break existing applications. The old entries are still susceptible to combinatorial explosion so in order to take advantage of the solver, existing applications (Nunavut) should be updated. The update amounts to ditching all calls to BitLengthSet.__iter__, BitLengthSet.__len__, BitLengthSet.__eq__ because they trigger numerical expansion. Instead, new attributes min, max, fixed_length, and __mod__ should be used as they are evaluated in linear time (also the results are cached).

If PyDSDL is asked to perform a slow numerical expansion, the stack trace of the request is logged to help one hunt down dependencies on the old API.

I am going to update the Nunavut templates soon. While doing that, I am likely to find deficiencies of the new implementation so the version is set to dev for now.

DSDL expressions evaluated for @assert, @print, @sealed, [...] etc always trigger numerical expansion for now so one should be careful with these. It is possible to update the expression evaluation logic to take advantage of the solver where possible but this has not been done yet and it is not on my roadmap because it doesn't seem important. I did, however, put a TODO comment or two.

This is how you can install it for testing locally:

pip install git+https://github.com/UAVCAN/pydsdl@combinatorial-explosion
pavel-kirienko commented 3 years ago

@thirtytwobits I tagged you for review but it is not really necessary to dig into the code. Rather, a high-level response like "yup it makes sense" (or don't) is needed. I linked the new docs in the OP post.