-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Passing SinglefileData to a task, e.g.
from pathlib import Path
from aiida.orm import StructureData, SinglefileData, Bool
from aiida import load_profile
from aiida_workgraph import task
from ase.io import read
load_profile()
struct = read("../structures/NaCl-traj.xyz")
struct_data = StructureData(ase=struct)
file = SinglefileData(Path("../structures/NaCl-traj.xyz").absolute())
from aiida_workgraph import WorkGraph, task
from aiida import load_profile
load_profile()
wg = WorkGraph(name='my_first_workgraph')
@task
def test_func(x):
return x
# return Bool(x is not None)
wg = WorkGraph("test_wg")
# wg.inputs.x = struct
wg.inputs.x = file
wg.add_task(test_func, "test", x=wg.inputs.x)
wg.outputs.result = wg.tasks.test.outputs.result
# Run the WorkGraph
wg.run()
raises the following error:
12/03/2025 03:53:11 PM <61640> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [32826|WorkGraphEngine|continue_workgraph]: tasks ready to run: test
12/03/2025 03:53:11 PM <61640> plumpy.processes: [ERROR] Error in task test: Cannot deserialize AiiDA data of type `aiida.orm.nodes.data.singlefile.SinglefileData`. This type does not define a `.value` attribute, and no matching deserializer was provided in `deserializers` for key `aiida.orm.nodes.data.singlefile.SinglefileData`. To fix this, either:
1. Use a Data type with a `.value` property, or
2. Provide a custom deserializer in `deserializers`, e.g.:
deserializers = {
'aiida.orm.nodes.data.singlefile.SinglefileData': 'my_package.my_module.my_deserializer'
}
Traceback (most recent call last):
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_workgraph/engine/task_manager.py", line 202, in execute_function_task
process, _ = task.execute(args, kwargs, var_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_workgraph/tasks/pythonjob_tasks.py", line 222, in execute
_, process = run_get_node(
^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/launch.py", line 65, in run_get_node
return runner.run_get_node(process, inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/runners.py", line 291, in run_get_node
result, node = self._run(process, inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/runners.py", line 241, in _run
result, node = process.run_get_node(**inputs) # type: ignore[union-attr]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_pythonjob/decorator.py", line 87, in run_get_node
process = PyFunction(inputs=process_inputs, runner=runner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 205, in __call__
inst.transition_to(inst.create_initial_state())
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 357, in transition_to
self.transition_failed(initial_state_label, label, *sys.exc_info()[1:])
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 1095, in transition_failed
raise exception.with_traceback(trace)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 343, in transition_to
self._enter_next_state(new_state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 410, in _enter_next_state
self._fire_state_event(StateEventHook.ENTERING_STATE, next_state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 311, in _fire_state_event
callback(self, hook, state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 358, in <lambda>
state_machine.StateEventHook.ENTERING_STATE: lambda _s, _h, state: self.on_entering(
^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 725, in on_entering
call_with_super_check(self.on_create)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/utils.py", line 31, in call_with_super_check
wrapped(*args, **kwargs)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/processes/process.py", line 453, in on_create
super().on_create()
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/utils.py", line 16, in wrapper
wrapped(self, *args, **kwargs)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 789, in on_create
result = self.spec().inputs.validate(self._parsed_inputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/ports.py", line 665, in validate
message = self.validator(port_values_clone, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_pythonjob/calculations/common.py", line 76, in validate_function_inputs
deserialize_to_raw_python_data(function_inputs, deserializers=deserializers, dry_run=True)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_pythonjob/data/deserializer.py", line 88, in deserialize_to_raw_python_data
return {k: deserialize_to_raw_python_data(v, deserializers=deserializers) for k, v in data.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_pythonjob/data/deserializer.py", line 75, in deserialize_to_raw_python_data
raise ValueError(
ValueError: Cannot deserialize AiiDA data of type `aiida.orm.nodes.data.singlefile.SinglefileData`. This type does not define a `.value` attribute, and no matching deserializer was provided in `deserializers` for key `aiida.orm.nodes.data.singlefile.SinglefileData`. To fix this, either:
1. Use a Data type with a `.value` property, or
2. Provide a custom deserializer in `deserializers`, e.g.:
deserializers = {
'aiida.orm.nodes.data.singlefile.SinglefileData': 'my_package.my_module.my_deserializer'
}
This is fairly unexpected given that it's an aiida-core datatype, is not the case for StructureData, which also lacks a .value attribute, and this error is not raised if I convert the decorator to a task.calcfunction.
In this case, however, I get a different error:
12/03/2025 03:55:25 PM <61640> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [32828|WorkGraphEngine|continue_workgraph]: tasks ready to run: test
12/03/2025 03:55:26 PM <61640> aiida.orm.nodes.process.calculation.calcfunction.CalcFunctionNode: [REPORT] [32829|test_func|on_except]: Traceback (most recent call last):
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 343, in transition_to
self._enter_next_state(new_state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 414, in _enter_next_state
self._fire_state_event(StateEventHook.ENTERED_STATE, last_state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 311, in _fire_state_event
callback(self, hook, state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 361, in <lambda>
state_machine.StateEventHook.ENTERED_STATE: lambda _s, _h, from_state: self.on_entered(
^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/processes/process.py", line 480, in on_entered
self.update_outputs()
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/processes/process.py", line 722, in update_outputs
output.base.links.add_incoming(self.node, LinkType.CREATE, link_label)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/orm/nodes/links.py", line 57, in add_incoming
self.validate_incoming(source, link_type, link_label)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/orm/nodes/links.py", line 94, in validate_incoming
raise ValueError('the link you are attempting to create would generate a cycle in the graph')
ValueError: the link you are attempting to create would generate a cycle in the graph
12/03/2025 03:55:26 PM <61640> plumpy.processes: [ERROR] Error in task test: the link you are attempting to create would generate a cycle in the graph
Traceback (most recent call last):
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_workgraph/engine/task_manager.py", line 202, in execute_function_task
process, _ = task.execute(args, kwargs, var_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida_workgraph/tasks/aiida.py", line 33, in execute
_, process = run_get_node(executor, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/launch.py", line 65, in run_get_node
return runner.run_get_node(process, inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/runners.py", line 291, in run_get_node
result, node = self._run(process, inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/runners.py", line 241, in _run
result, node = process.run_get_node(**inputs) # type: ignore[union-attr]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/processes/functions.py", line 246, in run_get_node
result = process.execute()
^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/processes/functions.py", line 555, in execute
result = super().execute()
^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 101, in func_wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 1313, in execute
return self.future().result()
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 343, in transition_to
self._enter_next_state(new_state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 414, in _enter_next_state
self._fire_state_event(StateEventHook.ENTERED_STATE, last_state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/base/state_machine.py", line 311, in _fire_state_event
callback(self, hook, state)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/plumpy/processes.py", line 361, in <lambda>
state_machine.StateEventHook.ENTERED_STATE: lambda _s, _h, from_state: self.on_entered(
^^^^^^^^^^^^^^^^
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/processes/process.py", line 480, in on_entered
self.update_outputs()
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/engine/processes/process.py", line 722, in update_outputs
output.base.links.add_incoming(self.node, LinkType.CREATE, link_label)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/orm/nodes/links.py", line 57, in add_incoming
self.validate_incoming(source, link_type, link_label)
File "/Users/elliottkasoar/Documents/PSDI/aiida-mlip/.venv/lib/python3.12/site-packages/aiida/orm/nodes/links.py", line 94, in validate_incoming
raise ValueError('the link you are attempting to create would generate a cycle in the graph')
ValueError: the link you are attempting to create would generate a cycle in the graph
This is independent of the input data (e.g. the same is triggered for wg.inputs.x = 1, which is not the case for a normal @task. Changing the function to not purely return the input, e.g. the commented out return Bool(x is not None) resolves this.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels