Skip to content

Merging nodes with same name but different interfaces drops further nodes without telling #14

@andres-fr

Description

@andres-fr

Hi yahooers! Thanks for this very helpful software. I noticed one issue at graph merging, seems like a bug. I have version 1.2.4

Scenario:

  • Define graph1 = abs(a + (a * b))**3, with operations named (mul1, sum1, abspow1)
  • Define graph2 = abs(a + (a * b))**2, with operations named (mul1, sum1, abspow2)
  • Merge via graphkit.compose(name="graph3", merge=True)(graph1, graph2)
  • Both sum1 operations have same name, but crucially different output names
  • abspow1 depends on sum1, and abspow2 depends on sum2

In this scenario, two options would be acceptable when evaluating the merged graph:

  1. Merge just mul1 (same name AND interface) and leave the rest as independent branches
  2. Merge also sum2 into sum1, and make abspow2 point to sum1`

But what is happening is that both the second sum1 and abspow2 are being dropped, without any warning or exception thrown. Also, the squared output of abspow2 is missing from the merged graph's output.

I assume the reason is that the merged graph can't fullfil abspow2's interface after sum1's "faulty" merge and is dropping it silently... Is this behaviour expected? The docs are pretty clear about the "merging by name process", but I feel like this scenario could be problematic if a user inadvertently messes up the interfaces, and whole branches of the graph are dropped.

In case this is unexpected, these could be 2 possible approaches:

  1. Maybe throwing something like an InterfaceConfictError and dismissing the merge (more conservative)
  2. Make all nodes that pointed to sum2 point to sum1 after they merge, regardless of their interface (would require some assumptions on the interface or potentially a redesign of the whole library into a statically typed, TF-ish ̶n̶i̶g̶h̶t̶m̶a̶r̶e̶ experience)

I uploaded a unittest with a reproducible example into this gist, It is in the test_graph_merge_dropping method. Let me know if I can be of any help via PR.

Cheers,
Andres

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions