How to hash a graph in igraph (python)?

Hello, I’m wondering whether we can hash a graph object? It seems that __hash__ method has been included in graph class, but the documentation documentation for hash says it is None.

In Python, most objects are hashable by default; setting __hash__ to None is the traditional way to indicate that an object is not meant to be hashable. If you really want to use graphs as keys in a dictionary, you can use id(graph) as a hash key - at least this makes it explicit that it’s not the structure of the graph that matters when hashing but its identity.

Thanks for your reply! However, in my case perhaps id(graph) is not a good choice. I need to generate a lot of random graphs and for each graph, I need to compute a score function related to its structure. I hope to save scores we have computed to prevent repeated computing. Therefore, the structure of the graph matters. Now, I convert the adjacency matrix to a long list and then view it as binary code of an integer. This method works in practice for small graphs.

This is probably the best that you can do; one other thing that you could try is to convert the adjacency matrix into Python tuples because tuples are hashable by content and not by identity.