Commit 9c363d33 authored by caminha's avatar caminha
Browse files

same seeds

parent 58a34311
#!/bin/bash
#SBATCH -N 1 --exclusive
#SBATCH -D /b/home/icube/rcaminha/nas-ndnsim
#SBATCH -o lcn.%j.out
#SBATCH -e lcn.%j.err
#SBATCH -J lcn
#SBATCH --mem=128gb
#SBATCH -N 1 --exclusive
if [ -z "$1" ]; then
NRUNS=5
......@@ -14,7 +15,12 @@ else
fi
NAME="lcn.$SLURM_JOB_ID"
[[ -v SLURM_ARRAY_JOB_ID ]] && NAME="$NAME.aid$SLURM_ARRAY_JOB_ID"
[[ -v SLURM_ARRAY_TASK_ID ]] && NAME="$NAME.aid$SLURM_ARRAY_TASK_ID"
[[ -v SLURM_RESTART_COUNT ]] && NAME=$NAME.r$SLURM_RESTART_COUNT
python3 scripts/run_multiple.py --same-seeds -g "lcn-simulations-2" --nruns=$NRUNS $NAME random-domain-streams --appScenario='DirectSubscriptions RandomTrees' --nConsumers='100 175 250 325 400 475 550'
seeds=(41181870 90747026 79144176 73209143 84833616 86331311 49641965 28873153 21840179 99940459 37523876 22633860 66934504 27108910 65512731 34636308 30006286 36910009 39877905 99585085 26873456 17692977 35492655 64167227 14511616 58347656 59822226 88321588 91627046 86585778)
seed_slice_size=$((${#seeds[*]}/($SLURM_ARRAY_TASK_MAX+1)))
seed_slice_begin=$(($seed_slice_size*$SLURM_ARRAY_TASK_ID))
seeds_to_be_used=${seeds[@]:$seed_slice_begin:$seed_slice_size}
python3 scripts/run_multiple.py --seeds $seeds_to_be_used -g "lcn-simulations-2" $NAME random-domain-streams --appScenario='DirectSubscriptions RandomTrees' --nConsumers='100 175 250 325 400 475 550'
......@@ -20,29 +20,29 @@ def runSimulation(script, outDir, totalNumRuns, slurm, seed, run_params):
runDir = path.join(outDir, path.join(*run_params).replace('-', ''), 'seed=%d'%seed)
run_logger.debug(runDir)
makedirs(runDir)
ns3_simulation_script_and_params = [script, '--RngSeed=%d'%seed]+run_params
ns3_simulation_script_and_params = ' '.join(ns3_simulation_script_and_params)
call_list = ['./waf', '--cwd='+runDir, '--run='+ns3_simulation_script_and_params]
run_logger.info("Running " + ' '.join(run_params))
if slurm:
fp = open('commands.txt', 'a')
fp.writelines(' '.join(call_list) + '\n')
fp.close()
else:
retries = 0
while retries < maxretries:
completedProcess = run(call_list, stdout=PIPE, stderr=PIPE, universal_newlines=True)
if completedProcess.returncode != 0:
run_logger.error("Simulation returned %d w/ params %s!" %
(completedProcess.returncode, ' '.join(run_params)))
run_logger.error("STDOUT: " + completedProcess.stdout)
run_logger.error("STDERR: " + completedProcess.stderr)
retries += 1
else:
break
if retries >= maxretries: exit(1)
if not path.isfile(path.join(runDir, 'consumer-metrics.trace')):
makedirs(runDir, exist_ok=True)
ns3_simulation_script_and_params = [script, '--RngSeed=%d'%seed]+run_params
ns3_simulation_script_and_params = ' '.join(ns3_simulation_script_and_params)
call_list = ['./waf', '--cwd='+runDir, '--run='+ns3_simulation_script_and_params]
run_logger.info("Running " + ' '.join(run_params))
if slurm:
fp = open('commands.txt', 'a')
fp.writelines(' '.join(call_list) + '\n')
fp.close()
else:
retries = 0
while retries < maxretries:
completedProcess = run(call_list, stdout=PIPE, stderr=PIPE, universal_newlines=True)
if completedProcess.returncode != 0:
run_logger.error("Simulation returned %d w/ params %s!" %
(completedProcess.returncode, ' '.join(run_params)))
run_logger.error("STDOUT: " + completedProcess.stdout)
run_logger.error("STDERR: " + completedProcess.stderr)
retries += 1
else:
break
if retries >= maxretries: exit(1)
with doneCounter.get_lock():
doneCounter.value += 1
......@@ -57,7 +57,7 @@ def expand_sim_parameters(sim_params):
#https://stackoverflow.com/questions/15211568/combine-python-dictionary-permutations-into-list-of-dictionaries
tmp = [dict(zip(new_sim_params, v)) for v in product(*new_sim_params.values())]
return [ [ '='.join(it) for it in d.items() ] for d in tmp ]
return [['='.join(it) for it in d.items()] for d in tmp]
def compile_script():
rcode = run(['./waf', 'build']).returncode
......
......@@ -71,7 +71,7 @@ statistics_dataframes = map(read_statistics, sim_folders)
def replace_values(val):
replacements = {
"Random Trees": "Multi-domain",
"Random Trees": "Transformation Overlay",
"Direct Subscriptions": "Conventional NDN"
}
if isinstance(val, str): val = val.strip()
......@@ -114,7 +114,7 @@ node_type_order = ("Consumer",
# scenarioOrder = ("NasArch", "PullEverything", "PushEverything")
# scenarioOrder = ("Random Trees", "Direct Subscriptions")
scenarioOrder = ("Multi-domain", "Conventional NDN")
scenarioOrder = ("Transformation Overlay", "Conventional NDN")
violin_params = {'inner': "box", 'bw': 'scott', 'scale': 'width'}
......
......@@ -4,7 +4,7 @@ from os import path, makedirs, chdir
import argparse
from shutil import rmtree
from random import sample
from multiprocessing import Pool, Value
from multiprocessing import Pool, Value, cpu_count
from functools import partial
import nas_utils
from itertools import cycle
......@@ -21,8 +21,8 @@ parser.add_argument('script', metavar="script_name", choices=['random-domain-str
parser.add_argument('--force-run', '-f', dest='force', action='store_true',
help='Makes this script overwrite previous runs, by default it will detect previous runs and skip running them')
parser.add_argument('--singlecpu', '--singlecore', dest='singlecpu', action='store_true',
help='Makes this script overwrite previous runs, by default it will detect previous runs and skip running them')
parser.add_argument('--ncpu', dest='ncpu', type=int, default=cpu_count(),
help='Number of cpus to use to run experiments. Defaults to the available amount.')
parser.add_argument('--runs_per_scenario', "--nruns", metavar='Runs per scenario', type=int, default=30,
help='Number of times the simulation must be run for each scenario')
......@@ -42,6 +42,9 @@ parser.add_argument('--slurm', action='store_true',
parser.add_argument('--same-seeds', dest='same_seeds', action='store_true',
help='Tells the runs to use the same seeds for all combinations of parameters instead of unique ones for each simulation')
parser.add_argument("--use-these-seeds", '--seeds', dest='use_these_seeds', type=int, nargs='+', default=list(),
help='Tells the simulation to use each of these seeds for each combination of the parameters')
parser.add_argument('sim_params', metavar='Others', type=str, nargs=argparse.REMAINDER,
help='Arguments to be put in every run of the simulation')
......@@ -69,24 +72,25 @@ if not params.slurm:
nas_utils.compile_script()
progressCounter = Value('d', 0.0)
#Pool creation has to be after job function definition!
if params.singlecpu:
runners = Pool(1, initializer=nas_utils.runSimulationWorkerInitializer, initargs=(progressCounter,))
else:
# runners = Pool(initializer=nas_utils.runSimulationWorkerInitializer, initargs=(progressCounter,))
# runners = Pool(int(mp.cpu_count()/2), initializer=nas_utils.runSimulationWorkerInitializer, initargs=(progressCounter,))
runners = Pool(5, initializer=nas_utils.runSimulationWorkerInitializer, initargs=(progressCounter,))
runners = Pool(params.ncpu, initializer=nas_utils.runSimulationWorkerInitializer, initargs=(progressCounter,))
params.expanded_sim_params = nas_utils.expand_sim_parameters(params.sim_params)
try:
logger.info('Running simulations')
logger.debug('Using params: ' + ", ".join([k+'='+str(v) for k, v in vars(params).items() if k != 'expanded_sim_params']))
totalRuns = len(params.expanded_sim_params) * params.runs_per_scenario
if params.same_seeds:
seed_list = sample(range(10000000, 99999999), params.runs_per_scenario)*len(params.expanded_sim_params)
if params.use_these_seeds:
seed_list = [s for s in params.use_these_seeds for i in params.expanded_sim_params]
totalRuns = len(seed_list)
else:
seed_list = sample(range(10000000, 99999999), totalRuns)
if params.same_seeds:
seed_list = [s for s in sample(range(10000000, 99999999), params.runs_per_scenario) for i in params.expanded_sim_params]
totalRuns = len(seed_list)
else:
seed_list = sample(range(10000000, 99999999), len(params.expanded_sim_params) * params.runs_per_scenario)
totalRuns = len(seed_list)
ids_seeds_and_params = zip(seed_list, cycle(params.expanded_sim_params))
runTestPartial = partial(nas_utils.runSimulation, params.script, outDir, totalRuns, params.slurm)
# total_t1 = time()
......@@ -98,9 +102,10 @@ try:
# logger.info('Running plot scripts')
# call(['./dot11s_simulation/scripts/node_statistics.py', outDir], stderr=PIPE, stdout=PIPE)
# call(['./dot11s_simulation/scripts/flow_statistics.py', outDir], stderr=PIPE, stdout=PIPE)
except BaseException as e:
# except BaseException as e:
# logger.error("Something went wrong with the experiment...")
# logger.error(e)
# # rmtree(outDir)
# exit(1)
finally:
runners.terminate()
logger.error("Something went wrong with the experiment...")
logger.error(e)
# rmtree(outDir)
exit(1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment