Support loading other Workflow process (e.g., WorkGraph) in the WorkflowFactory
Currently, WorkflowFactory hard-codes WorkChain and WorkFunction as the only valid classes.
If I register a WorkGraph in the workflow entry point:
[project.entry-points."aiida.workflows"]
"ase.espresso.eos" = "workgraph_collections.ase.espresso.eos:EosWorkGraph"
Then, I loaded the WorkGraph using WorkflowFactory, and I got this error.
In [1]: WorkflowFactory("ase.espresso.eos")
---------------------------------------------------------------------------
InvalidEntryPointTypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 WorkflowFactory("ase.espresso.eos")
File ~/apps/miniforge3/envs/aiida/lib/python3.11/site-packages/aiida/plugins/factories.py:477, in WorkflowFactory(entry_point_name, load)
472 if (isclass(entry_point) and issubclass(entry_point, WorkChain)) or (
473 is_process_function(entry_point) and entry_point.node_class is WorkFunctionNode # type: ignore[union-attr]
474 ):
475 return entry_point
--> 477 raise_invalid_type_error(entry_point_name, entry_point_group, valid_classes)
File ~/apps/miniforge3/envs/aiida/lib/python3.11/site-packages/aiida/plugins/factories.py:58, in raise_invalid_type_error(entry_point_name, entry_point_group, valid_classes)
56 template = 'entry point `{}` registered in group `{}` is invalid because its type is not one of: {}'
57 args = (entry_point_name, entry_point_group, ', '.join([e.__name__ for e in valid_classes]))
---> 58 raise InvalidEntryPointTypeError(template.format(*args))
InvalidEntryPointTypeError: entry point `ase.espresso.eos` registered in group `aiida.workflows` is invalid because its type is not one of: WorkChain, workfunction
In principle, WorkflowFactory should load all Workflow processes.
This is originally reported in this comment: https://github.com/aiidateam/aiida-workgraph/issues/723#issuecomment-3602661579
I'd like to contribute to this issue. @superstar54
It seems WorkflowFactory currently only accepts WorkChain and WorkFunction, so WorkGraph entry points fail type checks.
Hi @aman-coder03 , thanks for looking into this.
Note, aiida-core will not know WorkGraph, because we don't add aiida-workgraph as a dependency of aiida-core. Thus, we need to find a general way to recognize a Workflow process. Unfortunately, there is no WorkflowProcess, both WorkChain and WorkGraph inherit from the Process class directly.
thanks @superstar54 for your reply!!
One idea is to allow any class inheriting from Process and let plugins mark their workflows via a simple attribute/protocol (e.g., is_workflow = True).
Adding is_workflow attribute could be a fast and simple solution, but it is a "new" api, and it requires other workflow process classes (WorkChain, WorkGraph, maybe others) to update.
The initial solution that came to mind is to check the associated ProcessNode, which is always inherited from the WorkflowNode.
Thanks for the clarification, checking the associated ProcessNode sounds like a clean and backward-compatible approach, since WorkflowNode already represents the class of workflow processes.
@superstar54
node_class = getattr(entry_point, "node_class", None)
if node_class is not None and issubclass(node_class, WorkflowNode):
return entry_point
placed just before the InvalidEntryPointTypeError is raised.
If this approach matches what you have in mind, I can prepare a PR implementing it!!!