spcl / ncc

Neural Code Comprehension: A Learnable Representation of Code Semantics
BSD 3-Clause "New" or "Revised" License
206 stars 51 forks source link

'MultiDiGraph' object has no attribute 'node' #27

Closed PikachuHy closed 4 years ago

PikachuHy commented 4 years ago

Hi, I met some problem when use the code.

Traceback (most recent call last):
  File "/root/userfolder/code/ncc/inst2vec/inst2vec_preprocess.py", line 2828, in construct_xfg_single_raw_folder
    G, multi_edges = build_graph(preprocessed_file, functions_declared_in_files[i], file_names[i])
  File "/root/userfolder/code/ncc/inst2vec/inst2vec_preprocess.py", line 2198, in build_graph
    G = add_stmts_to_graph(G, file, functions_defined_in_file, functions_declared_in_file)
  File "/root/userfolder/code/ncc/inst2vec/inst2vec_preprocess.py", line 1503, in add_stmts_to_graph
    if basic_block_leaf(G, n, ids_in_basic_block):
  File "/root/userfolder/code/ncc/inst2vec/inst2vec_preprocess.py", line 1098, in basic_block_leaf
    if G.node[n]['id'] != 'ad_hoc':
AttributeError: 'MultiDiGraph' object has no attribute 'node'

https://github.com/spcl/ncc/blob/6bba4f32ff540cea240153bd5bddfaad5bd4f00c/inst2vec/inst2vec_preprocess.py#L1097

After read code, I think this maybe a typo. node->nodes

my pr:

https://github.com/spcl/ncc/pull/26

tbennun commented 4 years ago

Thanks! This is because of networkx changing their API in version 2.

tbennun commented 4 years ago

Merged.

See nx 1.10 reference with G.node[][]: https://networkx.github.io/documentation/networkx-1.10/reference/classes.graph.html Compared with G.nodes[][]: https://networkx.github.io/documentation/stable/reference/classes/graph.html

PikachuHy commented 4 years ago

Ok. Thank you for your prompt reply.