neo4j / graph-data-science

Source code for the Neo4j Graph Data Science library of graph algorithms.
https://neo4j.com/docs/graph-data-science/current/
Other
640 stars 161 forks source link

GDS 2.12 - Graph Object has no attribute 'name' #338

Closed Mintactus closed 3 hours ago

Mintactus commented 1 day ago

Neo4j 5.25.1 GDS 2.12 GDS Python Client 1.12

This is a shitshow, I have been stuggeling to make a simple projection works since hours and I never had a problem like that, something is wrong with GDS 2.12.

I'm also the one who wrote the "GDS - RandomWalk - Unable to load NODE" post. I hink both problems could be linked.

  File "/venv/lib/python3.12/site-packages/graphdatascience/algo/algo_proc_runner.py", line 16, in _run_procedure
    params = CallParameters(graph_name=G.name(), config=config)
                                       ^^^^^^
AttributeError: 'GraphCreateResult' object has no attribute 'name'

This is the call I used

    def run_random_walk(self):
        gds = GraphDataScience(NEO4j_CREDENTIALS['uri'], auth=NEO4j_CREDENTIALS['auth'], database=PAIR)
        graph = gds.graph.project(
            graph_name = 'eurusd',
            node_spec = {'Pattern': {'properties': 'pattern'}},  # Node projection
            relationship_spec = {'TO': {'properties': 'transition probability'}})
        pattern = self.markov_chain_nodes['pattern'].last()
        sourceNode = gds.find_node_id(["Pattern"], {"pattern": pattern})
        print(sourceNode)

        random_walk_config = {
            'sourceNodes': [sourceNode],
            'walkLength': FUTURE_SIZE,
            'walksPerNode': 1,
            'relationshipWeightProperty': 'transition probability',
            'concurrency': 4
        }
        future = gds.randomWalk.stream(graph, **random_walk_config)
        print(future)

If you need anything else let me know

Thanks for your support

IoannisPanagiotas commented 23 hours ago

Hi again @Mintactus,

Can you try G = gds.graph.get("eurusd") and use G to run the randomWalk?

The graph in your instance corresponds to the projection result which is not necessarily the graph object. Doing the line above should help.

Also, make sure to check florentin's reply to your other thread bypass creating a disk graph.

Best regards, Ioannis.

Mintactus commented 13 hours ago

Thanks Ioannis

You were certainly right, I did some reseach and I felt into a sneaky trap of python beginner:

"""In Python, when a function returns multiple values, it actually returns a tuple containing those values. If you only assign one variable to receive the return value, you'll get the entire tuple assigned to that variable"""

gds.graph.project does return two things as a tuple, and the tuple won't be the graph object needed by the algos, so i can assign tow variables to get its return right. graph, result = gds.graph.project() like said in the neo4j doc

I will test both soon :)

FlorentinD commented 10 hours ago

As a tip, I can also recommend using mypy to find out such problems.

Also our API docs contain the GraphCreateResult (see https://neo4j.com/docs/graph-data-science-client/1.12/api/graph_create_result/). Its actually a named tuple, thats why you can use result.graph as well

Mintactus commented 3 hours ago

Thanks guys, I will mark the issue as closed.