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
tensorrt int8 量化yolov5 4.0 onnx模型

onnx模型转换为 int8 tensorrt引擎

123 Dec 28, 2022
PPO is a very popular Reinforcement Learning algorithm at present.

PPO is a very popular Reinforcement Learning algorithm at present. OpenAI takes PPO as the current baseline algorithm. We use the PPO algorithm to train a policy to give the best action in any situat

Rosefintech 11 Aug 23, 2021
A Domain-Agnostic Benchmark for Self-Supervised Learning

DABS: A Domain Agnostic Benchmark for Self-Supervised Learning This repository contains the code for DABS, a benchmark for domain-agnostic self-superv

Alex Tamkin 81 Dec 09, 2022
Simultaneous Detection and Segmentation

Simultaneous Detection and Segmentation This is code for the ECCV Paper: Simultaneous Detection and Segmentation Bharath Hariharan, Pablo Arbelaez,

Bharath Hariharan 96 Jul 20, 2022
A code implementation of AC-GC: Activation Compression with Guaranteed Convergence, in NeurIPS 2021.

Code For AC-GC: Lossy Activation Compression with Guaranteed Convergence This code is intended to be used as a supplemental material for submission to

Dave Evans 2 Nov 01, 2022
SIEM Logstash parsing for more than hundred technologies

LogIndexer Pipeline Logstash Parsing Configurations for Elastisearch SIEM and OpenDistro for Elasticsearch SIEM Why this project exists The overhead o

146 Dec 29, 2022
An open source machine learning library for performing regression tasks using RVM technique.

Introduction neonrvm is an open source machine learning library for performing regression tasks using RVM technique. It is written in C programming la

Siavash Eliasi 33 May 31, 2022
Library for machine learning stacking generalization.

stacked_generalization Implemented machine learning *stacking technic[1]* as handy library in Python. Feature weighted linear stacking is also availab

114 Jul 19, 2022
An implementation of the AdaOPS (Adaptive Online Packing-based Search), which is an online POMDP Solver used to solve problems defined with the POMDPs.jl generative interface.

AdaOPS An implementation of the AdaOPS (Adaptive Online Packing-guided Search), which is an online POMDP Solver used to solve problems defined with th

9 Oct 05, 2022
Facial recognition project

Facial recognition project documentation Project introduction This project is developed by linuxu. It is a face model recognition project developed ba

Jefferson 2 Dec 04, 2022
FocusFace: Multi-task Contrastive Learning for Masked Face Recognition

FocusFace This is the official repository of "FocusFace: Multi-task Contrastive Learning for Masked Face Recognition" accepted at IEEE International C

Pedro Neto 21 Nov 17, 2022
Identifying Stroke Indicators Using Rough Sets

Identifying Stroke Indicators Using Rough Sets With the spirit of reproducible research, this repository contains all the codes required to produce th

Muhammad Salman Pathan 0 Jun 09, 2022
Civsim is a basic civilisation simulation and modelling system built in Python 3.8.

Civsim Introduction Civsim is a basic civilisation simulation and modelling system built in Python 3.8. It requires the following packages: perlin_noi

17 Aug 08, 2022
Implementation for Panoptic-PolarNet (CVPR 2021)

Panoptic-PolarNet This is the official implementation of Panoptic-PolarNet. [ArXiv paper] Introduction Panoptic-PolarNet is a fast and robust LiDAR po

Zixiang Zhou 126 Jan 01, 2023
Location-Sensitive Visual Recognition with Cross-IOU Loss

The trained models are temporarily unavailable, but you can train the code using reasonable computational resource. Location-Sensitive Visual Recognit

Kaiwen Duan 146 Dec 25, 2022
Video Swin Transformer - PyTorch

Video-Swin-Transformer-Pytorch This repo is a simple usage of the official implementation "Video Swin Transformer". Introduction Video Swin Transforme

Haofan Wang 116 Dec 20, 2022
Towards the D-Optimal Online Experiment Design for Recommender Selection (KDD 2021)

Towards the D-Optimal Online Experiment Design for Recommender Selection (KDD 2021) Contact 0 Jan 11, 2022

Pure python implementations of popular ML algorithms.

Minimal ML algorithms This repo includes minimal implementations of popular ML algorithms using pure python and numpy. The purpose of these notebooks

Alexis Gidiotis 3 Jan 10, 2022
FEMDA: Robust classification with Flexible Discriminant Analysis in heterogeneous data

FEMDA: Robust classification with Flexible Discriminant Analysis in heterogeneous data. Flexible EM-Inspired Discriminant Analysis is a robust supervised classification algorithm that performs well i

0 Sep 06, 2022
TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)

TensorFlow Examples This tutorial was designed for easily diving into TensorFlow, through examples. For readability, it includes both notebooks and so

Aymeric Damien 42.5k Jan 08, 2023