Skip to content

Commit

Permalink
Add a script to run training and evaluation of all agents in CCOD exa…
Browse files Browse the repository at this point in the history
…mple
  • Loading branch information
m-wojnar committed Feb 9, 2024
1 parent 2858cbe commit 6b4e8cf
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 53 deletions.
1 change: 0 additions & 1 deletion examples/ns-3-ccod/outputs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*
!.gitignore
!combine_basic_results.sh
!combine_csv_files.sh
!preprocess_basic_results.py
!preprocess_csma_results.py
34 changes: 0 additions & 34 deletions examples/ns-3-ccod/outputs/combine_basic_results.sh

This file was deleted.

16 changes: 10 additions & 6 deletions examples/ns-3-ccod/tools/slurm/baseline.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#!/usr/bin/scl enable devtoolset-11 rh-python38 -- /bin/bash -l
#!/bin/bash

if [[ $# -ne 3 ]]; then
echo "Usage: $0 <scenario> <nWifi> <seed>"
exit 1
fi

NS3_DIR="${NS3_DIR:=$HOME/ns-3.37}"
RLIB_DIR="${RLIB_DIR:=$HOME/reinforced-lib/examples/ns-3-ccod}"

cd "$NS3_DIR/build/scratch"

SIM_TIME=60
SCENARIO="convergence"
N_WIFI=55
SCENARIO=$1
N_WIFI=$2
SEED=$3

NUM_REPS=10
SEED=300

for (( i = 1; i <= NUM_REPS; i += 1)); do
CSV_PATH="$RLIB_DIR/outputs/CSMA_${SCENARIO}_${N_WIFI}_run${i}.csv"
echo "Testing CSMA/CA ${SCENARIO} ${N_WIFI} simulation [${i}/${NUM_REPS}]"
./ns3.37-ccod-sim-optimized --csvPath="$CSV_PATH" --agentType="discrete" --dryRun="true" --envStepTime="0.01" --historyLength="300" --nonZeroStart="true" --nWifi="$N_WIFI" --scenario="$SCENARIO" --simTime="$SIM_TIME" --RngRun="$SEED"
./ns3.37-ccod-sim-optimized --csvPath="$CSV_PATH" --agentType="discrete" --dryRun="true" --envStepTime="0.01" --historyLength="300" --nonZeroStart="true" --nWifi="$N_WIFI" --scenario="$SCENARIO" --simTime="60.0" --RngRun="$SEED"

SEED=$(( SEED + 1 ))
done
22 changes: 22 additions & 0 deletions examples/ns-3-ccod/tools/slurm/run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

TOOLS_DIR="${TOOLS_DIR:=$HOME/reinforced-lib/examples/ns-3-ccod/tools}"
cd "TOOLS_DIR/slurm"

for agent in "CSMA" "DDPG" "DDQN"; do
for nWifi in 5 15 30 50; do
if [[ $agent == "CSMA" ]]; then
./baseline.sh "basic" $nWifi 300
else
./train.sh $agent "basic" $nWifi 200
./test.sh $agent "basic" $nWifi 300
fi
done

if [[ $agent == "CSMA" ]]; then
./baseline.sh "convergence" 55 400
else
./train.sh $agent "convergence" 55 200
./test.sh $agent "convergence" 55 400
fi
done
25 changes: 19 additions & 6 deletions examples/ns-3-ccod/tools/slurm/test.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
#!/usr/bin/scl enable devtoolset-11 rh-python38 -- /bin/bash -l
#!/bin/bash

if [[ $# -ne 4 ]]; then
echo "Usage: $0 <agent> <scenario> <nWifi> <seed>"
exit 1
fi

NS3_DIR="${NS3_DIR:=$HOME/ns-3.37}"
RLIB_DIR="${RLIB_DIR:=$HOME/reinforced-lib/examples/ns-3-ccod}"

cd "$RLIB_DIR"

AGENT="DDPG"
AGENT_TYPE="continuous"
AGENT=$1

if [[ $AGENT == "DDPG" ]]; then
AGENT_TYPE="continuous"
elif [[ $AGENT == "DDQN" ]]; then
AGENT_TYPE="discrete"
else
echo "Invalid agent type: $AGENT"
exit 2
fi

SCENARIO="convergence"
N_WIFI=55
SCENARIO=$2
N_WIFI=$3
SEED=$4

LAST_RUN=14
NUM_REPS=10
SEED=300
MEMPOOL_KEY=1234

CHECKPOINT_LOAD_PATH="$RLIB_DIR/checkpoints/${AGENT}_${SCENARIO}_${N_WIFI}_run_${LAST_RUN}.pkl.lz4"
Expand Down
25 changes: 19 additions & 6 deletions examples/ns-3-ccod/tools/slurm/train.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
#!/usr/bin/scl enable devtoolset-11 rh-python38 -- /bin/bash -l
#!/bin/bash

if [[ $# -ne 4 ]]; then
echo "Usage: $0 <agent> <scenario> <nWifi> <seed>"
exit 1
fi

NS3_DIR="${NS3_DIR:=$HOME/ns-3.37}"
RLIB_DIR="${RLIB_DIR:=$HOME/reinforced-lib/examples/ns-3-ccod}"

cd "$RLIB_DIR"

AGENT="DDPG"
AGENT_TYPE="continuous"
AGENT=$1

if [[ $AGENT == "DDPG" ]]; then
AGENT_TYPE="continuous"
elif [[ $AGENT == "DDQN" ]]; then
AGENT_TYPE="discrete"
else
echo "Invalid agent type: $AGENT"
exit 2
fi

SCENARIO="convergence"
N_WIFI=55
SCENARIO=$2
N_WIFI=$3
SEED=$4

NUM_REPS=14
SEED=200
MEMPOOL_KEY=1234

for (( i = 1; i <= NUM_REPS; i += 1)); do
Expand Down

0 comments on commit 6b4e8cf

Please sign in to comment.