neuromorphs / NIR

Neuromorphic Intermediate Representation reference implementation
https://neuroir.org/docs
BSD 3-Clause "New" or "Revised" License
76 stars 10 forks source link

Reorganise ir and add auto serialisation #78

Closed alexfanqi closed 8 months ago

alexfanqi commented 8 months ago

Hi,

Since it seems no one is working on #55, I took the liberty to fix it. If this happens to be a few hours faster than anyone's work :-P, I am happy to withdraw or discuss for a better implementation.

Deserialization requires a reflection registry to create class from string. I choose to explicitly list all serialisable NIRNodes in a static ir.__all_ir because it is simple and there seems to be no demand for user-defined NIRNode out of the repo.

Another option would be using metaclass/ __init_subclass__ to dynamically register new sub classes in NIRNode. But I feel __init_subclass is black magic.

Would love any feedback for new file structure and implementation.

Cheers

alexfanqi commented 8 months ago

Testing was done by first testing new serialization against old deserialization, then testing new {de,}serializations together.

Jegp commented 8 months ago

Thank you for the addition! It looks great, but there is one test that's failing because you're using a "|" for a type annotation. Swapping that with Union should do the trick. I'm also happy to push the change, if you prefer :)

Jegp commented 8 months ago

Thank you for seeing this through @alexfanqi :partying_face:

Jegp commented 8 months ago

Closes #55