april-tools / cirkit

a python framework to build, learn and reason about probabilistic circuits and tensor networks
https://cirkit-docs.readthedocs.io/en/latest/
GNU General Public License v3.0
80 stars 4 forks source link

Allowing users to add new operators #276

Open lkct opened 1 month ago

lkct commented 1 month ago

Currently, end-users cannot add a new circuit operator, as it involves modifying (instead of inheriting) some classes in the library. The original motivation is that adding a new operator requires more understanding of the internals of the library and should be done as a dev.

However, it would still be great if we allow users to do so. E.g. to implement Fisher Divergence, the current version of cirkit is still not enough -- we lack a "sum operator" for the inner product, which should be easy to impl, but still impossible with only user code.

cc @loreloc

lkct commented 1 month ago

Some premature idea: Use more "registries" so that the classes are switchable by registering a subclass.

Meanwhile, we have registry override implemented, which might be useful, e.g. https://github.com/april-tools/cirkit/blob/00c07f061325293da37a2d93b93db5b02f49d1bb/cirkit/symbolic/functional.py#L162