Hi,
I'm using Neo4j 4.0.4 with GraphDataScience 1.2.1 library, from python 3.8.3 using the official neo4j python driver.
I have a script to call Louvain algorithm from python, but my database keeps crashing with the following error :
Traceback (most recent call last):
File "<ipython-input-1-4a6a01b5290f>", line 44, in <module>
call_louvain_algo(subject, obj, clust, rel_name, nb_supports, driver)
File "<ipython-input-1-4a6a01b5290f>", line 26, in call_louvain_algo
results = [[record['id'], record['communityId']] for record in results]
File "<ipython-input-1-4a6a01b5290f>", line 26, in <listcomp>
results = [[record['id'], record['communityId']] for record in results]
File "/home/briere/miniconda3/envs/ClustOmics/lib/python3.8/site-packages/neo4j/work/result.py", line 184, in __iter__
self._connection.fetch_message() # Receive at least one message from the server, if available.
File "/home/briere/miniconda3/envs/ClustOmics/lib/python3.8/site-packages/neo4j/io/_bolt4x0.py", line 330, in fetch_message
response.on_failure(summary_metadata or {})
File "/home/briere/miniconda3/envs/ClustOmics/lib/python3.8/site-packages/neo4j/io/_bolt4x0.py", line 518, in on_failure
raise Neo4jError.hydrate(**metadata)
TransientError: Database 'neo4j' unavailable
Here is my code :
import numpy as np
from neo4j import GraphDatabase
def call_louvain_algo(subject, obj, clust, rel_name, nb_supports, driver):
with driver.session() as session:
print("louvain")
obj1_nodes = "(o1:"+ obj + ":" + subject + ")"
obj2_nodes = "(o2:"+ obj + ":" + subject + ")"
cat_graph_name = "_".join([rel_name, str(nb_supports)])
objects =' MATCH ' + obj1_nodes + '-[r:' + rel_name + ']-' + obj2_nodes + \
' WHERE r.nb_supports >= ' + str(nb_supports) + ' RETURN DISTINCT id(o1) as id'
relations = 'MATCH ' + obj1_nodes + '-[r:' + rel_name + ']->' + obj2_nodes + \
' WHERE r.nb_supports >= ' + str(nb_supports) + ' RETURN id(o1) as source, id(o2) as target, r.nb_supports as weight'
make_graph_cat = "CALL gds.graph.create.cypher('" + cat_graph_name +\
"', '" + objects + "', '" + relations + "')"
session.run(make_graph_cat)
call_louvain = "CALL gds.louvain.stream('" + cat_graph_name +\
"',{relationshipWeightProperty:'weight', maxIterations:10})" +\
"YIELD nodeId, communityId RETURN gds.util.asNode(nodeId).id as id, communityId"
results = session.run(call_louvain)
results = [[record['id'], record['communityId']] for record in results]
remove_graph_cat = "CALL gds.graph.drop('" + cat_graph_name + "') YIELD graphName;"
session.run(remove_graph_cat)
return(np.array(results))
neo_id = 'neo4j'
neo_pwd = '4jneo'
neo_localhost = "bolt://localhost:7687"
subject = "SARC"
obj = "Patient"
clust = "Cluster"
rel_name = "SARC_EXP_MIRNA_MET_NEMO_PINS_SNF_rMKL"
nb_supports = 2
driver = GraphDatabase.driver(uri=neo_localhost, auth=(neo_id, neo_pwd))
for i in range(0,8):
call_louvain_algo(subject, obj, clust, rel_name, nb_supports, driver)
driver.close()
It runs fine for few iterations, but when executed multiple times in a row, then the database crashes.
Am I using session.run() wrong, is it a configuration issue ?
All tips appreciated,
Best regards,
GB