A static analysis library for computing graph representations of Python programs suitable for use with graph neural networks.

Overview

python_graphs

This package is for computing graph representations of Python programs for machine learning applications. It includes the following modules:

  • control_flow For computing control flow graphs statically from Python programs.
  • data_flow For computing data flow analyses of Python programs.
  • program_graph For computing graphs statically to represent arbitrary Python programs or functions.
  • cyclomatic_complexity For computing the cyclomatic complexity of a Python function.

Installation

To install python_graphs with pip, run: pip install python_graphs.

To install python_graphs from source, run: python setup.py develop.

Common Tasks

Generate a control flow graph from a function fn:

from python_graphs import control_flow
graph = control_flow.get_control_flow_graph(fn)

Generate a program graph from a function fn:

from python_graphs import program_graph
graph = program_graph.get_program_graph(fn)

Compute the cyclomatic complexity of a function fn:

from python_graphs import control_flow
from python_graphs import cyclomatic_complexity
graph = control_flow.get_control_flow_graph(fn)
value = cyclomatic_complexity.cyclomatic_complexity(graph)

This is not an officially supported Google product.

Comments
  • Can you provide a quick start example?

    Can you provide a quick start example?

    Super cool project! Love the idea and think it has a lot of potential.

    it would be awesome to have an examples/ directory containing some sample usages - maybe even just plotting the graphs with networkX and matplotlib.

    question 
    opened by LukeWood 5
  • How do we solve the error when installing python-graphs?

    How do we solve the error when installing python-graphs?

    Hello,

    I encountered an error "fatal error: 'graphviz/cgraph.h' file not found" when trying to install python_graphs. How do I solve this issue, please? Thanks.

    question 
    opened by fraolBatole 2
  • How to generate a Holistic Data Flow Graph for a given Function ?

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

    @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.

    opened by reshinthadithyan 2
  • Rename fn to get_test_components to eliminate extra test from logs

    Rename fn to get_test_components to eliminate extra test from logs

    The function test_components was being registered as an unsupported test, when in reality it was meant as a helper function for tests. Renaming resolves this.

    opened by dbieber 0
  • get_start_control_flow_node, next_from_end, raise edges, and labels in branches

    get_start_control_flow_node, next_from_end, raise edges, and labels in branches

    • Adds get_start_control_flow_node to ControlFlowGraph
    • Adds next_from_end to ControlFlowNode
    • Uses labels (e.g. '' and '' strings) to indicate these special nodes
    • Support keyword only arguments without defaults
    • Add non-interrupting edges from raise statements
    • Bump version number
    opened by dbieber 0
  • Separate branch kinds

    Separate branch kinds

    Splits "branches" into branches, except_branches, and reraise_branches.

    branches are you're usual branch decisions: ifs, fors, and whiles. except_branches are at "except E:" statements, with True indicating the exception matches and False indicating it does not reraise_branches are at the end of "finally:" blocks, with True indicating the path taken after finally if an error has been raised previously, and False indicating the path taken if there's nothing to reraise at the end of the finally.

    opened by dbieber 0
  • Add module frame to catch raises in top-level code.

    Add module frame to catch raises in top-level code.

    Add module frame to catch raises in top-level code. Also marks except expressions and finally blocks as branch points.

    An "except A:"'s branch decision is whether the current exception matches A. At the end of a finally block, the branch decision is whether an exception is currently being raised.

    This includes https://github.com/google-research/python-graphs/pull/3: Splits "branches" into branches, except_branches, and reraise_branches.

    branches are your usual branch decisions: ifs, fors, and whiles. except_branches are at "except E:" statements, with True indicating the exception matches and False indicating it does not reraise_branches are at the end of "finally:" blocks, with True indicating the path taken after finally if an error has been raised previously, and False indicating the path taken if there's nothing to reraise at the end of the finally.

    opened by dbieber 0
  • KeyError when trying to get program_graph

    KeyError when trying to get program_graph

    When I try to create a program graph, I encounter a KeyError. If I remove all the and and or expressions from the python file (buggy.py) the error does not occur.

    This is how I use the library:

    graph = program_graph.get_program_graph(code)
    program_graph_graphviz.render(graph, path='source.png')
    

    where code is simply the code in the attached file buggy.py.txt.

    I have also attached the log file log.txt.

    buggy.py.txt

    log.txt

    More information: python 3.9.5 commit head=44c15b92197f374c3550353ff827997ef1c1d857 gast 0.5.3

    opened by ppashakhanloo 1
Releases(v1.2.3)
  • v1.2.3(Oct 7, 2021)

    get_start_control_flow_node, next_from_end, raise edges, and labels in branches (#6)

    * Adds get_start_control_flow_node to ControlFlowGraph
    * Adds next_from_end to ControlFlowNode
    * Uses labels (e.g. '<exit>' and '<raise>' strings) to indicate these special nodes
    * Support keyword only arguments without defaults
    * Add non-interrupting edges from raise statements
    * Bump version number
    
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Oct 5, 2021)

    Introduce get_branches API on control flow nodes. Previously the new branch types (except_branches and reraise_branches) were only accessible on basic blocks, not on individual nodes.

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Oct 5, 2021)

    1. Adds a module frame to catch raises in top-level code.
    2. Also marks except expressions and finally blocks as branch points.

    The branch kinds are: branches, except_branches, and reraise_branches.

    • branches are your usual branch decisions: ifs, fors, and whiles.
    • except_branches are at "except E:" statements, with True indicating the exception matches and False indicating it does not
    • reraise_branches are at the end of "finally:" blocks, with True indicating the path taken after finally if an error has been raised previously, and False indicating the path taken if there's nothing to reraise at the end of the finally.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(May 7, 2021)

  • v1.0.0(Apr 12, 2021)

    v1.0.0

    Initial public release of the python_graphs library.

    Core features:

    • control flow graph generation
    • data flow analyses
    • program graph construction
    • cyclomatic complexity calculation
    • a solid test suite for all the above
    • visualizations using graphviz for each of the graph representations
    Source code(tar.gz)
    Source code(zip)
Owner
Google Research
Google Research
KAPAO is an efficient multi-person human pose estimation model that detects keypoints and poses as objects and fuses the detections to predict human poses.

KAPAO (Keypoints and Poses as Objects) KAPAO is an efficient single-stage multi-person human pose estimation model that models keypoints and poses as

Will McNally 664 Dec 30, 2022
一套完整的微博舆情分析流程代码,包括微博爬虫、LDA主题分析和情感分析。

已经将项目的关键文件上传,包含微博爬虫、LDA主题分析和情感分析三个部分。 1.微博爬虫 实现微博评论爬取和微博用户信息爬取,一天大概十万条。 2.LDA主题分析 实现文档主题抽取,包括数据清洗及分词、主题数的确定(主题一致性和困惑度)和最优主题模型的选择(暴力搜索)。 3.情感分析 实现评论文本的

182 Jan 02, 2023
Joint project of the duo Hacker Ninjas

Project Smoothie Společný projekt dua Hacker Ninjas. První pokus o hříčku po třech týdnech učení se programování. Jakub Kolář e:\

Jakub Kolář 2 Jan 07, 2022
We utilize deep reinforcement learning to obtain favorable trajectories for visual-inertial system calibration.

Unified Data Collection for Visual-Inertial Calibration via Deep Reinforcement Learning Update: The lastest code will be updated in this branch. Pleas

ETHZ ASL 27 Dec 29, 2022
PyTorch implementation of MoCo: Momentum Contrast for Unsupervised Visual Representation Learning

MoCo: Momentum Contrast for Unsupervised Visual Representation Learning This is a PyTorch implementation of the MoCo paper: @Article{he2019moco, aut

Meta Research 3.7k Jan 02, 2023
Most popular metrics used to evaluate object detection algorithms.

Most popular metrics used to evaluate object detection algorithms.

Rafael Padilla 4.4k Dec 25, 2022
Definition of a business problem according to Wilson Lower Bound Score and Time Based Average Rating

Wilson Lower Bound Score, Time Based Rating Average In this study I tried to calculate the product rating and sorting reviews more accurately. I have

3 Sep 30, 2021
Full Resolution Residual Networks for Semantic Image Segmentation

Full-Resolution Residual Networks (FRRN) This repository contains code to train and qualitatively evaluate Full-Resolution Residual Networks (FRRNs) a

Toby Pohlen 274 Oct 27, 2022
VL-LTR: Learning Class-wise Visual-Linguistic Representation for Long-Tailed Visual Recognition

VL-LTR: Learning Class-wise Visual-Linguistic Representation for Long-Tailed Visual Recognition Usage First, install PyTorch 1.7.1+, torchvision 0.8.2

40 Dec 12, 2022
This is a repository of our model for weakly-supervised video dense anticipation.

Introduction This is a repository of our model for weakly-supervised video dense anticipation. More results on GTEA, Epic-Kitchens etc. will come soon

2 Apr 09, 2022
Simulated garment dataset for virtual try-on

Simulated garment dataset for virtual try-on This repository contains the dataset used in the following papers: Self-Supervised Collision Handling via

33 Dec 20, 2022
[ICCV 2021 Oral] Deep Evidential Action Recognition

DEAR (Deep Evidential Action Recognition) Project | Paper & Supp Wentao Bao, Qi Yu, Yu Kong International Conference on Computer Vision (ICCV Oral), 2

Wentao Bao 80 Jan 03, 2023
CIFAR-10_train-test - training and testing codes for dataset CIFAR-10

CIFAR-10_train-test - training and testing codes for dataset CIFAR-10

Frederick Wang 3 Apr 26, 2022
Coursera - Quiz & Assignment of Coursera

Coursera Assignments This repository is aimed to help Coursera learners who have difficulties in their learning process. The quiz and programming home

浅梦 828 Jan 04, 2023
Attention-guided gan for synthesizing IR images

SI-AGAN Attention-guided gan for synthesizing IR images This repository contains the Tensorflow code for "Pedestrian Gender Recognition by Style Trans

1 Oct 25, 2021
OneShot Learning-based hotword detection.

EfficientWord-Net Hotword detection based on one-shot learning Home assistants require special phrases called hotwords to get activated (eg:"ok google

ANT-BRaiN 102 Dec 25, 2022
This is an example of object detection on Micro bacterium tuberculosis using Mask-RCNN

Mask-RCNN on Mycobacterium tuberculosis This is an example of object detection on Mycobacterium Tuberculosis using Mask RCNN. Implement of Mask R-CNN

Jun-En Ding 1 Sep 16, 2021
Implements Stacked-RNN in numpy and torch with manual forward and backward functions

Recurrent Neural Networks Implements simple recurrent network and a stacked recurrent network in numpy and torch respectively. Both flavours implement

Vishal R 1 Nov 16, 2021
ERISHA is a mulitilingual multispeaker expressive speech synthesis framework. It can transfer the expressivity to the speaker's voice for which no expressive speech corpus is available.

ERISHA: Multilingual Multispeaker Expressive Text-to-Speech Library ERISHA is a multilingual multispeaker expressive speech synthesis framework. It ca

Ajinkya Kulkarni 43 Nov 27, 2022
SuMa++: Efficient LiDAR-based Semantic SLAM (Chen et al IROS 2019)

SuMa++: Efficient LiDAR-based Semantic SLAM This repository contains the implementation of SuMa++, which generates semantic maps only using three-dime

Photogrammetry & Robotics Bonn 701 Dec 30, 2022