- Prerequisites
- Downloading AlphaRepair's Replication Package
- Installing Defects4J
- Creating Python Environment
- Running AlphaRepair
- Attribution
- License
- Contact Information
Before you begin, ensure you have met the following requirements:
- Operating System: The setup has been tested on Ubuntu 22.04.4 LTS.
- Anaconda: For creating and managing the Python environment.
- Git: For cloning the Defects4J repository.
AlphaRepair's replication package
is on Zenodo. I have already downloaded Version 2 and
included it in this repository. To do so, I downloaded code.zip
and
extracted its content into the root directory.
The correct_patches.zip
file is not needed for this setup.
AlphaRepair is a dynamic analysis tool written in Python. It needs Defects4J to run tests and to validate patches. So, you need to install Defects4J on your machine. AlphaRepair's replication package is developed to work with Defects4J versions 1.2 and 2.0. I recommend using version 1.2 as the current replication package of AlphaRepair includes fault localization information only for subjects in Defects4J version 1.2 (see the location directory).
To install Defects4J 1.2 on your machine, follow the instructions provided here. Do not forget to checkout the correct repository version after cloning:
git clone [email protected]:rjust/defects4j.git
cd defects4j
git checkout tags/v1.2.0
Also, make sure to add Defects4J's executables to your PATH as described in step 3 of Defects4J's installation process:
- Add Defects4J's executables to your PATH:
export PATH=$PATH:"path2defects4j"/framework/bin
AlphaRepair is a Python project. However, its replication
package does not include information about
its dependencies.
So I added the requirements.txt file,
which contains the requirements for running AlphaRepair on CPU (not GPU).
I have only tested it on CPU. If you have GPU, let me know
so that I can prepare another requirements.txt
that supports
GPU
(more information on installing the Transformers library).
- Create a conda environment. I tested everything using Python 3.11, but other Python versions should also work.
conda create -n alpharepair3.11 python=3.11
- Activate the environment we just created:
conda activate alpharepair3.11
- Install AlphaRepair's dependencies:
python -m pip install -r requirements.txt
Due to a bug in AlphaRepair, you must create a directory named codebert_result
in the root directory to prevent AlphaRepair from crashing.
I have already added this directory to the root for your convenience.
AlphaRepair supports the following command line arguments:
-
--bug_id: Defects4J bug id. For instance,
Lang-1
refers to bug #1 from the Lang project. To see the list of supported bug ids for perfect fault localization, see directory location/groundtruth. For bug ids supported for Ochiai-based fault localization, see directory location/ochiai. -
--uniapr: Indicates whether to use uniapr. According to the paper, using uniapr speeds up patch validation. If it does not work, simply do not use it.
-
--output_folder: The directory to store the patches. The default is
codebert_result
. Because of the bug and workaround mentioned above, use the default by not setting this parameter. -
--skip_v: Indicates whether to skip patch validation. Do not set it.
-
--re_rank:: Indicates whether to re-rank patches produced by the beam search. Set it.
-
--beam_width: Determines the size of the beam search. In the paper, it is set to 25.
-
--perfect: Indicates whether to use perfect fault localization or Ochiai. Set it.
-
--top_n_patches: Indicates the number of candidate patches to return. Set it to -1 to return all patches.
For example, to run AlphaRepair on bug Lang-1, use the following command:
python experiment.py --bug_id Lang-1 --re_rank --beam_width 25 --perfect --top_n_patches -1
The original authors of AlphaRepair are Chunqiu Steven Xia and Lingming Zhang. The tool was presented in the paper "Less training, more repairing please: revisiting automated program repair via zero-shot learning" at ESEC/FSE 2022.
The source code and related materials are available on Zenodo.
This repository is a replication package of their work. I have added additional documentation to make it easier for users to use the tool.
The original work is licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0) license. You can find the full license text in the LICENSE file in this repository.
If you have any questions or need further assistance, you can reach me at:
- Email: [email protected]
- GitHub Issues: Create an issue