You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current way of registering vital algorithms is a bit unwieldy and verbose. It seems like a perfect job for a decorator. I made a small proof-of-concept that demos a possible implementation for said decorator.
We may be able to refactor something like this
# In vital.pydef_register_algorithm(cls, name=None, desc=''):
ifnameisNone:
name=cls.__name__fromvital.algoimportalgorithm_factoryifnotalgorithm_factory.has_algorithm_impl_name(cls.static_type_name(), name):
algorithm_factory.add_algorithm(name, desc, cls)
algorithm_factory.mark_algorithm_as_loaded(name)
defregister_algorithm(name=None, desc=''):
""" POC refactor of __vital_algorithm_register__ into a decorator """def_wrapper(cls):
_register_algorithm(cls, name, desc)
returnclsreturn_wrapperdeflazy_register(cls, name=None, desc=''):
''' Alternate Proof-of-Concept '''def__vital_algorithm_register__():
return_register_algorithm(cls, name, desc)
return__vital_algorithm_register__# Then in your classimportvital@vial.register_algorithm(desc="PyTorch Netharn classification routine")classMyAlgorithm(BaseAlgo):
...
# OR if the current lazy structure is importantimportvitalclassMyAlgorithm(BaseAlgo):
...
__vital_algorithm_register__=vital.lazy_register(MyAlgorithm, desc="PyTorch Netharn classification routine")
# We could also play with adding class member variables for the lazy# initialization. There is lots of room to make this better / easier.
The text was updated successfully, but these errors were encountered:
Erotemic
changed the title
Simply Algorithm Registration
Simplify Algorithm Registration
Oct 23, 2020
Erotemic
changed the title
Simplify Algorithm Registration
Simplify Vital Algorithm Registration in Python
Oct 23, 2020
I think using decorators to register the algorithm is an improvement over the current approach. As for the lazy registration, can it be used anywhere or should it present in the file with the algorithm?
If we decide to change the registration, I would recommend moving it out of vital into a module of its own since we would be replacing sprokit_register too with a decorator
The current way of registering vital algorithms is a bit unwieldy and verbose. It seems like a perfect job for a decorator. I made a small proof-of-concept that demos a possible implementation for said decorator.
We may be able to refactor something like this
The text was updated successfully, but these errors were encountered: