Skip to content

Commit

Permalink
chore: refacto + add evaluate torch
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrery committed Apr 15, 2024
1 parent 917715d commit 0374847
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
51 changes: 32 additions & 19 deletions script/make_utils/run_use_case_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion use_case_examples/cifar/cifar_brevitas_training/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0374847

Please sign in to comment.