Skip to content

Commit

Permalink
Update bash scripts
Browse files Browse the repository at this point in the history
The unity cluster updates its OS and the names of their partitions.

Also have the option for the user to run in a specified directory.
  • Loading branch information
ryanmccann1024 committed Dec 21, 2024
1 parent d68ef1f commit 79af39e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
28 changes: 20 additions & 8 deletions bash_scripts/run_rl_sim.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash

#SBATCH -p cpu-preempt
#SBATCH -c 1
#SBATCH -p arm-preempt
#SBATCH -c 20
#SBATCH -G 0
#SBATCH --mem=16000
#SBATCH -t 0-04:00:00
#SBATCH -o slurm-%j.out
#SBATCH --mem=40000
#SBATCH -t 14-00:00:00
#SBATCH -o slurm-%A_%a.out # Output file for each task
#SBATCH --array=0-3 # Define array size based on total combinations

# This script is designed to run a reinforcement learning simulation on the Unity cluster at UMass Amherst.
# It sets up the necessary environment, installs dependencies, registers custom environments, and runs
Expand All @@ -18,10 +19,21 @@ set -e
# shellcheck disable=SC2164
cd
# shellcheck disable=SC2164
cd /work/pi_vinod_vokkarane_uml_edu/git/sdn_simulator/
# Default directory
DEFAULT_DIR="/work/pi_vinod_vokkarane_uml_edu/git/sdn_simulator/"

# Load the required Python module
module load python/3.11.0
# Check for user input
if [ -z "$1" ]; then
echo "No directory provided. Using default directory: $DEFAULT_DIR"
cd "$DEFAULT_DIR"
else
echo "Changing to user-specified directory: $1"
cd "$1"
fi

echo "Current directory: $(pwd)"

module load python/3.11.7

# Activate the virtual environment
# Create the virtual environment if it doesn't exist
Expand Down
49 changes: 35 additions & 14 deletions bash_scripts/run_sim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@
#SBATCH -o slurm-%A_%a.out # Output file for each task
#SBATCH --array=0-3 # Define array size based on total combinations


# This script is designed to run a non-artificial intelligence simulation on the Unity cluster at UMass Amherst.

set -e # Stop the script if any command fails
set -e # Stop the script if any command fails

# Default directory
DEFAULT_DIR="/work/pi_vinod_vokkarane_uml_edu/git/sdn_simulator/"

# Check for user input
if [ -z "$1" ]; then
echo "No directory provided. Using default directory: $DEFAULT_DIR"
cd "$DEFAULT_DIR"
else
echo "Changing to user-specified directory: $1"
cd "$1"
fi

# Confirm current directory
echo "Current directory: $(pwd)"

echo "Starting job with SLURM_ARRAY_TASK_ID: $SLURM_ARRAY_TASK_ID"

Expand All @@ -21,6 +35,16 @@ module load python/3.11.7
# Verify the loaded Python version
python --version

# Activate the virtual environment
# Create the virtual environment if it doesn't exist
if [ ! -d "venvs/unity_venv/venv" ]; then
./bash_scripts/make_venv.sh venvs/unity_venv python3.11
fi
source venvs/unity_venv/venv/bin/activate

# Install the required Python packages
pip install -r requirements.txt

# Define parameter arrays
allocation_methods=("first_fit" "last_fit")
spectrum_allocation_priorities=("CSB" "BSC")
Expand All @@ -31,7 +55,7 @@ num_requests=15000
multi_fiber=False

# Calculate total combinations
total_combinations=$(( ${#allocation_methods[@]} * ${#spectrum_allocation_priorities[@]} * ${#cores_per_link[@]} ))
total_combinations=$((${#allocation_methods[@]} * ${#spectrum_allocation_priorities[@]} * ${#cores_per_link[@]}))

# Ensure the task ID is within the range of total combinations
if [ "$SLURM_ARRAY_TASK_ID" -ge "$total_combinations" ]; then
Expand All @@ -40,10 +64,10 @@ if [ "$SLURM_ARRAY_TASK_ID" -ge "$total_combinations" ]; then
fi

# Calculate indices based on SLURM_ARRAY_TASK_ID
allocation_method_index=$(( SLURM_ARRAY_TASK_ID / (${#spectrum_allocation_priorities[@]} * ${#cores_per_link[@]}) ))
temp_index=$(( SLURM_ARRAY_TASK_ID % (${#spectrum_allocation_priorities[@]} * ${#cores_per_link[@]}) ))
spectrum_priority_index=$(( temp_index / ${#cores_per_link[@]} ))
cores_per_link_index=$(( temp_index % ${#cores_per_link[@]} ))
allocation_method_index=$((SLURM_ARRAY_TASK_ID / (${#spectrum_allocation_priorities[@]} * ${#cores_per_link[@]})))
temp_index=$((SLURM_ARRAY_TASK_ID % (${#spectrum_allocation_priorities[@]} * ${#cores_per_link[@]})))
spectrum_priority_index=$((temp_index / ${#cores_per_link[@]}))
cores_per_link_index=$((temp_index % ${#cores_per_link[@]}))

# Select parameters for this task
allocation_method=${allocation_methods[$allocation_method_index]}
Expand All @@ -58,14 +82,11 @@ echo " Cores per link: $cores"
echo " Number of requests: $num_requests"
echo " Multi-fiber: $multi_fiber"

# Move to the project directory
cd ~/Git/SDON_simulator/ || { echo "Failed to change to SDON_simulator directory"; exit 1; }

# Run the simulation with the specified parameters
python run_sim.py --allocation_method "$allocation_method" \
--spectrum_allocation_priority "$spectrum_priority" \
--cores_per_link "$cores" \
--num_requests "$num_requests" \
--multi_fiber "$multi_fiber"
--spectrum_allocation_priority "$spectrum_priority" \
--cores_per_link "$cores" \
--num_requests "$num_requests" \
--multi_fiber "$multi_fiber"

echo "Job completed successfully for SLURM_ARRAY_TASK_ID: $SLURM_ARRAY_TASK_ID"

0 comments on commit 79af39e

Please sign in to comment.