grand-cypher icon indicating copy to clipboard operation
grand-cypher copied to clipboard

Support passing `hints` in grandiso

Open j6k4m8 opened this issue 10 months ago • 3 comments

grandiso.find_motifs supports a hints attribute with is a list of partial-mappings, instead of requiring an exhaustive search:

host = nx.DiGraph()
nx.add_path(host, ["A", "B", "C", "A"])
motif = nx.DiGraph()
nx.add_path(motif, ["A", "B", "C", "A"])
assert (
    find_motifs(
        motif,
        host,
        count_only=True,
        # ↓ won't yield anything ↓   ↓ results in 1 match ↓
        hints=[{"A": "A", "B": "C"}, {"A": "A", "B": "B"}],
    )
    == 1
)

It would be a HUGE query savings if we could optionally pass a set of hints directly to the grandcypher constructor:

GrandCypher(G.nx).run(" ... ", grandiso_hints=[{"A": "A", "B": "B"}])

It would also be a huge performance boost if we took the attributes that have "simple" mappings (attribute equality, for instance) and auto-generated a set of hints from that. For example,

MATCH (A)-[]->(B)
WHERE B.username == "j6k4m8"
RETURN A

We should see that B can be easily found first, and populate a set of hints with all valid matches for B before we even call the motif search here.

j6k4m8 avatar Feb 01 '25 20:02 j6k4m8

This does seem like a really interested idea!

davidmezzetti avatar Feb 14 '25 17:02 davidmezzetti

This is interesting. I was having performance issues when I used grand-cypher in a large-scale project. I ended up traversing the graph myself.

This might be the solution. It's excited to see how the project grows, truely.

I forget a lot of stuff, but I think the node json_rule can be a good start for hinting.

khoale88 avatar Oct 29 '25 16:10 khoale88

Hi @j6k4m8 , coiuld you please help create 2 sub-issues for adding node hints from node json_data, and another one from node labels?

khoale88 avatar Oct 31 '25 15:10 khoale88