This document explains how to run the code compilation test feature, which is used to verify whether the generated code can successfully compile.
The compilation test feature requires the corresponding compiler for each programming language. Depending on the language you want to test, you need to install the required tools. Please refer to the setup.txt file for details.
Install all dependencies:
pip install -r requirements.txtEnsure the required Python package is installed:
pip install guesslangcd /workspace
python src/evaluation/run_compilation_test.py \
--output_dir results/single_level \
--prompt_dir dataset/instructions/single_level \
--detail_dir results/compilation_details \
--save_path results/compilation_results.json-
--output_dir: Directory of model output files (e.g.,results/single_level)- This directory should contain subdirectories named after each model
-
--prompt_dir: Directory of prompt files (e.g.,dataset/instructions/single_level)- Contains JSON files with the original prompts
-
--detail_dir: Directory for saving detailed results- Detailed compilation test results are stored here
- Directory structure:
detail_dir/model_name/constraint_name_compilation.json
-
--save_path: Path to save the aggregated results (optional)- If specified, statistics for all models will be saved into a single JSON file
-
--model: Name of the model to test (optional)- If specified, only this model will be tested, e.g.,
--model deepseek-r1
- If specified, only this model will be tested, e.g.,
python src/evaluation/run_compilation_test.py \
--output_dir results/single_level \
--prompt_dir dataset/instructions/single_level \
--detail_dir results/compilation_details \
--save_path results/compilation_results.jsonpython src/evaluation/run_compilation_test.py \
--output_dir results/single_level \
--prompt_dir dataset/instructions/single_level \
--detail_dir results/compilation_details \
--model deepseek-r1 \
--save_path results/compilation_deepseek-r1.jsonIf you want to test the results/multi_level or results/self_repair directories:
# Test multi_level
python src/evaluation/run_compilation_test.py \
--output_dir results/multi_level \
--prompt_dir dataset/instructions/multi_level \
--detail_dir results/compilation_details/multi_level \
--save_path results/compilation_multi_level.json
# Test self_repair
python src/evaluation/run_compilation_test.py \
--output_dir results/self_repair \
--prompt_dir dataset/instructions/single_level \
--detail_dir results/compilation_details/self_repair \
--save_path results/compilation_self_repair.jsonDetailed results for each constraint are saved in
detail_dir/model_name/constraint_name_compilation.json with the following format:
[
{
"id": 0,
"category": "syntax",
"constraint": "language_type",
"prompt": "...",
"answer": "python",
"generated_code": "def hello():\n print('Hello')\n",
"is_matched": true,
"error_message": ""
},
{
"id": 1,
"category": "syntax",
"constraint": "language_type",
"prompt": "...",
"answer": "python",
"generated_code": "def hello(\n print('Hello')\n",
"is_matched": false,
"error_message": "SyntaxError: invalid syntax"
}
]If --save_path is specified, an aggregated statistics file will be generated with the following format:
{
"model_name": {
"constraint_name": {
"total": 100,
"matched": 85,
"score": 0.85
},
"overall": {
"total": 500,
"matched": 425,
"score": 0.85
}
}
}- Compiler Installation: Make sure the appropriate compiler is installed for the language being tested
- File Paths: Ensure that
output_dirandprompt_dirpaths are correct - Permissions: Make sure you have write permissions for
detail_dirandsave_path - Time Limit: Each compilation test has a timeout limit of 10 seconds
- Temporary Files: Compilation tests create temporary files, which are automatically cleaned up after testing
Solution:
- Ensure the required compiler is installed
- Ensure the compiler is available in the system PATH
- Use
which compiler_nameto check the compiler location
Solution:
- Ensure the
guesslangpackage is installed:pip install guesslang - Or ensure the
answerfield in the prompt files contains language type information
Solution:
- The code may be too complex
- Check the
error_messagefield in the detailed result files - The default timeout is 10 seconds and can be adjusted in the code
Solution:
- Check whether the
prompt_dirpath is correct - Check whether the file name format matches
- File names should match the constraint name (e.g.,
syntax_language_type.json)
Complete usage example:
# 1. Ensure the environment is properly configured
python3 --version # Python
javac -version # Java (if testing Java code)
node --version # JavaScript (if testing JS code)
# 2. Install Python dependencies
pip install guesslang
# 3. Run the compilation test
python src/evaluation/run_compilation_test.py \
--output_dir results/single_level \
--prompt_dir dataset/instructions/single_level \
--detail_dir results/compilation_details \
--save_path results/compilation_results.json
# 4. View the results
cat results/compilation_results.json- Compilation Test Module:
src/evaluation/compile_test.py - Execution Script:
src/evaluation/run_compilation_test.py