diff --git a/eo/contrib/irace/expe/beta/csv_all_bests.sh b/eo/contrib/irace/expe/beta/csv_all_bests.sh new file mode 100755 index 000000000..3f0fb3652 --- /dev/null +++ b/eo/contrib/irace/expe/beta/csv_all_bests.sh @@ -0,0 +1,16 @@ +#!/bin/bash +ldata=$1 +file_py=$2 +csvdir="csv_FA" +ldir=$(echo $(ls ${ldata})) +for data in ${ldir[@]} ; do + path="${ldata}/${data}" + cmd="python3 ${file_py} ${path}" + plan_name=$(echo ${data} | sed "s/data//") + mexp=$(echo ${data[@]} | cut -d _ -f2) + mevals=$(echo ${data[@]} | cut -d _ -f3) + ddate=$(echo ${data[@]} | cut -d _ -f4) + name="results_irace_plan${plan_name[@]:0:1}_${mexp}_${mevals}_${ddate}" + mkdir -p "${csvdir}/csv_plan${plan_name[@]:0:1}" + ${cmd} > "${csvdir}/csv_plan${plan_name[@]:0:1}/${name}.csv" +done diff --git a/eo/contrib/irace/expe/beta/fastga_elites_all.sh b/eo/contrib/irace/expe/beta/fastga_elites_all.sh new file mode 100644 index 000000000..a53eb189d --- /dev/null +++ b/eo/contrib/irace/expe/beta/fastga_elites_all.sh @@ -0,0 +1,22 @@ +#!/bin/bash +ldata=$1 # eg : ./csv_planF/ don t forget to end the path with / +file_sh=$2 #eg : ./run_elites_planF +ldir=$(echo $(ls ${ldata})) +fastga_dir="fastga_results_all" +mkdir -p /scratchbeta/${USER}/${fatga_dir} +#mkdir -p "/home/${USER}/${fastga_dir}/fastga_results_plan1" +mkdir -p "/scratchbeta/${USER}/${fastga_dir}/fastga_results_planF" +mkdir -p "/scratchbeta/${USER}/${fastga_dir}/fastga_results_planA" + +for data in ${ldir[@]} ; do + path_csv="${ldata}${data}" + plan_name=$(echo ${data} | sed "s/results_irace_plan//") + mexp=$(echo ${data[@]} | cut -d _ -f4) + mexp_id=$(echo ${mexp} | cut -d = -f2) + mevals=$(echo ${data[@]} | cut -d _ -f5) + mevals_id=$(echo ${mevals} | cut -d = -f2) + path="/scratchbeta/${USER}/${fastga_dir}/fastga_results_plan${plan_name[@]:0:1}" + cmd="bash ${file_sh} ${path_csv} ${mexp_id} ${mevals_id} ${path}" + name="fastga${plan_name[@]:0:1}_${mexp}_${mevals}_$(date -Iseconds)_results_elites_all" + ${cmd} &> "${path}/output${plan_name[@]:0:1}_fastga_${mexp}_${mevals}_$(date -Iseconds).txt" +done diff --git a/eo/contrib/irace/expe/beta/irace_files_pA/default.instances b/eo/contrib/irace/expe/beta/irace_files_pA/default.instances new file mode 100755 index 000000000..4934f7988 --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pA/default.instances @@ -0,0 +1,27 @@ +## This is an example of specifying instances with a file. + +# Each line is an instance relative to trainInstancesDir +# (see scenario.txt.tmpl) and an optional sequence of instance-specific +# parameters that will be passed to target-runnerx when invoked on that +# instance. + +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 + diff --git a/eo/contrib/irace/expe/beta/irace_files_pA/example.scen b/eo/contrib/irace/expe/beta/irace_files_pA/example.scen new file mode 100755 index 000000000..abebcbb6d --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pA/example.scen @@ -0,0 +1,227 @@ +###################################################### -*- mode: r -*- ##### +## Scenario setup for Iterated Race (irace). +############################################################################ + +## To use the default value of a parameter of iRace, simply do not set +## the parameter (comment it out in this file, and do not give any +## value on the command line). + +## File that contains the description of the parameters of the target +## algorithm. +parameterFile = "./fastga.param" + +## Directory where the programs will be run. +execDir = "." + +## File to save tuning results as an R dataset, either absolute path or +## relative to execDir. +# logFile = "./irace.Rdata" + +## Previously saved log file to recover the execution of irace, either +## absolute path or relative to the current directory. If empty or NULL, +## recovery is not performed. +# recoveryFile = "" + +## Directory where training instances are located; either absolute path or +## relative to current directory. If no trainInstancesFiles is provided, +## all the files in trainInstancesDir will be listed as instances. +trainInstancesDir = "." + +## File that contains a list of training instances and optionally +## additional parameters for them. If trainInstancesDir is provided, irace +## will search for the files in this folder. +trainInstancesFile = "./default.instances" + +## File that contains a table of initial configurations. If empty or NULL, +## all initial configurations are randomly generated. +# configurationsFile = "" + +## File that contains a list of logical expressions that cannot be TRUE +## for any evaluated configuration. If empty or NULL, do not use forbidden +## expressions. +forbiddenFile = "./forbidden.txt" + +## Script called for each configuration that executes the target algorithm +## to be tuned. See templates. +targetRunner = "./target-runner" + +## Number of times to retry a call to targetRunner if the call failed. +# targetRunnerRetries = 0 + +## Optional data passed to targetRunner. This is ignored by the default +## targetRunner function, but it may be used by custom targetRunner +## functions to pass persistent data around. +# targetRunnerData = "" + +## Optional R function to provide custom parallelization of targetRunner. +# targetRunnerParallel = "" + +## Optional script or R function that provides a numeric value for each +## configuration. See templates/target-evaluator.tmpl +# targetEvaluator = "" + +## Maximum number of runs (invocations of targetRunner) that will be +## performed. It determines the maximum budget of experiments for the +## tuning. +maxExperiments = 0 #100000 + +## Maximum total execution time in seconds for the executions of +## targetRunner. targetRunner must return two values: cost and time. +# maxTime = 60 + +## Fraction (smaller than 1) of the budget used to estimate the mean +## computation time of a configuration. Only used when maxTime > 0 +# budgetEstimation = 0.02 + +## Maximum number of decimal places that are significant for numerical +## (real) parameters. +digits = 2 + +## Debug level of the output of irace. Set this to 0 to silence all debug +## messages. Higher values provide more verbose debug messages. +# debugLevel = 0 + +## Number of iterations. +# nbIterations = 0 + +## Number of runs of the target algorithm per iteration. +# nbExperimentsPerIteration = 0 + +## Randomly sample the training instances or use them in the order given. +# sampleInstances = 1 + +## Statistical test used for elimination. Default test is always F-test +## unless capping is enabled, in which case the default test is t-test. +## Valid values are: F-test (Friedman test), t-test (pairwise t-tests with +## no correction), t-test-bonferroni (t-test with Bonferroni's correction +## for multiple comparisons), t-test-holm (t-test with Holm's correction +## for multiple comparisons). +# testType = "F-test" + +## Number of instances evaluated before the first elimination test. It +## must be a multiple of eachTest. +# firstTest = 5 + +## Number of instances evaluated between elimination tests. +# eachTest = 1 + +## Minimum number of configurations needed to continue the execution of +## each race (iteration). +# minNbSurvival = 0 + +## Number of configurations to be sampled and evaluated at each iteration. +# nbConfigurations = 0 + +## Parameter used to define the number of configurations sampled and +## evaluated at each iteration. +# mu = 5 + +## Confidence level for the elimination test. +# confidence = 0.95 + +## If the target algorithm is deterministic, configurations will be +## evaluated only once per instance. +# deterministic = 0 + +## Seed of the random number generator (by default, generate a random +## seed). +# seed = NA + +## Number of calls to targetRunner to execute in parallel. Values 0 or 1 +## mean no parallelization. +# parallel = 0 + +## Enable/disable load-balancing when executing experiments in parallel. +## Load-balancing makes better use of computing resources, but increases +## communication overhead. If this overhead is large, disabling +## load-balancing may be faster. +# loadBalancing = 1 + +## Enable/disable MPI. Use Rmpi to execute targetRunner in parallel +## (parameter parallel is the number of slaves). +# mpi = 0 + +## Specify how irace waits for jobs to finish when targetRunner submits +## jobs to a batch cluster: sge, pbs, torque or slurm. targetRunner must +## submit jobs to the cluster using, for example, qsub. +# batchmode = 0 + +## Enable/disable the soft restart strategy that avoids premature +## convergence of the probabilistic model. +# softRestart = 1 + +## Soft restart threshold value for numerical parameters. If NA, NULL or +## "", it is computed as 10^-digits. +# softRestartThreshold = "" + +## Directory where testing instances are located, either absolute or +## relative to current directory. +# testInstancesDir = "" + +## File containing a list of test instances and optionally additional +## parameters for them. +# testInstancesFile = "" + +## Number of elite configurations returned by irace that will be tested if +## test instances are provided. +# testNbElites = 1 + +## Enable/disable testing the elite configurations found at each +## iteration. +# testIterationElites = 0 + +## Enable/disable elitist irace. +# elitist = 1 + +## Number of instances added to the execution list before previous +## instances in elitist irace. +# elitistNewInstances = 1 + +## In elitist irace, maximum number per race of elimination tests that do +## not eliminate a configuration. Use 0 for no limit. +# elitistLimit = 2 + +## User-defined R function that takes a configuration generated by irace +## and repairs it. +# repairConfiguration = "" + +## Enable the use of adaptive capping, a technique designed for minimizing +## the computation time of configurations. This is only available when +## elitist is active. +# capping = 0 + +## Measure used to obtain the execution bound from the performance of the +## elite configurations: median, mean, worst, best. +# cappingType = "median" + +## Method to calculate the mean performance of elite configurations: +## candidate or instance. +# boundType = "candidate" + +## Maximum execution bound for targetRunner. It must be specified when +## capping is enabled. +# boundMax = 0 + +## Precision used for calculating the execution time. It must be specified +## when capping is enabled. +# boundDigits = 0 + +## Penalization constant for timed out executions (executions that reach +## boundMax execution time). +# boundPar = 1 + +## Replace the configuration cost of bounded executions with boundMax. +# boundAsTimeout = 1 + +## Percentage of the configuration budget used to perform a postselection +## race of the best configurations of each iteration after the execution +## of irace. +# postselection = 0 + +## Enable/disable AClib mode. This option enables compatibility with +## GenericWrapper4AC as targetRunner script. +# aclib = 0 + +## END of scenario file +############################################################################ + diff --git a/eo/contrib/irace/expe/beta/irace_files_pA/fastga.param b/eo/contrib/irace/expe/beta/irace_files_pA/fastga.param new file mode 100755 index 000000000..2b5779f64 --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pA/fastga.param @@ -0,0 +1,12 @@ +# name switch type range +# continuator "--continuator=" c (0) +crossoverrate "--crossover-rate=" r (0,1) +crossselector "--cross-selector=" c (0,1,2,3,4,5,6) +# aftercrossselector "--aftercross-selector=" c (0) +crossover "--crossover=" c (0,1,2,3,4,5,6,7,8,9) +mutationrate "--mutation-rate=" r (0,1) +mutselector "--mut-selector=" c (0,1,2,3,4,5,6) +mutation "--mutation=" c (0,1,2,3,4,5,6,7,8,9,10) +replacement "--replacement=" c (0,1,2,3,4,5,6,7,8,9,10) +popsize "--pop-size=" i (1,50) +offspringsize "--offspring-size=" i (1,50) diff --git a/eo/contrib/irace/expe/beta/irace_files_pA/target-runner b/eo/contrib/irace/expe/beta/irace_files_pA/target-runner new file mode 100755 index 000000000..54c47ecd2 --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pA/target-runner @@ -0,0 +1,89 @@ +#!/bin/bash +############################################################################### +# This script is the command that is executed every run. +# Check the examples in examples/ +# +# This script is run in the execution directory (execDir, --exec-dir). +# +# PARAMETERS: +# $1 is the candidate configuration number +# $2 is the instance ID +# $3 is the seed +# $4 is the instance name +# The rest ($* after `shift 4') are parameters to the run +# +# RETURN VALUE: +# This script should print one numerical value: the cost that must be minimized. +# Exit with 0 if no error, with 1 in case of error +############################################################################### +error() { + echo "`TZ=UTC date`: $0: error: $@" + exit 1 +} + + +EXE="./fastga" +LOG_DIR="irace_logs" + +#FIXED_PARAMS="--problem=0" +# +CONFIG_ID=$1 +INSTANCE_ID=$2 +SEED=$3 +INSTANCE=$(echo $4 | sed 's/\//\n/g'|tail -n 1) +CROSSOVER_RATE=$5 +CROSSOVER_SELECTOR=$6 +CROSSOVER=$7 +MUTATION_RATE=$8 +MUT_SELECTOR=$9 +MUTATION=${10} +REPLACEMENT=${11} +POPSIZE=${12} +OFFSPRINGSIZE=${13} +shift 13 || error "Not enough parameters" + +INSTANCE_PARAMS=$* +buckets=0 +# STDOUT=${LOG_DIR}/c${CONFIG_ID}_i${INSTANCE_ID}_s${SEED}.stdout +# STDERR=${LOG_DIR}/c${CONFIG_ID}_i${INSTANCE_ID}_s${SEED}.stderr +STDOUT="/dev/null" +STDERR="/dev/null" + +if [ ! -x "${EXE}" ]; then + error "${EXE}: not found or not executable (pwd: $(pwd))" +fi + +# If the program just prints a number, we can use 'exec' to avoid +# creating another process, but there can be no other commands after exec. +#exec $EXE ${FIXED_PARAMS} -i $INSTANCE ${INSTANCE_PARAMS} +# exit 1 +# +# Otherwise, save the output to a file, and parse the result from it. +# (If you wish to ignore segmentation faults you can use '{}' around +# the command.) +cmd="$EXE --problem=${INSTANCE} --instance=${INSTANCE} --seed=${SEED} ${CROSSOVER_RATE} ${CROSSOVER_SELECTOR} ${CROSSOVER} ${MUTATION_RATE} ${MUT_SELECTOR} ${MUTATION} ${REPLACEMENT} ${POPSIZE} ${OFFSPRINGSIZE} --max-evals=${buckets}" +# NOTE: irace seems to capture both stderr and stdout, so you should not output to stderr +echo ${cmd} > ${STDERR} +$cmd 2> ${STDERR} | tee ${STDOUT} + +# The following code is useless if the binary only output a single number on stdout. + +# This may be used to introduce a delay if there are filesystem +# issues. +# SLEEPTIME=1 +# while [ ! -s "${STDOUT}" ]; do +# sleep $SLEEPTIME +# let "SLEEPTIME += 1" +# done + +# This is an example of reading a number from the output. +# It assumes that the objective value is the first number in +# the first column of the last line of the output. +# if [ -s "${STDOUT}" ]; then +# COST=$(tail -n 1 ${STDOUT} | grep -e '^[[:space:]]*[+-]\?[0-9]' | cut -f1) +# echo "$COST" +# rm -f "${STDOUT}" "${STDERR}" +# exit 0 +# else +# error "${STDOUT}: No such file or directory" +# fi diff --git a/eo/contrib/irace/expe/beta/irace_files_pF/default.instances b/eo/contrib/irace/expe/beta/irace_files_pF/default.instances new file mode 100755 index 000000000..a0a1adfc3 --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pF/default.instances @@ -0,0 +1,48 @@ +## This is an example of specifying instances with a file. + +# Each line is an instance relative to trainInstancesDir +# (see scenario.txt.tmpl) and an optional sequence of instance-specific +# parameters that will be passed to target-runnerx when invoked on that +# instance. + +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 diff --git a/eo/contrib/irace/expe/beta/irace_files_pF/example.scen b/eo/contrib/irace/expe/beta/irace_files_pF/example.scen new file mode 100755 index 000000000..abebcbb6d --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pF/example.scen @@ -0,0 +1,227 @@ +###################################################### -*- mode: r -*- ##### +## Scenario setup for Iterated Race (irace). +############################################################################ + +## To use the default value of a parameter of iRace, simply do not set +## the parameter (comment it out in this file, and do not give any +## value on the command line). + +## File that contains the description of the parameters of the target +## algorithm. +parameterFile = "./fastga.param" + +## Directory where the programs will be run. +execDir = "." + +## File to save tuning results as an R dataset, either absolute path or +## relative to execDir. +# logFile = "./irace.Rdata" + +## Previously saved log file to recover the execution of irace, either +## absolute path or relative to the current directory. If empty or NULL, +## recovery is not performed. +# recoveryFile = "" + +## Directory where training instances are located; either absolute path or +## relative to current directory. If no trainInstancesFiles is provided, +## all the files in trainInstancesDir will be listed as instances. +trainInstancesDir = "." + +## File that contains a list of training instances and optionally +## additional parameters for them. If trainInstancesDir is provided, irace +## will search for the files in this folder. +trainInstancesFile = "./default.instances" + +## File that contains a table of initial configurations. If empty or NULL, +## all initial configurations are randomly generated. +# configurationsFile = "" + +## File that contains a list of logical expressions that cannot be TRUE +## for any evaluated configuration. If empty or NULL, do not use forbidden +## expressions. +forbiddenFile = "./forbidden.txt" + +## Script called for each configuration that executes the target algorithm +## to be tuned. See templates. +targetRunner = "./target-runner" + +## Number of times to retry a call to targetRunner if the call failed. +# targetRunnerRetries = 0 + +## Optional data passed to targetRunner. This is ignored by the default +## targetRunner function, but it may be used by custom targetRunner +## functions to pass persistent data around. +# targetRunnerData = "" + +## Optional R function to provide custom parallelization of targetRunner. +# targetRunnerParallel = "" + +## Optional script or R function that provides a numeric value for each +## configuration. See templates/target-evaluator.tmpl +# targetEvaluator = "" + +## Maximum number of runs (invocations of targetRunner) that will be +## performed. It determines the maximum budget of experiments for the +## tuning. +maxExperiments = 0 #100000 + +## Maximum total execution time in seconds for the executions of +## targetRunner. targetRunner must return two values: cost and time. +# maxTime = 60 + +## Fraction (smaller than 1) of the budget used to estimate the mean +## computation time of a configuration. Only used when maxTime > 0 +# budgetEstimation = 0.02 + +## Maximum number of decimal places that are significant for numerical +## (real) parameters. +digits = 2 + +## Debug level of the output of irace. Set this to 0 to silence all debug +## messages. Higher values provide more verbose debug messages. +# debugLevel = 0 + +## Number of iterations. +# nbIterations = 0 + +## Number of runs of the target algorithm per iteration. +# nbExperimentsPerIteration = 0 + +## Randomly sample the training instances or use them in the order given. +# sampleInstances = 1 + +## Statistical test used for elimination. Default test is always F-test +## unless capping is enabled, in which case the default test is t-test. +## Valid values are: F-test (Friedman test), t-test (pairwise t-tests with +## no correction), t-test-bonferroni (t-test with Bonferroni's correction +## for multiple comparisons), t-test-holm (t-test with Holm's correction +## for multiple comparisons). +# testType = "F-test" + +## Number of instances evaluated before the first elimination test. It +## must be a multiple of eachTest. +# firstTest = 5 + +## Number of instances evaluated between elimination tests. +# eachTest = 1 + +## Minimum number of configurations needed to continue the execution of +## each race (iteration). +# minNbSurvival = 0 + +## Number of configurations to be sampled and evaluated at each iteration. +# nbConfigurations = 0 + +## Parameter used to define the number of configurations sampled and +## evaluated at each iteration. +# mu = 5 + +## Confidence level for the elimination test. +# confidence = 0.95 + +## If the target algorithm is deterministic, configurations will be +## evaluated only once per instance. +# deterministic = 0 + +## Seed of the random number generator (by default, generate a random +## seed). +# seed = NA + +## Number of calls to targetRunner to execute in parallel. Values 0 or 1 +## mean no parallelization. +# parallel = 0 + +## Enable/disable load-balancing when executing experiments in parallel. +## Load-balancing makes better use of computing resources, but increases +## communication overhead. If this overhead is large, disabling +## load-balancing may be faster. +# loadBalancing = 1 + +## Enable/disable MPI. Use Rmpi to execute targetRunner in parallel +## (parameter parallel is the number of slaves). +# mpi = 0 + +## Specify how irace waits for jobs to finish when targetRunner submits +## jobs to a batch cluster: sge, pbs, torque or slurm. targetRunner must +## submit jobs to the cluster using, for example, qsub. +# batchmode = 0 + +## Enable/disable the soft restart strategy that avoids premature +## convergence of the probabilistic model. +# softRestart = 1 + +## Soft restart threshold value for numerical parameters. If NA, NULL or +## "", it is computed as 10^-digits. +# softRestartThreshold = "" + +## Directory where testing instances are located, either absolute or +## relative to current directory. +# testInstancesDir = "" + +## File containing a list of test instances and optionally additional +## parameters for them. +# testInstancesFile = "" + +## Number of elite configurations returned by irace that will be tested if +## test instances are provided. +# testNbElites = 1 + +## Enable/disable testing the elite configurations found at each +## iteration. +# testIterationElites = 0 + +## Enable/disable elitist irace. +# elitist = 1 + +## Number of instances added to the execution list before previous +## instances in elitist irace. +# elitistNewInstances = 1 + +## In elitist irace, maximum number per race of elimination tests that do +## not eliminate a configuration. Use 0 for no limit. +# elitistLimit = 2 + +## User-defined R function that takes a configuration generated by irace +## and repairs it. +# repairConfiguration = "" + +## Enable the use of adaptive capping, a technique designed for minimizing +## the computation time of configurations. This is only available when +## elitist is active. +# capping = 0 + +## Measure used to obtain the execution bound from the performance of the +## elite configurations: median, mean, worst, best. +# cappingType = "median" + +## Method to calculate the mean performance of elite configurations: +## candidate or instance. +# boundType = "candidate" + +## Maximum execution bound for targetRunner. It must be specified when +## capping is enabled. +# boundMax = 0 + +## Precision used for calculating the execution time. It must be specified +## when capping is enabled. +# boundDigits = 0 + +## Penalization constant for timed out executions (executions that reach +## boundMax execution time). +# boundPar = 1 + +## Replace the configuration cost of bounded executions with boundMax. +# boundAsTimeout = 1 + +## Percentage of the configuration budget used to perform a postselection +## race of the best configurations of each iteration after the execution +## of irace. +# postselection = 0 + +## Enable/disable AClib mode. This option enables compatibility with +## GenericWrapper4AC as targetRunner script. +# aclib = 0 + +## END of scenario file +############################################################################ + diff --git a/eo/contrib/irace/expe/beta/irace_files_pF/fastga.param b/eo/contrib/irace/expe/beta/irace_files_pF/fastga.param new file mode 100755 index 000000000..2e1d9fe1c --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pF/fastga.param @@ -0,0 +1,12 @@ +# name switch type range +# continuator "--continuator=" c (0) +crossoverrate "--crossover-rate=" r (0,1) +crossselector "--cross-selector=" c (0,1,2,3,4,5,6) +# aftercrossselector "--aftercross-selector=" c (0) +crossover "--crossover=" c (0,1,2,3,4,5,6,7,8,9) +mutationrate "--mutation-rate=" r (0,1) +mutselector "--mut-selector=" c (0,1,2,3,4,5,6) +mutation "--mutation=" c (0,1,2,3,4,5,6,7,8,9,10) +replacement "--replacement=" c (0,1,2,3,4,5,6,7,8,9,10) +popsize "--pop-size=" i (1,50) +offspringsize "--offspring-size=" i (1,50) diff --git a/eo/contrib/irace/expe/beta/irace_files_pF/target-runner b/eo/contrib/irace/expe/beta/irace_files_pF/target-runner new file mode 100755 index 000000000..7a990a8ec --- /dev/null +++ b/eo/contrib/irace/expe/beta/irace_files_pF/target-runner @@ -0,0 +1,96 @@ +#!/bin/bash +############################################################################### +# This script is the command that is executed every run. +# Check the examples in examples/ +# +# This script is run in the execution directory (execDir, --exec-dir). +# +# PARAMETERS: +# $1 is the candidate configuration number +# $2 is the instance ID +# $3 is the seed +# $4 is the instance name +# The rest ($* after `shift 4') are parameters to the run +# +# RETURN VALUE: +# This script should print one numerical value: the cost that must be minimized. +# Exit with 0 if no error, with 1 in case of error +############################################################################### +error() { + echo "`TZ=UTC date`: $0: error: $@" + exit 1 +} + + +EXE="./fastga" +LOG_DIR="irace_logs" + +FIXED_PARAMS="--problem=0" +#MAX_EVALS=2 +# +CONFIG_ID=$1 +INSTANCE_ID=$2 +SEED=$3 +INSTANCE=$(echo $4 | sed 's/\//\n/g'|tail -n 1) +CROSSOVER_RATE=$5 +CROSSOVER_SELECTOR=$6 +CROSSOVER=$7 +MUTATION_RATE=$8 +MUT_SELECTOR=$9 +MUTATION=${10} +REPLACEMENT=${11} +POPSIZE=${12} +OFFSPRINGSIZE=${13} +shift 13 || error "Not enough parameters" + +INSTANCE_PARAMS=$* + +buckets=0 +#dim=(20 20 16 48 25 32 128 128 128 50 100 150 128 192 192 192 256 75 150) +#size= $( echo $(echo $13 | cut -d'=' -f2)) +#pb=$(echo $(echo $13 | cut -d'=' -f2)) +#maxevals=$( echo ${dim[$pb]}) +# STDOUT=${LOG_DIR}/c${CONFIG_ID}_i${INSTANCE_ID}_s${SEED}.stdout +# STDERR=${LOG_DIR}/c${CONFIG_ID}_i${INSTANCE_ID}_s${SEED}.stderr +STDOUT="/dev/null" +STDERR="/dev/null" + +if [ ! -x "${EXE}" ]; then + error "${EXE}: not found or not executable (pwd: $(pwd))" +fi + +# If the program just prints a number, we can use 'exec' to avoid +# creating another process, but there can be no other commands after exec. +#exec $EXE ${FIXED_PARAMS} -i $INSTANCE ${INSTANCE_PARAMS} +# exit 1 +# +# Otherwise, save the output to a file, and parse the result from it. +# (If you wish to ignore segmentation faults you can use '{}' around +# the command.) + +cmd="$EXE ${FIXED_PARAMS} --instance=${INSTANCE} --seed=${SEED} ${CROSSOVER_RATE} ${CROSSOVER_SELECTOR} ${CROSSOVER} ${MUTATION_RATE} ${MUT_SELECTOR} ${MUTATION} ${REPLACEMENT} ${POPSIZE} ${OFFSPRINGSIZE} --max-evals=${buckets}" +# NOTE: irace seems to capture both stderr and stdout, so you should not output to stderr +echo ${cmd} > ${STDERR} +$cmd 2> ${STDERR} | tee ${STDOUT} + +# The following code is useless if the binary only output a single number on stdout. + +# This may be used to introduce a delay if there are filesystem +# issues. +# SLEEPTIME=1 +# while [ ! -s "${STDOUT}" ]; do +# sleep $SLEEPTIME +# let "SLEEPTIME += 1" +# done + +# This is an example of reading a number from the output. +# It assumes that the objective value is the first number in +# the first column of the last line of the output. +# if [ -s "${STDOUT}" ]; then +# COST=$(tail -n 1 ${STDOUT} | grep -e '^[[:space:]]*[+-]\?[0-9]' | cut -f1) +# echo "$COST" +# rm -f "${STDOUT}" "${STDERR}" +# exit 0 +# else +# error "${STDOUT}: No such file or directory" +# fi diff --git a/eo/contrib/irace/expe/beta/parseA_irace_bests.py b/eo/contrib/irace/expe/beta/parseA_irace_bests.py new file mode 100755 index 000000000..7c48f8049 --- /dev/null +++ b/eo/contrib/irace/expe/beta/parseA_irace_bests.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +#parse data1 +import os +import re +import sys + +print("ecdf,id,crossover-rate,cross-selector,crossover,mutation-rate,mut-selector,mutation,replacement,pop-size,offspring-size") + + +#give the path of one experiment +argv=sys.argv[1] +for datadir in os.listdir(argv): + #if(os.path.isdir(os.path.join(argv,datadir))): check if argv/datadir is a directory + if(datadir.find("results_irace")>=0): #check if the directory is one JOB + with open(os.path.join("./",argv,datadir,"irace.log")) as fd: + data = fd.readlines() + + # Find the last best configuration + bests = [line.strip() for line in data if "Best-so-far" in line] + #print(datadir,bests) + best = bests[-1].split() + best_id, best_perf = best[2], best[5] + # print(best_id,best_perf) + + # Filter the config detail + configs = [line.strip() for line in data if "--crossover-rate=" in line and best_id in line] + # print(configs) + # Format as CSV + algo = re.sub("\-\-\S*=", ",", configs[0]) + csv_line = best_perf + "," + algo + print(csv_line.replace(" ","")) \ No newline at end of file diff --git a/eo/contrib/irace/expe/beta/parseF_irace_bests.py b/eo/contrib/irace/expe/beta/parseF_irace_bests.py new file mode 100755 index 000000000..39c3d44cc --- /dev/null +++ b/eo/contrib/irace/expe/beta/parseF_irace_bests.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +#parse data1 +import os +import re +import sys +#print("pb,ecdf,id,crossover-rate,cross-selector,crossover,mutation-rate,mut-selector,mutation,replacement") #plan1 +print("pb,ecdf,id,crossover-rate,cross-selector,crossover,mutation-rate,mut-selector,mutation,replacement,pop-size,offspring-size") + + +#give the path of one experiment +argv=sys.argv[1] +for datadir in os.listdir(argv): + #if(os.path.isdir(os.path.join(argv,datadir))): check if argv/datadir is a directory + if(datadir.find("results_irace")>=0): #check if the directory is one JOB + for pb_dir in os.listdir(os.path.join(argv,datadir)): + if "results_problem" in pb_dir: + pb_id=pb_dir.replace("results_problem_","") + with open(os.path.join("./",argv,datadir,pb_dir,"irace.log")) as fd: + data = fd.readlines() + + # Find the last best configuration + bests = [line.strip() for line in data if "Best-so-far" in line] + #print(datadir,bests) + best = bests[-1].split() + best_id, best_perf = best[2], best[5] + # print(best_id,best_perf) + + # Filter the config detail + configs = [line.strip() for line in data if "--crossover-rate=" in line and best_id in line] + # print(configs) + + # Format as CSV + algo = re.sub("\-\-\S*=", ",", configs[0]) + csv_line = pb_id + "," + best_perf + "," + algo + print(csv_line.replace(" ","")) diff --git a/eo/contrib/irace/expe/beta/planA/r_iA.sh b/eo/contrib/irace/expe/beta/planA/r_iA.sh new file mode 100755 index 000000000..b9ca24be8 --- /dev/null +++ b/eo/contrib/irace/expe/beta/planA/r_iA.sh @@ -0,0 +1,34 @@ +#!/bin/bash +#run once each problem + +echo "-------------------------Start the JOB : $(date --iso-8601=seconds)" +. /etc/profile.d/modules.sh +export MODULEPATH=${MODULEPATH}${MODULEPATH:+:}/opt/dev/Modules/Anaconda:/opt/dev/Modules/Compilers:/opt/dev/Modules/Frameworks:/opt/dev/Modules/Libraries:/opt/dev/Modules/Tools:/opt/dev/Modules/IDEs:/opt/dev/Modules/MPI +module load LLVM/clang-llvm-10.0 +module load R + +dir=$1 +run=$2 +budget_irace=$3 +buckets=$4 +myhome=$5 +cp -r ${myhome}/R . +cp -r ${myhome}/irace_files_pA . +#cp -r /scratchbeta/zhenga/irace_files . +#chmod u+x ./fastga +outdir="${run}_$(date --iso-8601=seconds)_results_irace" +rundir=${dir}/${outdir} +mkdir -p ${rundir} +# Fore some reason, irace absolutely need those files... +cp ${myhome}/code/paradiseo/eo/contrib/irace/release/fastga ${rundir} +cat ./irace_files_pA/example.scen | sed "s%\".%\"${rundir}%g" | sed "s/maxExperiments = 0/maxExperiments=${budget_irace}/" > ${rundir}/example.scen +cp ./irace_files_pA/default.instances ${rundir} +cp ./irace_files_pA/fastga.param ${rundir} +cp ./irace_files_pA/forbidden.txt ${rundir} +cat ./irace_files_pA/target-runner | sed "s/buckets=0/buckets=${buckets}/" > ${rundir}/target-runner +chmod u+x ${rundir}/target-runner + +echo "---start $(date)" +time -p ./R/x86_64-pc-linux-gnu-library/3.6/irace/bin/irace --scenario ${rundir}/example.scen > ${rundir}/irace.log +echo "---end $(date)" +echo "End the JOB : $(date --iso-8601=seconds)------------------------------" diff --git a/eo/contrib/irace/expe/beta/planA/riaA.sh b/eo/contrib/irace/expe/beta/planA/riaA.sh new file mode 100755 index 000000000..c28359626 --- /dev/null +++ b/eo/contrib/irace/expe/beta/planA/riaA.sh @@ -0,0 +1,25 @@ +#!/bin/bashi +myhome=$1 +scratchpath=$2 +mexp=$3 +mevals=$4 +date -Iseconds +echo "STARTS" +dir=${scratchpath}/dataFAR/dataA +#dir=${HOME}/plan4/${name} +#cat ${HOME}/irace_files_pA/example.scen |sed "s/maxExperiments = 0/maxExperiments = ${mexp}/" > ${HOME}/irace_files_pA/example.scen + +mkdir -p ${dir} +outdir="${dir}/dataA_maxExp=${mexp}_maxEv=${mevals}_$(date --iso-8601=seconds)" +mkdir -p ${outdir} +for r in $(seq 2); do + echo "Run $r/15"; + cmd="qsub -N iraceA_maxEv_${r} -q beta -l select=1:ncpus=1 -l walltime=00:30:00 -- ${scratchpath}/planA/r_iA.sh ${outdir} ${r} ${mexp} ${mevals} ${myhome}" + #cmd="bash ./r_iA_buckets.sh ${outdir} ${r} ${mexp} ${mevals}" + echo $cmd + time -p $cmd +done +echo "DONE" +#cat ${HOME}/irace_files_pA/example.scen |sed "s/maxExperiments = ${mexp}/maxExperiments = 0/" > ${HOME}/irace_files_pA/example.scen +date -Iseconds + diff --git a/eo/contrib/irace/expe/beta/planF/r_iF.sh b/eo/contrib/irace/expe/beta/planF/r_iF.sh new file mode 100755 index 000000000..fb9246746 --- /dev/null +++ b/eo/contrib/irace/expe/beta/planF/r_iF.sh @@ -0,0 +1,37 @@ +#!/bin/bash +#run once each problem +dir=$1 +run=$2 +budget_irace=$3 +buckets=$4 +myhome=$5 + +echo "---------------start JOB ${run} $(date --iso-8601=seconds)" +. /etc/profile.d/modules.sh +export MODULEPATH=${MODULEPATH}${MODULEPATH:+:}/opt/dev/Modules/Anaconda:/opt/dev/Modules/Compilers:/opt/dev/Modules/Frameworks:/opt/dev/Modules/Libraries:/opt/dev/Modules/Tools:/opt/dev/Modules/IDEs:/opt/dev/Modules/MPI +module load LLVM/clang-llvm-10.0 +module load R + +cp -r ${myhome}/R . +cp -r ${myhome}/irace_files_pF . +#cp -r /scratchbeta/zhenga/irace_files . +#chmod u+x ./fastga +outdir="${run}_$(date --iso-8601=seconds)_results_irace" +for pb in $(seq 0 18) ; do + echo "Problem ${pb}... " + res="results_problem_${pb}" + mkdir -p ${dir}/${outdir}/${res} + # Fore some reason, irace absolutely need those files... + cp ${myhome}/code/paradiseo/eo/contrib/irace/release/fastga ${dir}/${outdir}/${res} + cat ./irace_files_pF/example.scen | sed "s%\".%\"${dir}/${outdir}/${res}%g" | sed "s/maxExperiments = 0/maxExperiments=${budget_irace}/" > ${dir}/${outdir}/${res}/example.scen + cp ./irace_files_pF/default.instances ${dir}/${outdir}/${res} + cp ./irace_files_pF/fastga.param ${dir}/${outdir}/${res} + cp ./irace_files_pF/forbidden.txt ${dir}/${outdir}/${res} + cat ./irace_files_pF/target-runner | sed "s/--problem=0/--problem=${p}/" | sed "s/buckets=0/buckets=${buckets}/" > ${dir}/${outdir}/${res}/target-runner + chmod u+x ${dir}/${outdir}/${res}/target-runner + + echo "---start $(date)" + time -p ./R/x86_64-pc-linux-gnu-library/3.6/irace/bin/irace --scenario ${dir}/${outdir}/${res}/example.scen > ${dir}/${outdir}/${res}/irace.log + echo "---end $(date)" +done +echo "end JOB ${run} $(date --iso-8601=seconds)---------------" diff --git a/eo/contrib/irace/expe/beta/planF/riaF.sh b/eo/contrib/irace/expe/beta/planF/riaF.sh new file mode 100755 index 000000000..5791a1a1d --- /dev/null +++ b/eo/contrib/irace/expe/beta/planF/riaF.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +date -Iseconds +echo "STARTS" +myhome=$1 +scratchpath=$2 +#dir=${HOME}/plan2/${name} +mexp=$3 #budget irace +mevals=$4 #budget fastga +name="dataF_maxExp=${mexp}_maxEv=${mevals}_$(date --iso-8601=seconds)" +dir=${scratchpath}/dataFAR/dataF/${name} +mkdir -p ${dir} + +for r in $(seq 2); do + echo "Run $r/15"; + #date -Iseconds + #cmd="qsub -N irace_${runs}_${buckets}" -q beta -l select=1:ncpus=1 -l walltime=00:04:00 --${HOME}/run_irace.sh ${dir} + cmd="qsub -N iraceF_${mevals}_run=${r} -q beta -l select=1:ncpus=1 -l walltime=00:30:00 -- ${scratchpath}/planF/r_iF.sh ${dir} ${r} ${mexp} ${mevals} ${myhome}" + #time -p bash ${HOME}/plan2/run_irace2.sh ${dir} ${r} &> ${dir}/erreur_${r}.txt + #bash ${HOME}/test/r_i.sh + echo $cmd + $cmd + #date -Iseconds +done + +#echo "DONE" +#date -Iseconds +#echo $(pwd) diff --git a/eo/contrib/irace/expe/beta/readme.txt b/eo/contrib/irace/expe/beta/readme.txt new file mode 100755 index 000000000..6d53b7d90 --- /dev/null +++ b/eo/contrib/irace/expe/beta/readme.txt @@ -0,0 +1,101 @@ +1. INTRODUCTION + +The aim of all the scripts is to make the experimental plans for Algorithm Configuration for Genetic Algorithms by using a fully modular benchmarking pipeline design of this article https://arxiv.org/abs/2102.06435 . + +Plan A is an experimental plan for finding an efficient algorithm for all the functions that we consider. + +Plan F is an experimental plan for finding an efficient algorithm for each function that we consider. + +Plan R is an experimental plan for getting random algorithms. + +2. VOCABULARIES + +* maxExp : means maximum Experiments, the budget for irace +* maxEv : means maximum evaluation, the budget for FastGA algorithms + +*dataFAR : directory which we store all the experiment data of Plan F and Plan A, created when you run run_exp.sh + +* dataA, dataF +dataA is a directory which we store all the runs of an experiment plan for several budgets +eg : /dataA/planA_maxExp=*_maxEv=**_$(data), * is a value of maxExp, and ** is a value of maxEv + + +*fastga_results_all : directory which we store all the data for validation runs. It constains only 3 subdirectories (fastga_results_planF, fastga_results_planA, fastga_results_random), created by running run_exp.sh + +* fastga_results_planF, fastga_results_planA, fastga_results_random +Each directory store the data for validation runs of each experiment plan. +fastga_random directory are created by running run_exp.sh +fastga_results_planF and fastag_results_planA are created only after you have data in the dataA or dataF directories. + + +* planA_*, planF_* +If the planA_* or planF_* are in the dataFAR directory, the directory contains the data of experimental plan. This means that each plan contains the result of 15 runs of irace stored in irace.log file, and the data are provided by run_exp.sh. + +If the planA_* or planF_* directories are in the fastga_results_planA or fastga_results_planF, these directories contain the data of 50 validation runs by running all the best algorithms of each plan stores in dataFAR. The data are provided by running run_res.sh + + +*fastag_all_results : contains the directories of the validation run data. + +*fastga_results_planF, fastga_results_planA and fastga_results_random contain respectively the validation run data of Plan F, Plan A and Plan R. + + +3. DESCRIPTION + +The directory which you load all the scripts contains : + + * bash files : + -run_res.sh : submit to the cluster all the experiment plan, get all the data we need for the plan F, plan A and plan R. + -run_exp.sh : submit to the cluster for getting all the data for validation runs of each data A and data F provided by running run_res.sh + -run_random.sh : script for getting random algorithms and the data for validation runs for each problem + -testrandom.sh : change the budget fastga (maxEv) in this file if you need, by running this file, you submit plan R job in the cluster + + -csv_all_bests.sh : script for getting all the best configurations of each plan in a dataF or a dataA directories + + -run_elites_planA.sh : script for validation runs of plan A by giving a csv file of each best configuration. This file is provided by running parseA_irace_bests.py. + -run_elites_planB.sh + -fastga_elites_all.sh : run this file, by giving a directory csv_plan* of csv files ( must only contains the csv file of the same plan, eg : csv_planF) and a run_elites_plan*.sh (* is the name of the plan, eg run_elites_planF.sh), by running this file you get all the validation runs of each csv file. Each csv file contains the best configuration (you get these csv files by running csv_all_bests.sh) + + * python files : + -parseA_irace_bests.py : for parsing the irace.log file of each data provided by running irace. By giving a bounch of directories of one experiment + -parseF_irace_bests.py + + * 4 directories : + -irace_files_pA : + -default.instances + -example.scen + -fastga.param + -forbidden.txt + -target-runner + + -irace_files_pF : + -default.instances : + -example.scen + -fastga.param + -forbidden.txt + -target-runner + + -planA : + -riaA.sh : for running 15 times r_iA.sh file by submitting to the mesu cluster + -r_iA.sh : for running irace for all the problems + + -planF : + -riaF.sh : for running 15 times r_iF.sh file by submitting to the mesu cluster + -r_iF.sh : for running irace for each problem we considered + + +The directories planA, planF contain the scripts to run one experiment of Plan A and Plan F. + +The directories irace_files_pA and irace_files_pA contain the scripts needing for calling irace for one experiment of Plan A and Plan F. [Look at the irace package : User Guide for more information] + + +5. CONCLUSION + +For getting all the experiment data and the validation run data run run_exp.sh file first, after run_exp.sh file finished to execute and there is all the data in the dataFAR (ie : in the cluster, all the jobs finished to execute) run_res.sh data. + +Warning : run_exp.sh may take few days or few weeks depending on the Budget you ask, do not run_res.sh if in dataFAR there are data which are not finished to execute in the cluster, or jobs killed. Do not forget to remove directories of plan which are not complete. + + + + + + diff --git a/eo/contrib/irace/expe/beta/run_elites_planA.sh b/eo/contrib/irace/expe/beta/run_elites_planA.sh new file mode 100755 index 000000000..8cc3b146a --- /dev/null +++ b/eo/contrib/irace/expe/beta/run_elites_planA.sh @@ -0,0 +1,61 @@ +#!/bin/bash +#instance = seed +echo "-----------------Start $(date)" +. /etc/profile.d/modules.sh +export MODULEPATH=${MODULEPATH}${MODULEPATH:+:}/opt/dev/Modules/Anaconda:/opt/dev/Modules/Compilers:/opt/dev/Modules/Frameworks:/opt/dev/Modules/Libraries:/opt/dev/Modules/Tools:/opt/dev/Modules/IDEs:/opt/dev/Modules/MPI +module load LLVM/clang-llvm-10.0 + +csv_file=$1 #contains all the configs of all the problems of one experiments +mexp=$2 +mevals=$3 +path=$4 +# Number of runs (=seeds). +runs=50 + +# You most probably want to run on release builds. +exe="/home/zhenga/fastga" +plan=$(echo ${csv_file} | sed "s/results_irace_plan//") +outdir="${path}/plan4_maxExp=${mexp}_maxEv=${mevals}_$(date --iso-8601=minutes)_results_elites_all" +mkdir -p ${outdir} +mkdir -p ${outdir}/raw +mkdir -p ${outdir}/raw/data +mkdir -p ${outdir}/raw/logs + +n=0 +algoid=0 +for line in $(cat ${csv_file}| sed 1,1d | cut -s -d"," -f3-11 ); do + a=($(echo $line | sed "s/,/ /g")) + algo="--crossover-rate=${a[0]} --cross-selector=${a[1]} --crossover=${a[2]} --mutation-rate=${a[3]} --mut-selector=${a[4]} --mutation=${a[5]} --replacement=${a[6]} --pop-size=${a[7]} --offspring-size=${a[8]}" + + #perc=$(echo "scale=3;${n}/(285)*100.0" | bc) + #echo "${perc}% : algo ${algoid}/285" + # echo -n "Runs: " + for pb in $(seq 0 18) ; do + name_dir="pb=${pb}_$(echo "${algo}" | sed 's/--//g' | sed 's/ /_/g')" + mkdir -p ${outdir}/raw/data/${name_dir} + mkdir -p ${outdir}/raw/logs/${name_dir} + for seed in $(seq ${runs}) ; do # Iterates over runs/seeds. + # This is the command to be ran. + #cmd="${exe} --full-log=1 --problem=${pb} --seed=${seed} ${algo}" + cmd="${exe} --problem=${pb} --seed=${seed} --instance=${seed} ${algo}" + #echo ${cmd} # Print the command. + # Forge a directory/log file name + # (remove double dashs and replace spaces with underscore). + name_run="pb=${pb}_seed=${seed}_$(echo "${algo}" | sed 's/--//g' | sed 's/ /_/g')" + # echo $name_run + # Actually start the command. + + ${cmd} > "${outdir}/raw/data/${name_dir}/${name_run}.dat" 2> "${outdir}/raw/logs/${name_dir}/${name_run}.log" + # Check for the most common problem in the log file. + #cat "${outdir}/raw/logs/${name_run}.log" | grep "illogical performance" + done # seed + n=$(($n+1)) + done + algoid=$(($algoid+1)) +done + +# Move IOH logs in the results directory. +#mv ./FastGA_* ${outdir} + +echo "Done $(date) -----------------------" +#date diff --git a/eo/contrib/irace/expe/beta/run_elites_planF.sh b/eo/contrib/irace/expe/beta/run_elites_planF.sh new file mode 100755 index 000000000..1c8b20a0a --- /dev/null +++ b/eo/contrib/irace/expe/beta/run_elites_planF.sh @@ -0,0 +1,59 @@ +#!/bin/bash +#instance = seed +echo "-----------------Start $(date)" +. /etc/profile.d/modules.sh +export MODULEPATH=${MODULEPATH}${MODULEPATH:+:}/opt/dev/Modules/Anaconda:/opt/dev/Modules/Compilers:/opt/dev/Modules/Frameworks:/opt/dev/Modules/Libraries:/opt/dev/Modules/Tools:/opt/dev/Modules/IDEs:/opt/dev/Modules/MPI +module load LLVM/clang-llvm-10.0 + +csv_file=$1 #contains all the configs of all the problems of one experiments +mexp=$2 +mevals=$3 +path=$4 +# Number of runs (=seeds). +runs=50 + +# You most probably want to run on release builds. +exe="/home/${USER}/fastga" +plan=$(echo ${csv_file} | cut -d / -f3 | sed "s/results_irace_plan//") +outdir="${path}/plan${plan[@]:0:1}_maxExp=${mexp}_maxEv=${mevals}_$(date --iso-8601=minutes)_results_elites_all" +mkdir -p ${outdir} +mkdir -p ${outdir}/raw +mkdir -p ${outdir}/raw/data +mkdir -p ${outdir}/raw/logs + +n=0 +algoid=0 +for line in $(cat ${csv_file}| sed 1,1d ); do + a=($(echo $line | sed "s/,/ /g")) + algo="--crossover-rate=${a[3]} --cross-selector=${a[4]} --crossover=${a[5]} --mutation-rate=${a[6]} --mut-selector=${a[7]} --mutation=${a[8]} --replacement=${a[9]} --pop-size=${a[10]} --offspring-size=${a[11]}" + + #perc=$(echo "scale=3;${n}/(285)*100.0" | bc) + #echo "${perc}% : algo ${algoid}/285" + # echo -n "Runs: " + name_dir="pb=${a[0]}_$(echo "${algo}" | sed 's/--//g' | sed 's/ /_/g')" + mkdir -p ${outdir}/raw/logs/${name_dir} + mkdir -p ${outdir}/raw/data/${name_dir} + for seed in $(seq ${runs}) ; do # Iterates over runs/seeds. + # This is the command to be ran. + #cmd="${exe} --full-log=1 --problem=${pb} --seed=${seed} ${algo}" + cmd="${exe} --problem=${a[0]} --seed=${seed} --instance=${seed} ${algo}" + #echo ${cmd} # Print the command. + # Forge a directory/log file name + # (remove double dashs and replace spaces with underscore). + name_run="pb=${a[0]}_seed=${seed}_$(echo "${algo}" | sed 's/--//g' | sed 's/ /_/g')" + # echo $name_run + # Actually start the command. + ${cmd} > "${outdir}/raw/data/${name_dir}/${name_run}.dat" 2> "${outdir}/raw/logs/${name_dir}/${name_run}.log" + # Check for the most common problem in the log file. + #cat "${outdir}/raw/logs/${name_run}.log" | grep "illogical performance" + done # seed + + n=$(($n+1)) + algoid=$(($algoid+1)) +done + +# Move IOH logs in the results directory. +#mv ./FastGA_* ${outdir} + +echo "Done $(date) -----------------------" +#date diff --git a/eo/contrib/irace/expe/beta/run_exp.sh b/eo/contrib/irace/expe/beta/run_exp.sh new file mode 100644 index 000000000..c3669a1c7 --- /dev/null +++ b/eo/contrib/irace/expe/beta/run_exp.sh @@ -0,0 +1,12 @@ +#!/bin/bash +lexp=(300 600 1000 10000) +levals=(100 500 1000) +myscratchpath=/scratchbeta/$USER +myhome=${HOME} +for exp in ${lexp[@]} ; do + for evals in ${levals[@]} ; do + bash ./planF/riaF.sh ${myhome} ${myscratchpath} ${exp} ${evals} + bash ./planA/riaA.sh ${myhome} ${myscratchpath} ${exp} ${evals} + done +done +bash testrandom.sh ${myhome} ${scratchpath} ${levals[@]} diff --git a/eo/contrib/irace/expe/beta/run_random.sh b/eo/contrib/irace/expe/beta/run_random.sh new file mode 100755 index 000000000..f509e4f3a --- /dev/null +++ b/eo/contrib/irace/expe/beta/run_random.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# Number of runs (=seeds). +runs=5 +basename=$1 +mevals=$2 +nbAlgo=2 +echo "Start JOB maxEv= $mevals $(date -Iseconds) ----------------------" +. /etc/profile.d/modules.sh +export MODULEPATH=${MODULEPATH}${MODULEPATH:+:}/opt/dev/Modules/Anaconda:/opt/dev/Modules/Compilers:/opt/dev/Modules/Frameworks:/opt/dev/Modules/Libraries:/opt/dev/Modules/Tools:/opt/dev/Modules/IDEs:/opt/dev/Modules/MPI +module load LLVM/clang-llvm-10.0 +cp ${HOME}/code/paradiseo/eo/contrib/irace/release/fastga . +# You most probably want to run on release builds. +exe="./fastga" + +#outdir="/scratchbeta/$USER/$(date --iso-8601=minutes)_results_randoms" +outdir="${basename}/maxEv=${mevals}_nbAlgo=${nbAlgo}_$(date --iso-8601=minutes)_results_randoms" +mkdir -p ${outdir} +n=1 +algoid=0 +for algoid in $(seq ${nbAlgo}); do + #date + r1=$(echo "scale=2 ; ${RANDOM}/32767" | bc) + r2=$(echo "scale=2 ; ${RANDOM}/32767" | bc) + a=(${r1} $((RANDOM%7)) $((RANDOM%10)) ${r2} $((RANDOM%7)) $((RANDOM%11)) $((RANDOM%11)) $((RANDOM%50 +1)) $((RANDOM%50 +1)) ) + #condition for value of replacement, pop-size and offspringsize + while [[ (1 -lt ${a[6]} && ${a[7]} -lt ${a[8]}) || ( ${a[6]} -eq 1 && ${a[7]} -ne ${a[8]}) ]] + do + #echo "get in ------------------replacement ${a[6]} popsize ${a[7]} offspringsize ${a[8]}" + r1=$(echo "scale=2 ; ${RANDOM}/32767" | bc) + r2=$(echo "scale=2 ; ${RANDOM}/32767" | bc) + a=(${r1} $((RANDOM%7)) $((RANDOM%10)) ${r2} $((RANDOM%7)) $((RANDOM%11)) $((RANDOM%11)) $((RANDOM%50 +1)) $((RANDOM%50 +1))) + done + algo="--crossover-rate=${a[0]} --cross-selector=${a[1]} --crossover=${a[2]} --mutation-rate=${a[3]} --mut-selector=${a[4]} --mutation=${a[5]} --replacement=${a[6]} --pop-size=${a[7]} --offspring-size=${a[8]}" + echo " start algo ${a}------ $(date --iso-8601=minutes)" + algodir="$(echo "${algo}" | sed 's/--//g' | sed 's/ /_/g')" + for pb in $(seq 0 18) ; do + perc=$(echo "scale=3;${n}/(10*18)*10.0" | bc) + #echo "${perc}% : algo ${algoid}/100, problem ${pb}/18 $(date --iso-8601=minutes)" + # echo -n "Runs: " + name_dir="pb=${pb}_$(echo "${algo}" | sed 's/--//g' | sed 's/ /_/g')" + + mkdir -p ${outdir}/${algodir}/data/${name_dir} + mkdir -p ${outdir}/${algodir}/logs/${name_dir} + + for seed in $(seq ${runs}) ; do # Iterates over runs/seeds. + # This is the command to be ran. + cmd="${exe} --problem=${pb} --seed=${seed} --instance=${seed} ${algo} --max-evals=${mevals}" + name_run="pb=${pb}_seed=${seed}_$(echo "${algo}" | sed 's/--//g' | sed 's/ /_/g')" + # echo $name_run + #echo $algo + + ${cmd} > ${outdir}/${algodir}/data/${name_dir}/${name_run}.dat 2> ${outdir}/${algodir}/logs/${name_dir}/${name_run}.log + # Check for the most common problem in the log file. + #cat "${outdir}/raw/logs/${name_run}.log" | grep "illogical performance" + done # seed + # echo "" + + n=$(($n+1)) + done # pb + echo "end algo $(date -Iseconds) " + algoid=$(($algoid+1)) +done + + + +echo "------------------------------------Done $mevals $(date -Iseconds) " + diff --git a/eo/contrib/irace/expe/beta/run_res.sh b/eo/contrib/irace/expe/beta/run_res.sh new file mode 100644 index 000000000..de5b352ad --- /dev/null +++ b/eo/contrib/irace/expe/beta/run_res.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +#get csv file, parse dataF in a csv file +dir=/scratchbeta/$USER/dataFAR +listdir=$(echo $(ls ${dir})) + +for data in ${listdir[@]} ; do + file_py="parse${data: -1}_irace_bests.py" + path="${dir}/${data}" + cmd="bash ./csv_all_bests.sh ${path} ${file_py}" + echo $cmd + $cmd +done + +#get validation run of each config + +dir=/scratchbeta/$USER/csv_FA +listdir=$(echo $(ls ${dir})) +echo ${listdir[@]} +for csvdir in ${listdir[@]} ; do + csvpath="${dir}/${csvdir}" + file_py="./run_elites_plan${csvdir: -1}.sh" + cmd="bash ./fastga_elites_all.sh ${csvpath} ${file_py}" + echo $cmd + $cmd +done diff --git a/eo/contrib/irace/expe/beta/testrandom.sh b/eo/contrib/irace/expe/beta/testrandom.sh new file mode 100644 index 000000000..5c6880594 --- /dev/null +++ b/eo/contrib/irace/expe/beta/testrandom.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#tab=(15000 20000 30000 40000) +#tab=(100 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 10000) +myhome=$1 +scratchpath=$2 +tab=${@:3} +#echo ${tab[@]} +outdir="/scratchbeta/$USER/fastga_results_all/fastga_results_random" +mkdir -p ${outdir} #results of random experiment +for evals in ${tab[@]}; do + #evalsdir="${name}/maxEv=${evals}" + #mkdir -p ${evalsdir} + #{ time -p bash /home/$USER/run_random.sh ${name} ${i} 50 ; } &> "${name}/sortie5_${j}_maxExp=${i}.txt" + #cmd="qsub -N iraceR_maxEv=${evals} -q beta -l select=1:ncpus=1 -l walltime=00:30:00 -- /scratchbeta/$USER/run_random.sh ${outdir} ${evals}" + $cmd + +done