This repository contains an exemplary setup that uses the R package irace: Iterated Racing for Automatic Algorithm Configuration with a code project written in Julia. It is set up to use a minimum running example on a Windows computer.
.\code
contains the Julia code including the environment (see Pkg.jl) and a small R-script to view the examplary output of iraceirace.Rdata
.\tuning
contains files necessary for irace
The following guide only contains a brief introduction to irace. Think of it as a "tl;dr" for the irace user guide combined with an introduction to command line arguments in Julia. For an extensive user guide including a way wider range of configurations and usage scenarios, please, refer to the irace user guide.
Follow the instruction on https://mlopez-ibanez.github.io/irace/#quick-start to install both R and the irace package on your computer.
- Navigate to the folder where you want to create the files and open a terminal there (or the other way around).
- Run
irace --init
here. - Several files are being generated now such as configurations.txt, forbidden.txt, parameters.txt, etc.
- A fixed set of parameters, must be defined as categorical. For example, if you want to test 100, 200, and 300 as values for a parameter, the configuration would be:
numIterations "--param " c (100,200, 300)
. Using this definition, irace adds--param 100
, among the others, to the command line call. Note the empty space in the definition of the String"--param "
. - You can also define a continuous set of integer values to test a range of parameter values, for example, between 100 and 300:
numIterations "--numIterations " i (100,300)
. The same holds for real numbers (type in theparamaters.txt
isr
instead ofi
).
- defines how irace is executed
- the file is well commented when initialized by
irace --init
and self-explaining. - for an example, refer to the given
scenario.txt
- irace runs the
target-runner.bat
located in the folder where you calledirace --init
. This script uses values passed by irace, calls your code and reads the output values. Please refer to the corresponding file in this git and the comments in this file for more details. - irace always aims to minimize the output value of your code. So, if you aim to maximize the value, simply multiply it by
-1
before returning it. target-runner.bat
is set up to read two values: the cost, i.e., the value irace aims to minimize, and the runtime which is used, e.g., for limiting the maximum runtime in irace but not part of the optimization. If you want to find a trade-off between minimizing the runtime and the objective function value (OFV) of your algorithm, you must find a single value that represents both. In the user guide, the authors propose a weighted sum. However, the weights of runtime and OFV are not trivial and must be chosen carefully.
(Hint: %var%
denotes a variables called var in a .bat-script)
- your code must take input from irace as command line arguments
- in Julia, they can be accessed via the
ARGS
vector. For more elaborate usage of command line arguments, you can use ArgParse.jl. An example of this is given inmain.jl
- the way your code is called is specified in
target-runner.bat
.- In case you are using an own environment or other values that are constant/the same for all calls of your code, you can specify this using the
fixed_params
. - the core call in the script is
julia %exe% %fixed_params% --inst=%instance% --seed=%seed% %candidate_parameters% --stdout=%stdout% --stderr=%stderr%
- this calls Julia to execute the code in the file
%exe%
with all the%fixed_params%
and the additional parametersinst
,seed
,stdout
,stderr
and the parameters to be tuned%candidate_parameters%
. %candidate_parameters%
must be defined inparameters.txt
as described above.
- this calls Julia to execute the code in the file
- the script expects two files created by your code:
%stdout%
and%stderr%
(the file names are passed as input to your code). - in
%stdout%
, thetarget-runner.bat
looks for two values in the last line of the file (might also be a single line). The first value is expected to be the cost, the second one is expected to be the runtime. Note that irace expects two values becausemaxTime
is set inscenario.txt
. If you want to usemaxEperiments
(only one of both can be set), irace expects a single value. For this, you need to both adapt the output of your code as well as the.bat
-script to read a single value instead of two.
- In case you are using an own environment or other values that are constant/the same for all calls of your code, you can specify this using the
- navigate to the directory that contains the
target-runner.bat
as well as the configuration files, open a terminal / the command line and execute the commandirace
there. - the output will be stored in the
execDir
defined in thescenario.txt
- the output is both
stderr
andstdout
files for each instance as well as the irace results in a file calledirace.Rdata
.- there are several ways to access this data, first and foremost using R
- if you are not familiar with R, you can pick another way to convert the data or simply view them in an IDE that is capable of showing
.RData
files. - an IDE built for R is, for example, RStudio.
- alternatively, there is an extension for VS Code.
- in
read_results.r
you can find an example on how to read the results of irace