Skip to content

pkuzqh/Recoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recoder

A PyTorch Implementation of "A Syntax-Guided Edits Decoder for Neural Program Repair"

Introduction

Automated Program Repair (APR) helps improve the efficiency of software development and maintenance. Recent APR techniques use deep learning, particularly the encoder-decoder architecture, to generate patches. Though existing DL-based APR approaches have proposed different encoder architectures, the decoder remains to be the standard one, which generates a sequence of tokens one by one to replace the faulty statement. This decoder has multiple limitations: 1) allowing to generate syntactically incorrect programs, 2) inefficiently representing small edits, and 3) not being able to generate project-specific identifiers.

In this paper, we propose Recoder, a syntax-guided edit decoder with placeholder generation. Recoder is novel in multiple aspects: 1) Recoder generates edits rather than modified code, allowing efficient representation of small edits; 2) Recoder is syntax-guided, with the novel provider/decider architecture to ensure the syntactic correctness of the patched program and accurate generation; 3) Recoder generates placeholders that could be instantiated as project-specific identifiers later.

We conduct experiments to evaluate Recoder on 395 bugs from Defects4J v1.2 and 420 additional bugs from Defects4J v2.0. Our results show that Recoder repairs 53 bugs on Defects4J v1.2, which achieves 26.2% improvement over the previous state-of-the-art approach for single-hunk bugs (TBar). Importantly, to our knowledge, Recoder is the first DL-based APR approach that has outperformed the traditional APR approaches on this dataset. Furthermore, Recoder also repairs 19 bugs on the additional bugs from Defects4J v2.0, which is 137.5% more than TBar (8 bugs) and 850% more than SimFix (2 bugs). This result suggests that Recoder has better generalizability than existing APR approaches.

image

The Main File Tree of Recoder

.
├── Result
│   └── out
├── Picture
│   ├── Insert.png
│   ├── Modify.png
│   └── overviewmodel.png.Jpeg
├── Attention.py
├── Dataset.py
├── run.py
├── testDefect4j.py
├── totalrepair.py
└── Model.py

To Run Recoder via Docker

  • To run the docker, you need first install docker in your machine.
    sudo apt install docker
    
  • To use GPUs, you need to install CUDA v10.2 in your machine.
    1. Download the corresponding CUDA file in Nvidia.
    2. Install CUDA
    bash cuda.sh(name of the CUDA file)
    
  • To use GPUs in docker, you also need to install nvidia-docker.(We take Ubuntu as example, more details can be found in nvidia-docker)
    # Add the package repositories
    distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
    curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
    curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
    
    sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
    sudo systemctl restart docker
    sudo apt-get install nvidia-container-runtime
    sudo systemctl restart docker
    
  • Pull the docker We provider two docker files to run Recoder.
    • To use Recoder to repair defects with pre-trained model
      sudo docker pull zqh111/recoder:interface 
      
    • To train Recoder
      sudo docker pull zqh111/recoder:training 
      
  • Start the docker
    • Inference
    docker run -it --gpus all --shm-size="1g" zqh111/recoder:interface /bin/bash
    cd /root/Repair/
    
    • Training
    docker run -it --gpus all --shm-size="1g" zqh111/recoder:training /bin/bash
    cd /root/Repair/
    

Training Set

The data is included in the docker.

The raw data https://drive.google.com/drive/folders/1ECNX98qj9FMdRT2MXOUY6aQ6-sNT0b_a?usp=sharing .

Train a New Model

CUDA_VISIBLE_DEVICES=0,1 python3 run.py train

The saved model is checkpointSearch/best_model.ckpt.

After our model was trained, we can

Generate Patches for Defects4J v1.2 with Ochiai by

CUDA_VISIBLE_DEVICES=0 python3 testDefect4j.py bugid

The generated patches are in folder patch/ in json.

Generate Patches for Defects4J v2.0 by

CUDA_VISIBLE_DEVICES=0 python3 testDefect4jv21.py bugid

The generated patches are in folder patch/ in json.

We further test the generated patches based on the test cases by

Validate Patches

python3 repair.py bugid

The results are in folder patches/ in json.

Generate Patches for Quixbugs

Replace 'testDefect4j.py' with 'testQuixbug.py' and modify the corresponding file path, then run

python3 testQuixbug.py

Validate Patches Parallelly

python3 totalrepair.py

you need to change the corresponding bug IDs in this file.

Two Examples of Edits

Gnerated Patches

The generated patches are in the folder Result/.

Dependency

  • Python 3.7
  • PyTorch 1.3
  • Defects4J
  • Java 8
  • docker
  • nvidia-docker

Online Demo

A demo to show Recoder.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages