wscript 9.97 KB
Newer Older
1
2
#!/usr/bin/env python
# encoding: utf-8
3
4
5
6
#| Copyright Inria May 2015
#| This project has received funding from the European Research Council (ERC) under
#| the European Union's Horizon 2020 research and innovation programme (grant
#| agreement No 637972) - see http://www.resibots.eu
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
7
#|
8
9
10
11
12
13
#| Contributor(s):
#|   - Jean-Baptiste Mouret (jean-baptiste.mouret@inria.fr)
#|   - Antoine Cully (antoinecully@gmail.com)
#|   - Kontantinos Chatzilygeroudis (konstantinos.chatzilygeroudis@inria.fr)
#|   - Federico Allocati (fede.allocati@gmail.com)
#|   - Vaios Papaspyros (b.papaspyros@gmail.com)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
14
#|
15
16
17
18
19
#| This software is a computer library whose purpose is to optimize continuous,
#| black-box functions. It mainly implements Gaussian processes and Bayesian
#| optimization.
#| Main repository: http://github.com/resibots/limbo
#| Documentation: http://www.resibots.eu/limbo
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
20
#|
21
22
23
24
25
#| This software is governed by the CeCILL-C license under French law and
#| abiding by the rules of distribution of free software.  You can  use,
#| modify and/ or redistribute the software under the terms of the CeCILL-C
#| license as circulated by CEA, CNRS and INRIA at the following URL
#| "http://www.cecill.info".
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
26
#|
27
28
29
30
31
#| As a counterpart to the access to the source code and  rights to copy,
#| modify and redistribute granted by the license, users are provided only
#| with a limited warranty  and the software's author,  the holder of the
#| economic rights,  and the successive licensors  have only  limited
#| liability.
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
32
#|
33
34
35
36
37
38
39
40
41
42
#| In this respect, the user's attention is drawn to the risks associated
#| with loading,  using,  modifying and/or developing or reproducing the
#| software by the user in light of its specific status of free software,
#| that may mean  that it is complicated to manipulate,  and  that  also
#| therefore means  that it is reserved for developers  and  experienced
#| professionals having in-depth computer knowledge. Users are therefore
#| encouraged to load and test the software's suitability as regards their
#| requirements in conditions enabling the security of their systems and/or
#| data to be ensured and,  more generally, to use and operate it in the
#| same conditions as regards security.
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
43
#|
44
45
#| The fact that you are presently reading this means that you have had
#| knowledge of the CeCILL-C license and that you accept its terms.
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
46
#|
47
48
import sys
sys.path.insert(0, './waf_tools')
49

50
51
VERSION = '0.0.1'
APPNAME = 'limbo'
52
53
54
55

srcdir = '.'
blddir = 'build'

56
import glob
57
58
import os
import subprocess
59
import limbo
Federico Allocati's avatar
Federico Allocati committed
60
import inspect
61
from waflib.Build import BuildContext
62

63
64
65
66
67
def options(opt):
        opt.load('compiler_cxx boost waf_unit_test')
        opt.load('compiler_c')
        opt.load('eigen')
        opt.load('tbb')
68
        opt.load('mkl')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
69
        opt.load('sferes')
70
        opt.load('limbo')
71
        opt.load('openmp')
72
        opt.load('nlopt')
73
        opt.load('libcmaes')
74
        opt.load('xcode')
75

Vaios Papaspyros's avatar
Vaios Papaspyros committed
76
        opt.add_option('--create', type='string', help='create a new exp', dest='create_exp')
77
        limbo.add_create_options(opt)
78
        opt.add_option('--exp', type='string', help='exp(s) to build, separate by comma', dest='exp')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
79
80
        opt.add_option('--qsub', type='string', help='config file (json) to submit to torque', dest='qsub')
        opt.add_option('--oar', type='string', help='config file (json) to submit to oar', dest='oar')
81
        opt.add_option('--local', type='string', help='config file (json) to run local', dest='local')
82
        opt.add_option('--local_serial', type='string', help='config file (json) to run local', dest='local_serial')
83
        opt.add_option('--experimental', action='store_true', help='specify to compile the experimental examples', dest='experimental')
84
        opt.add_option('--nb_replicates', type='int', help='number of replicates performed during the benchmark', dest='nb_rep')
85
        opt.add_option('--tests', action='store_true', help='compile tests or not', dest='tests')
86
87
        opt.add_option('--write_params', type='string', help='write all the default values of parameters in a file (used by the documentation system)', dest='write_params')

88
        for i in glob.glob('exp/*'):
Federico Allocati's avatar
Federico Allocati committed
89
90
                if os.path.isdir(i):
                    opt.recurse(i)
91

92
        opt.recurse('src/benchmarks')
93

94
def configure(conf):
95
        conf.load('compiler_cxx boost waf_unit_test')
96
97
98
        conf.load('compiler_c')
        conf.load('eigen')
        conf.load('tbb')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
99
        conf.load('sferes')
100
        conf.load('openmp')
101
        conf.load('mkl')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
102
        conf.load('xcode')
103
        conf.load('nlopt')
104
        conf.load('libcmaes')
105

106
107
108
        if conf.env.CXX_NAME in ["icc", "icpc"]:
            common_flags = "-Wall -std=c++11"
            opt_flags = " -O3 -xHost  -march=native -mtune=native -unroll -fma -g"
109
        else:
110
            if conf.env.CXX_NAME in ["gcc", "g++"] and int(conf.env['CC_VERSION'][0]+conf.env['CC_VERSION'][1]) < 47:
111
112
113
                common_flags = "-Wall -std=c++0x"
            else:
                common_flags = "-Wall -std=c++11"
114
115
            if conf.env.CXX_NAME in ["clang", "llvm"]:
                common_flags += " -fdiagnostics-color"
116
            opt_flags = " -O3 -march=native -g"
117

118
        conf.check_boost(lib='serialization filesystem \
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
119
            system unit_test_framework program_options \
120
            thread', min_version='1.39')
121
122
        conf.check_eigen()
        conf.check_tbb()
123
        conf.check_sferes()
124
125
        conf.check_openmp()
        conf.check_mkl()
126
        conf.check_nlopt()
127
        conf.check_libcmaes()
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
128

Federico Allocati's avatar
Federico Allocati committed
129
130
        conf.env.INCLUDES_LIMBO = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/src"

131
132
        all_flags = common_flags + opt_flags
        conf.env['CXXFLAGS'] = conf.env['CXXFLAGS'] + all_flags.split(' ')
133
        print 'CXXFLAGS:', conf.env['CXXFLAGS']
134

Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
135
136
137
138
        if conf.options.exp:
                for i in conf.options.exp.split(','):
                        print 'configuring for exp: ' + i
                        conf.recurse('exp/' + i)
139
        conf.recurse('src/benchmarks')
140
141
142
143
144
        print ''
        print 'WHAT TO DO NOW?'
        print '---------------'
        print '[users] To compile Limbo (inc. unit tests): ./waf build'
        print '[users] Read the documentation (inc. tutorials) on http://www.resibots.eu/limbo'
145
146
147
        print '[developers] To compile the HTML documentation (this requires sphinx and the resibots theme): ./waf doc'
        print '[developers] To compile the benchmarks: ./waf build_benchmarks'
        print '[developers] To compile the extensive tests: ./waf build_extensive_tests'
148

Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
149

150
def build(bld):
151
152
153
    if bld.options.write_params:
        limbo.write_default_params(bld.options.write_params)
        print 'default parameters written in ' + bld.options.write_params
154
155
156
157
158
    bld.recurse('src/')
    if bld.options.exp:
        for i in bld.options.exp.split(','):
            print 'Building exp: ' + i
            bld.recurse('exp/' + i)
159
            limbo.output_params('exp/'+i)
160
    bld.add_post_fun(limbo.summary)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
161

162
def build_extensive_tests(ctx):
163
    ctx.recurse('src/')
164
165
    ctx.recurse('src/tests')

166
167
168
def build_benchmark(ctx):
    ctx.recurse('src/benchmarks')

169
170
171
172
173
174
175
def run_extensive_tests(ctx):
    for fullname in glob.glob('build/src/tests/combinations/*'):
        if os.path.isfile(fullname) and os.access(fullname, os.X_OK):
            fpath, fname = os.path.split(fullname)
            print "Running: " + fname
            s = "cd " + fpath + "; ./" + fname
            retcode = subprocess.call(s, shell=True, env=None)
176

177
178
179
180
def submit_extensive_tests(ctx):
    for fullname in glob.glob('build/src/tests/combinations/*'):
        if os.path.isfile(fullname) and os.access(fullname, os.X_OK):
            fpath, fname = os.path.split(fullname)
181
            s = "cd " + fpath + ";oarsub -l /nodes=1/core=2,walltime=00:15:00 -n " + fname + " -O " + fname + ".stdout.%jobid%.log -E " + fname + ".stderr.%jobid%.log ./" + fname
182
183
184
            retcode = subprocess.call(s, shell=True, env=None)
            print "oarsub returned:" + str(retcode)

185
def run_benchmark(ctx):
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
    HEADER='\033[95m'
    NC='\033[0m'
    res_dir=os.getcwd()+"/benchmark_results/"
    try:
        os.makedirs(res_dir)
    except:
        print "WARNING, dir:" + res_dir + " not be created"
    for fullname in glob.glob('build/src/benchmarks/*'):
        if os.path.isfile(fullname) and os.access(fullname, os.X_OK):
            fpath, fname = os.path.split(fullname)
            directory = res_dir + "/" + fname
            try:
                os.makedirs(directory)
            except:
                print "WARNING, dir:" + directory + " not be created, the new results will be concatenated to the old ones"
            s = "cp " + fullname + " " + directory
            retcode = subprocess.call(s, shell=True, env=None)
            if ctx.options.nb_rep:
                nb_rep = ctx.options.nb_rep
            else:
                nb_rep = 10
            for i in range(0,nb_rep):
                print HEADER+" Running: " + fname + " for the "+str(i)+"th time"+NC
                s="cd " + directory +";./" + fname
                retcode = subprocess.call(s, shell=True, env=None)
211

212
def shutdown(ctx):
Vaios Papaspyros's avatar
Vaios Papaspyros committed
213
    if ctx.options.create_exp:
214
        limbo.create_exp(ctx.options.create_exp, ctx.options)
215
216
    if ctx.options.qsub:
        limbo.qsub(ctx.options.qsub)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
217
218
    if ctx.options.oar:
        limbo.oar(ctx.options.oar)
219
    if ctx.options.local:
220
221
222
        limbo.run_local(ctx.options.local, False)
    if ctx.options.local_serial:
        limbo.run_local(ctx.options.local_serial)
223

224
225
226
def insert_license(ctx):
    limbo.insert_license()

227
def build_docs(ctx):
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
228
229
230
    print 'extracting default params...'
    limbo.write_default_params('docs/defaults.rst')
    print "generating HTML doc..."
231
232
233
    s = "cd docs; make html"
    retcode = subprocess.call(s, shell=True, env=None)

234
235
236
class BuildExtensiveTestsContext(BuildContext):
    cmd = 'build_extensive_tests'
    fun = 'build_extensive_tests'
237
238
239
240

class BuildBenchmark(BuildContext):
    cmd = 'build_benchmark'
    fun = 'build_benchmark'
241

242
243
244
class InsertLicense(BuildContext):
    cmd = 'insert_license'
    fun = 'insert_license'
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
245

246
247
248
class BuildDoc(BuildContext):
    cmd = 'docs'
    fun = 'build_docs'