2024-01-08 13:08:17 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-05-25 08:09:53 +02:00
|
|
|
# Validate the correctness and optionally measure times of aba2sat and aspforaba
|
|
|
|
# best used through the bundled nix version `nix run .#validate`
|
|
|
|
|
2024-01-08 13:08:17 +01:00
|
|
|
print_help_and_exit() {
|
2024-06-28 09:44:12 +02:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
printf "%s\n\n" "$1"
|
|
|
|
fi
|
|
|
|
printf "Usage: validate [OPTIONS] \n"
|
|
|
|
printf "\n"
|
|
|
|
printf "Options:\n"
|
|
|
|
printf " --aspforaba EXE\n"
|
|
|
|
printf " Binary to use when calling aspforaba\n"
|
|
|
|
printf " -p, --problem\n"
|
|
|
|
printf " The problem to solve\n"
|
|
|
|
printf " -a, --arg\n"
|
|
|
|
printf " The additional argument for the problem\n"
|
|
|
|
printf " -f, --file\n"
|
|
|
|
printf " The file containing the problem in ABA format\n"
|
|
|
|
printf " -t, --time\n"
|
|
|
|
printf " Execute hyperfine to determine runtimes\n"
|
|
|
|
printf " --files-from\n"
|
|
|
|
printf " Use the following dir to read files, specify a single file with --file instead\n"
|
|
|
|
printf " --aba2sat EXE\n"
|
|
|
|
printf " Binary to use when calling aba2sat\n"
|
|
|
|
printf " --max-loops NUM (Default: 0)\n"
|
|
|
|
printf " Set the maximum number of loops aba2sat should try to fix\n"
|
|
|
|
exit 1
|
2024-01-08 13:08:17 +01:00
|
|
|
}
|
|
|
|
|
2024-04-20 14:09:41 +02:00
|
|
|
format_time() {
|
2024-06-28 09:44:12 +02:00
|
|
|
COMMAND="$1"
|
|
|
|
FILE="$2"
|
|
|
|
mean=$(jq ".results[] | select(.command == \"$COMMAND\") | (.mean * 1000)" "$FILE")
|
|
|
|
stddev=$(jq ".results[] | select(.command == \"$COMMAND\") | (.stddev * 1000)" "$FILE")
|
|
|
|
printf "%7.3f±%7.3fms" "$mean" "$stddev"
|
2024-04-20 14:09:41 +02:00
|
|
|
}
|
|
|
|
|
2024-01-08 13:08:17 +01:00
|
|
|
run_dc_co() {
|
2024-06-28 09:44:12 +02:00
|
|
|
OUTPUT_DIR=${OUTPUT_DIR:-$(mktemp -d)}
|
|
|
|
mkdir -p "$OUTPUT_DIR"
|
|
|
|
JSON_FILE="$OUTPUT_DIR/$(basename "$ABA_FILE")-hyperfine.json"
|
|
|
|
# Restrict memory to 20GB
|
|
|
|
ulimit -v 20000000
|
|
|
|
if [ -z "$ADDITIONAL_ARG" ]; then
|
|
|
|
print_help_and_exit "Parameter --arg is missing!"
|
|
|
|
fi
|
|
|
|
if [ -z "$ABA_FILE" ]; then
|
|
|
|
print_help_and_exit "Parameter --file is missing!"
|
|
|
|
fi
|
|
|
|
printf "===== %s ==== " "$(basename "$ABA_FILE")"
|
|
|
|
our_result=$("$ABA2SAT" --max-loops "$MAX_LOOPS" --file "$ABA_FILE" dc-co --query "$ADDITIONAL_ARG" | tee "$OUTPUT_DIR/$(basename "$ABA_FILE")-aba2sat-result")
|
|
|
|
other_result=$("$ASPFORABA" --file "$ABA_FILE" --problem DC-CO --query "$ADDITIONAL_ARG" | tee "$OUTPUT_DIR/$(basename "$ABA_FILE")-aspforaba-result")
|
|
|
|
if [ "$our_result" != "$other_result" ]; then
|
|
|
|
printf "❌\n"
|
|
|
|
else
|
|
|
|
printf "✅\n"
|
|
|
|
fi
|
|
|
|
printf "Argument: %s\n" "$ADDITIONAL_ARG"
|
2024-04-25 17:02:48 +02:00
|
|
|
|
2024-06-28 09:44:12 +02:00
|
|
|
if [ -n "$TIME_COMMANDS" ]; then
|
|
|
|
$HYPERFINE --shell=none \
|
|
|
|
--export-json "$JSON_FILE" \
|
|
|
|
--command-name "aba2sat" \
|
|
|
|
"$ABA2SAT --max-loops \"$MAX_LOOPS\" --file \"$ABA_FILE\" dc-co --query \"$ADDITIONAL_ARG\"" \
|
|
|
|
--command-name "aspforaba" \
|
|
|
|
"$ASPFORABA --file \"$ABA_FILE\" --problem DC-CO --query \"$ADDITIONAL_ARG\"" 1>/dev/null 2>&1
|
|
|
|
printf "Our: %3s %30s\n" "$our_result" "$(format_time "aba2sat" "$JSON_FILE")"
|
|
|
|
printf "Their: %3s %30s\n" "$other_result" "$(format_time "aspforaba" "$JSON_FILE")"
|
|
|
|
else
|
|
|
|
printf "Our: %3s\n" "$our_result"
|
|
|
|
printf "Their: %3s\n" "$other_result"
|
|
|
|
fi
|
2024-04-25 17:02:48 +02:00
|
|
|
|
2024-01-08 13:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
POSITIONAL_ARGS=()
|
|
|
|
ASPFORABA=ASPforABA
|
2024-05-25 08:09:53 +02:00
|
|
|
ABA2SAT=aba2sat
|
2024-01-08 13:08:17 +01:00
|
|
|
ABA_FILE=
|
|
|
|
ABA_FILE_DIR=
|
|
|
|
ABA_FILE_EXT=aba
|
2024-04-20 14:09:41 +02:00
|
|
|
HYPERFINE=hyperfine
|
2024-06-28 09:44:12 +02:00
|
|
|
MAX_LOOPS=0
|
2024-01-08 13:08:17 +01:00
|
|
|
PROBLEM=
|
|
|
|
ADDITIONAL_ARG=
|
2024-04-25 17:02:48 +02:00
|
|
|
TIME_COMMANDS=
|
2024-01-08 13:08:17 +01:00
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
2024-06-28 09:44:12 +02:00
|
|
|
case $1 in
|
|
|
|
-h | --help)
|
|
|
|
print_help_and_exit ""
|
|
|
|
;;
|
|
|
|
--aspforaba)
|
|
|
|
shift
|
|
|
|
ASPFORABA=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-p | --problem)
|
|
|
|
shift
|
|
|
|
PROBLEM=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-f | --file)
|
|
|
|
if [ -n "$ABA_FILE_DIR" ]; then
|
|
|
|
print_help_and_exit "Parameters --file and --files-from cannot be mixed"
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
ABA_FILE=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--files-from)
|
|
|
|
if [ -n "$ABA_FILE" ]; then
|
|
|
|
print_help_and_exit "Parameters --file and --files-from cannot be mixed"
|
|
|
|
fi
|
|
|
|
if [ -n "$ADDITIONAL_ARG" ]; then
|
|
|
|
print_help_and_exit "Parameters --arg and --files-from cannot be mixed"
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
ABA_FILE_DIR=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-a | --arg)
|
|
|
|
if [ -n "$ABA_FILE_DIR" ]; then
|
|
|
|
print_help_and_exit "Parameters --arg and --files-from cannot be mixed"
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
ADDITIONAL_ARG=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-t | --time)
|
|
|
|
shift
|
|
|
|
TIME_COMMANDS=yes
|
|
|
|
;;
|
|
|
|
--aba2sat)
|
|
|
|
shift
|
|
|
|
ABA2SAT=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--max-loops)
|
|
|
|
shift
|
|
|
|
echo "MAX LOOPS $1"
|
|
|
|
MAX_LOOPS=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo "Unknown option $1"
|
|
|
|
print_help_and_exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
POSITIONAL_ARGS+=("$1") # save positional arg
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
esac
|
2024-01-08 13:08:17 +01:00
|
|
|
done
|
|
|
|
|
2024-03-13 11:10:32 +01:00
|
|
|
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
|
2024-01-08 13:08:17 +01:00
|
|
|
|
|
|
|
case "$PROBLEM" in
|
2024-06-28 09:44:12 +02:00
|
|
|
dc-co | DC-CO)
|
|
|
|
if [ -n "$ABA_FILE_DIR" ]; then
|
|
|
|
# run for every file found in the directory
|
|
|
|
for file in $(find "$ABA_FILE_DIR" -type f -iname "*.$ABA_FILE_EXT" | shuf); do
|
|
|
|
ABA_FILE="$file" ADDITIONAL_ARG="$(cat "$file.asm")" run_dc_co
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# run for the single configured file
|
|
|
|
run_dc_co
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
print_help_and_exit "Problem $PROBLEM is not supported"
|
|
|
|
;;
|
2024-01-08 13:08:17 +01:00
|
|
|
esac
|