Skip to content

Repository files navigation


A Micro-benchmarking Framework for Python Type Inference Tools

📌 Features:

  • 📜 Contains 154 code snippets to test and benchmark.
  • 🏷 Offers 845 type annotations across a diverse set of Python functionalities.
  • 📂 Organized into 18 distinct categories targeting various Python features.
  • 🚢 Seamlessly manages the execution of containerized tools.
  • 🔄 Efficiently transforms inferred types into a standardized format.
  • 📊 Automatically produces meaningful metrics for in-depth assessment and comparison.

[New] TypeEvalPy Autogen

  • 🤖 Autogenerates code snippets and ground truth to scale the benchmark based on the original TypeEvalPy benchmark.
  • 📈 The autogen benchmark now contains:
    • Python files: 7121
    • Type annotations: 78373

🛠️ Supported Tools

Supported ✅In-progress 🔧Planned 💡
HeaderGenIntellij PSIMonkeyType
JediPyrePyannotate
PyrightPySonar2
HiTyperPytype
ScalpelTypeT5
Type4Py
GPT
Ollama
RightTyper

🏆 TypeEvalPy Leaderboard

Below is a comparison showcasing exact matches across different tools and LLMs on the Autogen benchmark.

Rank🛠️ ToolFunction Return TypeFunction Parameter TypeLocal Variable TypeTotal
1mistral-large-it-2407-123b167017285755074979
2qwen2-it-72b164886295516072277
3llama3.1-it-70b166485805444571673
4gemma2-it-27b163425994977266713
5codestral-v0.1-22b164567064937966541
6codellama-it-34b159604734895765390
7mistral-nemo-it-2407-12.2b162215264843965186
8mistral-v0.3-it-7b166864724793565093
9phi3-medium-it-14b168024674512162390
10llama3.1-it-8b161254924431360930
11codellama-it-13b162144794302159714
12phi3-small-it-7.3b161554223809354670
13qwen2-it-7b156843133810954106
14HeaderGen140863463637050802
15phi3-mini-it-3.8b159083203034146569
16phi3.5-mini-it-3.8b157633622869444819
17codellama-it-7b137793182934643443
18Jedi1316001540328563
19Scalpel153831711815572
20gemma2-it-9b16116654647141
21Type4Py31433822435424
22tinyllama-1.1b15142826994241
23mixtral-v0.1-it-8x7b3235333773645
24phi3.5-moe-it-41.9b3090252733388
25gemma2-it-2b14974118483386

(Auto-generated based on the the analysis run on 30 Aug 2024)


🐳 Running with Docker

1️⃣ Clone the repo

git clone https://github.com/secure-software-engineering/TypeEvalPy.git

2️⃣ Build Docker image

docker build -t typeevalpy .

3️⃣ Run TypeEvalPy

🕒 Takes about 30mins on first run to build Docker containers.

📂 Results will be generated in the results folder within the root directory of the repository. Each results folder will have a timestamp, allowing you to easily track and compare different runs.

Correlation of CSV Files Generated to Tables in ICSE Paper Here is how the auto-generated CSV tables relate to the paper's tables:
  • Table 1 in the paper is derived from three auto-generated CSV tables:

    • paper_table_1.csv - details Exact matches by type category.
    • paper_table_2.csv - lists Exact matches for 18 micro-benchmark categories.
    • paper_table_3.csv - provides Sound and Complete values for tools.
  • Table 2 in the paper is based on the following CSV table:

    • paper_table_5.csv - shows Exact matches with top_n values for machine learning tools.

Additionally, there are CSV tables that are not included in the paper:

  • paper_table_4.csv - containing Sound and Complete values for 18 micro-benchmark categories.
  • paper_table_6.csv - featuring Sensitivity analysis.
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ./results:/app/results \
typeevalpy

🔧 Optionally, run analysis on specific tools:

docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ./results:/app/results \
typeevalpy --runners headergen scalpel

📊 Run analysis on custom benchmarks:

Here, running with the autogen benchmark on HeaderGen

docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ./results:/app/results \
typeevalpy \
--runners headergen \
--custom_benchmark_dir /app/autogen_typeevalpy_benchmark

🛠️ Available options: headergen, pyright, scalpel, jedi, hityper, type4py, hityperdl

🤖 Running TypeEvalPy with LLMs

TypeEvalPy integrates with LLMs through Ollama, streamlining their management. Begin by setting up your environment:

  • Create Configuration File: Copy the config_template.yaml from the src directory and rename it to config.yaml.

In the config.yaml, configure in the following:

  • openai_key: your key for accessing OpenAI's models.
  • ollama_url: the URL for your Ollama instance. For simplicity, we recommend deploying Ollama using their Docker container. Get started with Ollama here.
  • prompt_id: set this to questions_based_2 for optimal performance, based on our tests.
  • ollama_models: select a list of model tags from the Ollama library. For better operation, ensure the model is pre-downloaded with the ollama pull command.

With the config.yaml configured, run the following command:

docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ./results:/app/results \
typeevalpy --runners ollama

Running From Source...

1. 📥 Installation

  1. Clone the repo

    git clone https://github.com/secure-software-engineering/TypeEvalPy.git
  2. Install Dependencies and Set Up Virtual Environment

    Run the following commands to set up your virtual environment and activate the virtual environment.

    python3 -m venv .env
    source .env/bin/activate
    pip install -r requirements.txt

2. 🚀 Usage: Running the Analysis

  1. Navigate to the src Directory

    cd src
  2. Execute the Analyzer

    Run the following command to start the benchmarking process on all tools:

    python main_runner.py

    or

    Run analysis on specific tools

    python main_runner.py --runners headergen scalpel
    

Running TypeEvalPy Autogen

To generate an extended version of the original TypeEvalPy benchmark to include many more Python types, run the following commands:

  1. Navigate to the autogen Directory

    cd autogen
  2. Execute the Generation Script

    Run the following command to start the generation process:

    python generate_typeevalpy_dataset.py

This will generate a folder in the repo root with the autogen benchmark with the current date.


Running TypeEvalPy with ManyType4Py dataset

To run the LLM based Type Inference for ManyType4Py dataset, please follow the guide here : src/target_tools/real-world-llms/README.md


🤝 Contributing

Thank you for your interest in contributing! To add support for a new tool, please utilize the Docker templates provided in our repository. After implementing and testing your tool, please submit a pull request (PR) with a descriptive message. Our maintainers will review your submission, and merge them.

To get started with integrating your tool, please follow the guide here: docs/Tool_Integration_Guide.md


⭐️ Show Your Support

Give a ⭐️ if this project helped you!

About

A Micro-benchmarking Framework for Python Type Inference Tools

Topics

Resources

Stars

37 stars

Watchers

4 watching

Forks

Used by

Contributors

Languages