Replacing a node in a ComputeGraph (Makie)

Is there any way to replace a node in a ComputeGraph?
Let’s say I want to replace an input node with a computed value, but I do not want to delete all the dependent nodes and recreate them.

Example

Given this graph:

graph = ComputeGraph()
add_input!(graph, :A, 1)
add_input!(graph, :B, 2)
register_computation!(graph, [:A, :B], [:C]) do inputs, changed, cached
    return (inputs.A[] + inputs.B[], )
end

Is it possible to transform it into:

graph2 = ComputeGraph()
add_input!(graph2, :A, 1)
add_input!(graph2, :X, 2)
register_computation!(graph2, [:X], [:B]) do inputs, changed, cached
    return (inputs.X[]*100, )
end
register_computation!(graph2, [:A, :B], [:C]) do inputs, changed, cached
    return (inputs.A[] + inputs.B[], )
end

without deleting and recreating the node :C?

No not really and there likely wont be.
Btw, using ComputeGraph outside plot.attributes isn’t totally recommended, since we’re not entirely sure in which direction the compute graph will go and how to manage its life cycle outside of plot recipes.
Best only do it when you have a strong reason for it.

1 Like

I was also looking for such functionality recently… Basically, to “insert” a step between existing calculations in a plotting setup.

1 Like

Thanks for the input!

This is for modifying the “axis” plot object of an LScene. That is, let’s say I have

fig = Figure()
ax = fig[1,1] = LScene(fig)
p = only(ax.scene.plots)

and I want the axisnames (labels for each axis) to depend on something.
I am able to access this as an Observable using

p.attributes.inputs[:names].value.axisnames

and by modifying that (e.g. using connect!), I can achieve what I want right now.

So maybe my question is more about the long term relationship between Observables and ComputeGraph. My impression (perhaps incorrectly) was that in the long run, we should prefer to remove Observables and implement as much as possible using the ComputeGraph directly - to avoid e.g. problems with updates that need to be synchronous.

And if later, axisnames is implemented with Observables, I wouldn’t be able to make it depend on something computed - without replacing the node in the compute graph.