_swe_env_setup.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # THIS SCRIPT ONLY NEED TO BE RUN ONCE BEFORE EVALUATION
  3. set -e
  4. function setup_environment_and_testbed {
  5. local instance_file_name=$1
  6. # throw error if user name is not opendevin
  7. if [ "$USER" != "opendevin" ]; then
  8. echo "Error: This script is intended to be run by the 'opendevin' user only." >&2
  9. exit 1
  10. fi
  11. # =======================================================
  12. # Install & Setup Conda
  13. # assume /swe_util/miniforge3 already exists
  14. # install if swe-util does NOT have conda
  15. if [ ! -d /swe_util/miniforge3 ]; then
  16. pushd /swe_util
  17. echo "Downloading and installing Miniforge3"
  18. wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
  19. bash Miniforge3-$(uname)-$(uname -m).sh -b -p /swe_util/miniforge3
  20. fi
  21. echo 'export PATH=/swe_util/miniforge3/bin:$PATH' >> ~/.bashrc
  22. eval "$(/swe_util/miniforge3/bin/conda shell.bash hook)"
  23. conda init bash
  24. source ~/.bashrc
  25. conda config --set changeps1 False
  26. conda config --append channels conda-forge
  27. # =======================================================
  28. # Install swe-bench-eval environment if it does not exist
  29. ENV_EXISTS=$(conda info --envs | awk '/swe-bench-eval/ {print $1}')
  30. echo "ENV_EXISTS: $ENV_EXISTS"
  31. if [ -z "$ENV_EXISTS" ]; then
  32. echo "Environment swe-bench-eval does not exist. Creating the environment."
  33. conda create -n swe-bench-eval python==3.11.5 -y
  34. conda activate swe-bench-eval
  35. pip install requests python-dotenv GitPython datasets pandas beautifulsoup4 ghapi
  36. fi
  37. conda activate swe-bench-eval
  38. echo 'swe-bench-eval environment is ready.'
  39. # =======================================================
  40. # Read the swe-bench-test-lite.json / swe-bench-test.json file and extract the required item based on instance_id
  41. INSTANCE_DATA_FILE=/swe_util/eval_data/instances/$instance_file_name
  42. echo "Instance data file loaded: $INSTANCE_DATA_FILE"
  43. # =======================================================
  44. # generate testbed & conda environment for ALL instances in the test file
  45. echo "Generating testbed & conda environment for all instances in the test file"
  46. export PYTHONPATH=/swe_util/OD-SWE-bench:$PYTHONPATH
  47. python3 /swe_util/OD-SWE-bench/swebench/harness/engine_testbed.py \
  48. --instances_path $INSTANCE_DATA_FILE \
  49. --log_dir /swe_util/eval_data/testbed_logs \
  50. --conda_path /swe_util/miniforge3 \
  51. --testbed /swe_util/eval_data/testbeds \
  52. --timeout 1000
  53. # Check every log in /swe_util/eval_data/testbed_logs to see if they contains "Init Succeeded"
  54. # If not, print the log file name and exit
  55. for log_file in /swe_util/eval_data/testbed_logs/*; do
  56. if ! grep -q "Init Succeeded" $log_file; then
  57. echo "Error: $log_file does not contain 'Init Succeeded'"
  58. exit 1
  59. fi
  60. done
  61. echo "All logs contain 'Init Succeeded'. Testbed & conda environment setup is successful."
  62. }
  63. # check if $1 is either swe-bench-test-lite.json or swe-bench-test.json
  64. if [ "$1" != "swe-bench-test-lite.json" ] && [ "$1" != "swe-bench-test.json" ]; then
  65. echo "Error: Invalid input file name. Please provide either swe-bench-test-lite.json or swe-bench-test.json"
  66. exit 1
  67. fi
  68. # call the function
  69. echo "Calling setup_environment_and_testbed with $1"
  70. setup_environment_and_testbed $1