aiidateam / aiida-workgraph

Efficiently design and manage flexible workflows with AiiDA, featuring an interactive GUI, checkpoints, provenance tracking, and remote execution capabilities.
https://aiida-workgraph.readthedocs.io/en/latest/
MIT License
9 stars 5 forks source link

Any type does not work anymore, need to use node_graph.Any #230

Open agoscinski opened 4 weeks ago

agoscinski commented 4 weeks ago

The example from the doc does not work https://aiida-workgraph.readthedocs.io/en/latest/concept/task.html#Define-a-Task

from aiida_workgraph.task import Task

class MyAdd(Task):

    identifier: str = "MyAdd"
    name = "MyAdd"
    node_type = "calcfunction"
    catalog = "Test"
    kwargs = ["x", "y"]

    def create_sockets(self):
        self.inputs.clear()
        self.outputs.clear()
        inp = self.inputs.new("Any", "x")
        inp.add_property("Any", "x", default=0.0)
        inp = self.inputs.new("Any", "y")
        inp.add_property("Any", "y", default=0.0)
        self.outputs.new("Any", "sum")

    def get_executor(self):
        return {
            "path": "aiida_workgraph.test",
            "name": "add",
        }
from aiida_workgraph import WorkGraph
wg = WorkGraph()
wg.add_task(MyAdd, name="add1")

Error

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[2], line 27
     25 from aiida_workgraph import WorkGraph
     26 wg = WorkGraph()
---> 27 wg.add_task(MyAdd, name="add1")

File ~/code/aiida-workgraph/aiida_workgraph/workgraph.py:469, in WorkGraph.add_task(self, identifier, name, **kwargs)
    465 def add_task(
    466     self, identifier: Union[str, callable], name: str = None, **kwargs
    467 ) -> Task:
    468     """Add a task to the workgraph."""
--> 469     node = self.tasks.new(identifier, name, **kwargs)
    470     return node

File ~/code/aiida-workgraph/aiida_workgraph/collection.py:49, in TaskCollection.new(self, identifier, name, uuid, **kwargs)
     47 if isinstance(identifier, WorkGraph):
     48     identifier = build_task_from_workgraph(identifier)
---> 49 return super().new(identifier, name, uuid, **kwargs)

File ~/code/aiida-workgraph/.pixi/envs/widget-env/lib/python3.12/site-packages/node_graph/collection.py:208, in decorator_check_identifier_name.<locals>.wrapper_func(*args, **kwargs)
    204 if kwargs.get("name", None) in args[0].keys():
    205     raise Exception(
    206         "{} already exist, please choose another name.".format(args[1])
    207     )
--> 208 item = func(*args, **kwargs)
    209 return item

File ~/code/aiida-workgraph/.pixi/envs/widget-env/lib/python3.12/site-packages/node_graph/collection.py:254, in NodeCollection.new(self, identifier, name, uuid, **kwargs)
    252 else:
    253     raise Exception(f"Identifier {identifier} is not a node or node name.")
--> 254 item = ItemClass(inner_id=inner_id, name=name, uuid=uuid, parent=self.parent)
    255 self.append(item)
    256 item.set(kwargs)

File ~/code/aiida-workgraph/aiida_workgraph/task.py:39, in Task.__init__(self, context_mapping, process, pk, **kwargs)
     29 def __init__(
     30     self,
     31     context_mapping: Optional[List[Any]] = None,
   (...)
     34     **kwargs: Any,
     35 ) -> None:
     36     """
     37     Initialize a Task instance.
     38     """
---> 39     super().__init__(
     40         property_collection_class=WorkGraphPropertyCollection,
     41         input_collection_class=WorkGraphInputSocketCollection,
     42         output_collection_class=WorkGraphOutputSocketCollection,
     43         **kwargs,
     44     )
     45     self.context_mapping = {} if context_mapping is None else context_mapping
     46     self.waiting_on = TaskCollection(parent=self)

File ~/code/aiida-workgraph/.pixi/envs/widget-env/lib/python3.12/site-packages/node_graph/node.py:100, in Node.__init__(self, inner_id, name, uuid, parent, property_collection_class, input_collection_class, output_collection_class)
     98 self.ng = self.get_node_group() if self.node_type.upper() == "GROUP" else None
     99 self.create_properties()
--> 100 self.create_sockets()
    101 self.create_ctrl_sockets()

Cell In[2], line 14, in MyAdd.create_sockets(self)
     12 self.inputs.clear()
     13 self.outputs.clear()
---> 14 inp = self.inputs.new("Any", "x")
     15 inp.add_property("Any", "x", default=0.0)
     16 inp = self.inputs.new("Any", "y")

File ~/code/aiida-workgraph/aiida_workgraph/collection.py:81, in WorkGraphInputSocketCollection.new(self, identifier, name, **kwargs)
     79     identifier = build_socket_from_AiiDA(identifier)
     80 # Call the original new method
---> 81 return super().new(identifier, name, **kwargs)

File ~/code/aiida-workgraph/.pixi/envs/widget-env/lib/python3.12/site-packages/node_graph/collection.py:199, in decorator_check_identifier_name.<locals>.wrapper_func(*args, **kwargs)
    195     else:
    196         msg = "Identifier: {} is not defined. Do you mean {}".format(
    197             identifier, ", ".join(items)
    198         )
--> 199     raise Exception(msg)
    200 if len(args) > 2 and args[2] in args[0].keys():
    201     raise Exception(
    202         "{} already exist, please choose another name.".format(args[2])
    203     )

Exception: Identifier: Any is not defined.

renaming the type to node_graph.Any works, but I think that is not intenden

agoscinski commented 4 weeks ago

Seems not to be limited to the creation of a workgraph Task

superstar54 commented 4 weeks ago

Indeed! Now, we need to use workgraph.any after this PR #209 .

Beside, there is a error in the executor

-"path": "aiida_workgraph.test",
+"path": "aiida_workgraph.executors.test",
superstar54 commented 4 weeks ago

Maybe we can make it simple, for the entry point for aiida-workgraph (the core), we can skip the workgraph, and just use any. For other plugins, we still require xxx.abc, xxx is the package name.

@agoscinski what do you think?