Node similarity and leiden

Hi!
I have a use case where I want to use nodeSimilarity on a graph with 2 node types, to get a SIMILAR relationship.
I then want to use the Leiden algorithm to get communities of similar nodes.
My initial thought was to project the graph, then use nodeSimilarity.mutate to get the SIMILAR relationships with weights and use the same projection for Leiden.

However, the Leiden algorithm only accepts UNDIRECTED relationships and mutate produces pairs of directed relationships.
The only way I can think of to get around this is to write the SIMILAR relationships back to the graph and do a new graph projection, then run Leiden.
This however results in a lot of writing that seems unneccessary!
Is there any way around this? Can one project from the projection? Force the relationships to be undirected?
It is a big graph so i'd rather not write when i dont have to!

Thanks

When you project with projection of undirected, it does so by projecting pairs of bidirectional relationships. As such, the mutate may be giving what you need. Have you tried it?

Yes, I've tried


    G, res = gds.graph.project('gds_test', '*', '*')
    res = gds.nodeSimilarity.mutate(G, mutateRelationshipType='SIM', mutateProperty='similarity', similarityCutoff=0.1)
    res = gds.beta.leiden.write(G, relationshipTypes = ['SIM'], relationshipWeightProperty="similarity", writeProperty="leiden_community")

Gives


neo4j.exceptions.ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure `gds.beta.leiden.write`: Caused by: java.lang.IllegalArgumentException: The Leiden algorithm works only with undirected graphs. Please orient the edges properly}

By default, GDS projects the graph as directed. To change this behaviour you can use specify the orientation in the projection (see Projecting graphs using native projections - Neo4j Graph Data Science).

In the case of nodeSimilarity, you can also convert relationships to undirected (Relationship operations - Neo4j Graph Data Science).

For a first try or if you want to run nodeSimilarity on directed relationships, you can also just use the latter for all relationships