wscript 12.1 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
#| Contributor(s):
#|   - Jean-Baptiste Mouret (jean-baptiste.mouret@inria.fr)
#|   - Antoine Cully (antoinecully@gmail.com)
11
#|   - Konstantinos Chatzilygeroudis (konstantinos.chatzilygeroudis@inria.fr)
12
13
#|   - Federico Allocati (fede.allocati@gmail.com)
#|   - Vaios Papaspyros (b.papaspyros@gmail.com)
Konstantinos Chatzilygeroudis's avatar
Konstantinos Chatzilygeroudis committed
14
#|   - Roberto Rama (bertoski@gmail.com)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
15
#|
16
17
18
19
20
#| 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
21
#|
22
23
24
25
26
#| 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
27
#|
28
29
30
31
32
#| 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
33
#|
34
35
36
37
38
39
40
41
42
43
#| 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
44
#|
45
46
#| 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
47
#|
48
49
import sys
sys.path.insert(0, './waf_tools')
50

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

srcdir = '.'
blddir = 'build'

57
import glob
58
59
import os
import subprocess
60
import limbo, benchmarks
Federico Allocati's avatar
Federico Allocati committed
61
import inspect
62
from waflib import Logs
63
from waflib.Build import BuildContext
64
from waflib.Errors import WafError
65

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

Vaios Papaspyros's avatar
Vaios Papaspyros committed
79
        opt.add_option('--create', type='string', help='create a new exp', dest='create_exp')
80
        limbo.add_create_options(opt)
81
        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
82
83
        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')
84
        opt.add_option('--local', type='string', help='config file (json) to run local', dest='local')
85
        opt.add_option('--local_serial', type='string', help='config file (json) to run local', dest='local_serial')
86
        opt.add_option('--experimental', action='store_true', help='specify to compile the experimental examples', dest='experimental')
87
        opt.add_option('--nb_replicates', type='int', help='number of replicates performed during the benchmark', dest='nb_rep')
88
        opt.add_option('--tests', action='store_true', help='compile tests or not', dest='tests')
89
        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')
90
        opt.add_option('--regression_benchmarks', type='string', help='config file (json) to compile benchmark for regression', dest='regression_benchmarks')
91
        opt.add_option('--cpp14', action='store_true', default=False, help='force c++-14 compilation [--cpp14]', dest='cpp14')
92
        opt.add_option('--no-native', action='store_true', default=False, help='disable -march=native, which can cause some troubles [--no-native]', dest='no_native')
93

94

95
96
97
98
        try:
                os.mkdir(blddir)# because this is not always created at that stage
        except:
                print("build dir not created (it probably already exists, this is fine)")
99
100
        opt.logger = Logs.make_logger(blddir + '/options.log', 'mylogger')

101
        for i in glob.glob('exp/*'):
Federico Allocati's avatar
Federico Allocati committed
102
                if os.path.isdir(i):
103
                    opt.start_msg('command-line options for [%s]' % i)
104
105
106
107
108
                    try:
                        opt.recurse(i)
                        opt.end_msg(' -> OK')
                    except WafError:
                        opt.end_msg(' -> no options found')
109

110
        opt.recurse('src/benchmarks')
111

112
def configure(conf):
113
        conf.load('compiler_cxx boost waf_unit_test')
114
115
116
        conf.load('compiler_c')
        conf.load('eigen')
        conf.load('tbb')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
117
        conf.load('sferes')
118
        conf.load('openmp')
119
        conf.load('mkl')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
120
        conf.load('xcode')
121
        conf.load('nlopt')
122
        conf.load('libcmaes')
123

Konstantinos Chatzilygeroudis's avatar
Konstantinos Chatzilygeroudis committed
124
        native_flags = "-march=native"
125
126
127
128
129
130

        is_cpp14 = conf.options.cpp14
        if is_cpp14:
            is_cpp14 = conf.check_cxx(cxxflags="-std=c++14", mandatory=False, msg='Checking for C++14')
            if not is_cpp14:
                conf.msg('C++14 is requested, but your compiler does not support it!', 'Disabling it!', color='RED')
131
132
        if conf.env.CXX_NAME in ["icc", "icpc"]:
            common_flags = "-Wall -std=c++11"
133
134
            opt_flags = " -O3 -xHost -g"
            native_flags = "-mtune=native -unroll -fma"
135
        else:
136
            if conf.env.CXX_NAME in ["gcc", "g++"] and int(conf.env['CC_VERSION'][0]+conf.env['CC_VERSION'][1]) < 47:
137
138
139
                common_flags = "-Wall -std=c++0x"
            else:
                common_flags = "-Wall -std=c++11"
140
141
            if conf.env.CXX_NAME in ["clang", "llvm"]:
                common_flags += " -fdiagnostics-color"
142
143
            opt_flags = " -O3 -g"

144
145
146
        if is_cpp14:
            common_flags = common_flags + " -std=c++14"

147
        native = conf.check_cxx(cxxflags=native_flags, mandatory=False, msg='Checking for compiler flags \"'+native_flags+'\"')
148
        if native and not conf.options.no_native:
149
            opt_flags = opt_flags + ' ' + native_flags
150
        elif not native:
151
            Logs.pprint('YELLOW', 'WARNING: Native flags not supported. The performance might be a bit deteriorated.')
152
153
154
        else:
            Logs.pprint('YELLOW', 'WARNING: Native flags not activated. The performance might be a bit deteriorated.')

155

156
        conf.check_boost(lib='serialization filesystem \
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
157
            system unit_test_framework program_options \
158
            thread', min_version='1.39')
159
160
        conf.check_eigen()
        conf.check_tbb()
161
        conf.check_sferes()
162
163
        conf.check_openmp()
        conf.check_mkl()
164
        conf.check_nlopt()
165
        conf.check_libcmaes()
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
166

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

169
170
        all_flags = common_flags + opt_flags
        conf.env['CXXFLAGS'] = conf.env['CXXFLAGS'] + all_flags.split(' ')
171
        Logs.pprint('NORMAL', 'CXXFLAGS: %s' % conf.env['CXXFLAGS'])
172

Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
173
174
        if conf.options.exp:
                for i in conf.options.exp.split(','):
175
                        Logs.pprint('NORMAL', 'configuring for exp: %s' % i)
Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
176
                        conf.recurse('exp/' + i)
177
        conf.recurse('src/benchmarks')
178
179
180
181
182
183
184
        Logs.pprint('NORMAL', '')
        Logs.pprint('NORMAL', 'WHAT TO DO NOW?')
        Logs.pprint('NORMAL', '---------------')
        Logs.pprint('NORMAL', '[users] To compile Limbo: ./waf build')
        Logs.pprint('NORMAL', '[users] To compile and run unit tests: ./waf --tests')
        Logs.pprint('NORMAL', '[users] Read the documentation (inc. tutorials) on http://www.resibots.eu/limbo')
        Logs.pprint('NORMAL', '[developers] To compile the HTML documentation (this requires sphinx and the resibots theme): ./waf docs')
185
186
187
        Logs.pprint('NORMAL', '[developers] To compile the BO benchmarks: ./waf build_bo_benchmarks')
        Logs.pprint('NORMAL', '[developers] To run the BO benchmarks: ./waf run_bo_benchmarks')
        Logs.pprint('NORMAL', '[developers] To compile the regression benchmarks (requires a json file with the setup): ./waf --regression_benchmarks file.json')
188
        Logs.pprint('NORMAL', '[developers] To run the regression benchmarks: ./waf run_regression_benchmarks --regression_benchmarks file.json')
189
        Logs.pprint('NORMAL', '[developers] To compile the extensive tests: ./waf build_extensive_tests')
190

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

192
def build(bld):
193
194
    if bld.options.write_params:
        limbo.write_default_params(bld.options.write_params)
195
        Logs.pprint('NORMAL', 'default parameters written in %s' % bld.options.write_params)
196
197
198
    bld.recurse('src/')
    if bld.options.exp:
        for i in bld.options.exp.split(','):
199
            Logs.pprint('NORMAL', 'Building exp: %s' % i)
200
            bld.recurse('exp/' + i)
201
            limbo.output_params('exp/'+i)
202
    if bld.options.regression_benchmarks:
203
        benchmarks.compile_regression_benchmarks(bld, bld.options.regression_benchmarks)
204
    bld.add_post_fun(limbo.summary)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
205

206
def build_extensive_tests(ctx):
207
    ctx.recurse('src/')
208
209
    ctx.recurse('src/tests')

210
def build_bo_benchmarks(ctx):
211
212
    ctx.recurse('src/benchmarks')

213
214
215
216
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)
217
            Logs.pprint('NORMAL', 'Running: %s' % fname)
218
219
            s = "cd " + fpath + "; ./" + fname
            retcode = subprocess.call(s, shell=True, env=None)
220

221
222
223
224
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)
225
            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
226
            retcode = subprocess.call(s, shell=True, env=None)
227
            Logs.pprint('NORMAL', 'oarsub returned: %s' % str(retcode))
228

229
def run_bo_benchmarks(ctx):
230
    benchmarks.run_bo_benchmarks(ctx)
231

232
def run_regression_benchmarks(ctx):
233
    benchmarks.run_regression_benchmarks(ctx)
234

235
def shutdown(ctx):
Vaios Papaspyros's avatar
Vaios Papaspyros committed
236
    if ctx.options.create_exp:
237
        limbo.create_exp(ctx.options.create_exp, ctx.options)
238
239
    if ctx.options.qsub:
        limbo.qsub(ctx.options.qsub)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
240
241
    if ctx.options.oar:
        limbo.oar(ctx.options.oar)
242
    if ctx.options.local:
243
244
245
        limbo.run_local(ctx.options.local, False)
    if ctx.options.local_serial:
        limbo.run_local(ctx.options.local_serial)
246

247
248
249
def insert_license(ctx):
    limbo.insert_license()

250
def write_default_params(ctx):
251
    Logs.pprint('NORMAL', 'extracting default params to docs/defaults.rst')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
252
    limbo.write_default_params('docs/defaults.rst')
253

254
def build_docs(ctx):
255
    Logs.pprint('NORMAL', "generating HTML doc with versioning...")
256
    s = 'sphinx-versioning -v build -f docs/pre_script.sh --whitelist-branches "(master|release-*)" docs docs/_build/html'
257
258
    retcode = subprocess.call(s, shell=True, env=None)

259
260
261
class BuildExtensiveTestsContext(BuildContext):
    cmd = 'build_extensive_tests'
    fun = 'build_extensive_tests'
262
263

class BuildBenchmark(BuildContext):
264
265
    cmd = 'build_bo_benchmarks'
    fun = 'build_bo_benchmarks'
266

267
268
269
class InsertLicense(BuildContext):
    cmd = 'insert_license'
    fun = 'insert_license'
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
270

271
272
273
class BuildDoc(BuildContext):
    cmd = 'docs'
    fun = 'build_docs'
274
275
276

class BuildDoc(BuildContext):
    cmd = 'default_params'
277
    fun = 'write_default_params'