haesleinhuepf / napari-workflows

BSD 3-Clause "New" or "Revised" License
12 stars 10 forks source link

Distinguish between string and task name #42

Open multimeric opened 2 months ago

multimeric commented 2 months ago

Currently the napari workflow format uses strings as arguments, either to name tasks that they depend on, or as literal strings. If the workflow is "complete", ie all the dependencies are specified, then this is not a big issue: any strings that correspond to a task name are assumed to be dependencies, otherwise they are strings. However, it does mean that any determination of inputs is impossible. In the following task, I have one task (strlen) that just calculates the length of "some_string" and has no inputs. I also have dimensions which returns the shape of an unspecified image. However if I try to work out which inputs the workflow needs to run, roots() thinks that both are inputs:

from napari_workflows import Workflow
from numpy import shape

w = Workflow()
w.set("dimensions", shape, "input_img")
w.set("strlen", len, "some_string")
w.roots()
['input_img', 'some_string']

The only true result here should be input_img.

I think it would be better to use a special type to either mark literal strings or task connections, in order to disambiguate this scenario. For example something like this would be ideal:

from napari_workflows import dependency

w.set("dimensions", shape, dependency("input_img"))
w.set("strlen", len, "some_string")
haesleinhuepf commented 2 months ago

Hi @multimeric ,

awesome, thanks for the feedback! I have no idea if this technically feasible. Under the hood we are using dask graphs and strings as keys because napari layers have string names. Saying that, if you could implement your proposal in a way that this plugin still works with napari and code generation with the napari-assisrant, I'd be happy to merge your pull-request.

Let me know if I can do anything to support you!

Best, Robert