aiida-core icon indicating copy to clipboard operation
aiida-core copied to clipboard

Support loading other Workflow process (e.g., WorkGraph) in the WorkflowFactory

Open superstar54 opened this issue 2 weeks ago • 7 comments

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

superstar54 avatar Dec 05 '25 16:12 superstar54

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.

aman-coder03 avatar Dec 12 '25 14:12 aman-coder03

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.

superstar54 avatar Dec 12 '25 14:12 superstar54

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).

aman-coder03 avatar Dec 12 '25 14:12 aman-coder03

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.

superstar54 avatar Dec 12 '25 14:12 superstar54

The initial solution that came to mind is to check the associated ProcessNode, which is always inherited from the WorkflowNode.

superstar54 avatar Dec 12 '25 14:12 superstar54

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.

aman-coder03 avatar Dec 12 '25 15:12 aman-coder03

@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!!!

aman-coder03 avatar Dec 12 '25 16:12 aman-coder03