diff --git a/script/make_utils/run_use_case_examples.sh b/script/make_utils/run_use_case_examples.sh index 11a9a2fa73..7b99d8d200 100755 --- a/script/make_utils/run_use_case_examples.sh +++ b/script/make_utils/run_use_case_examples.sh @@ -7,15 +7,14 @@ use_case_dir="${current_dir}/${use_case_dir_name}" check_directory_exists() { if [ ! -d "$1" ]; then - echo "Error: '$use_case_dir_name' directory must be present in the Concrete ML source root." + echo "Error: Directory '${1}' not found." exit 1 fi } check_clean_git_status() { if git ls-files --others --exclude-standard | grep -q "$1"; then - echo "Error: This script must be run in a clean clone of the Concrete ML repo." - echo "Untracked files detected in $1." + echo "Error: The repository is not clean. Untracked files found in $1." echo "List untracked files with: git ls-files --others --exclude-standard | grep $1" echo "Remove untracked files with: git clean -fdx $1" exit 1 @@ -24,23 +23,30 @@ check_clean_git_status() { setup_virtualenv() { local venv_path="/tmp/virtualenv_$1" - echo "Setting up virtual environment for $1..." - rm -rf "$venv_path" # Ensure a clean environment + echo "Setting up virtual environment in $venv_path..." python3 -m venv "$venv_path" source "${venv_path}/bin/activate" - echo "Virtual environment created at $venv_path." + echo "Virtual environment activated." } install_concrete_ml() { pip install -U pip setuptools wheel - pip install -e . || return 1 - echo "Concrete ML installed." + if pip install -e .; then + echo "Concrete ML installation successful." + else + echo "Failed to install Concrete ML." + return 1 + fi } install_requirements() { if [ -f "requirements.txt" ]; then - pip install -r requirements.txt || return 1 - echo "Requirements installed." + if pip install -r requirements.txt; then + echo "Requirements installed successfully." + else + echo "Failed to install requirements." + return 1 + fi fi } @@ -49,38 +55,44 @@ run_example() { local example_name=$(basename "$example_dir") if [ ! -f "${example_dir}/Makefile" ]; then + echo "No Makefile found in $example_dir, skipping..." return fi - echo "*** Processing example $example_name ***" + echo "*** Running example: $example_name ***" setup_virtualenv "$example_name" - cd "$current_dir" || return install_concrete_ml || return - cd "$example_dir" || return install_requirements || return set +e - USE_CASE_DIR=$use_case_dir make 3>&2 2>&1 1>&3- | tee /dev/tty | perl -pe 's/\e[^\[\]]*\[.*?[a-zA-Z]|\].*?\a//g' + if [ -t 1 ]; then + USE_CASE_DIR=$use_case_dir make 3>&2 2>&1 1>&3- | tee /dev/tty | perl -pe 's/\e[^\[\]]*\[.*?[a-zA-Z]|\].*?\a//g' + else + USE_CASE_DIR=$use_case_dir make 3>&2 2>&1 1>&3- | perl -pe 's/\e[^\[\]]*\[.*?[a-zA-Z]|\].*?\a//g' + fi + local result="${PIPESTATUS[0]}" set -e + if [ "$result" -ne 0 ]; then - echo "Error while running example $example_name." + echo "Failure in example $example_name." failed_examples+=("$example_name") else + echo "Successfully completed example $example_name." success_examples+=("$example_name") fi + deactivate rm -rf "/tmp/virtualenv_$example_name" } print_summary() { - echo - echo "Summary:" - echo "Successes: ${#success_examples[@]}" + echo "Summary of execution results:" + echo "Successful examples: ${#success_examples[@]}" for example in "${success_examples[@]}"; do echo " - $example" done - echo "Failures: ${#failed_examples[@]}" + echo "Failed examples: ${#failed_examples[@]}" for example in "${failed_examples[@]}"; do echo " - $example" done @@ -93,6 +105,7 @@ main() { declare -a success_examples declare -a failed_examples + local LIST_OF_USE_CASES=() if [[ -z "${USE_CASE}" ]]; then LIST_OF_USE_CASES=($(find "$use_case_dir/" -mindepth 1 -maxdepth 2 -type d | grep -v checkpoints | sort)) else diff --git a/use_case_examples/cifar/cifar_brevitas_training/Makefile b/use_case_examples/cifar/cifar_brevitas_training/Makefile index 840146c7a1..26f0c96bb6 100644 --- a/use_case_examples/cifar/cifar_brevitas_training/Makefile +++ b/use_case_examples/cifar/cifar_brevitas_training/Makefile @@ -6,7 +6,10 @@ EXAMPLE_NAME=cifar_brevitas_training JUPYTER_RUN=jupyter nbconvert --to notebook --inplace --execute TIME_NB="${USE_CASE_DIR}/time_notebook_execution.sh" -run_example: one +run_example: one two one: @python evaluate_one_example_fhe.py + +two: + @python evaluate_torch_cml.py \ No newline at end of file