google-research / python-graphs

A static analysis library for computing graph representations of Python programs suitable for use with graph neural networks.
Apache License 2.0
325 stars 39 forks source link

How to generate a Holistic Data Flow Graph for a given Function ? #1

Closed reshinthadithyan closed 2 years ago

reshinthadithyan commented 2 years ago

@dbieber, Thanks for this awesome work.

Question

control_flow.get_control_flow_graph, returns a Control Flow Graph for a given Function Object. There is one data_flow class, Is there a way to generate a complete Data Flow Graph given a Function Object?

Thanks.

dbieber commented 2 years ago

Have a look at program_graph.get_program_graph, with example usage in https://github.com/google-research/python-graphs/blob/main/python_graphs/program_graph_test.py.

It doesn't do exactly what you're asking for. Instead it constructs a "program graph" consisting of AST, data flow, control flow, and lexical edges. It should be possible to write a similar function that only incorporates the data flow edges.

Heads up that data flow is less battle tested than control flow in the library, so there are likely sharp edges along the way.

dbieber commented 2 years ago

Let me know if you have any further questions. And if you do write a complete data flow graph function, please consider contributing it back to the library.