Admin/mira.py
author wenzelm
Sun Jan 24 12:33:40 2016 +0100 (2016-01-24)
changeset 62236 3a326bc9d4d8
parent 59993 8f6cacc87f42
permissions -rw-r--r--
more CONTRIBUTORS;
haftmann@41542
     1
"""
haftmann@41542
     2
    Test configuration descriptions for mira.
haftmann@41542
     3
"""
haftmann@41542
     4
haftmann@41542
     5
import os
haftmann@41542
     6
from os import path
haftmann@41542
     7
from glob import glob
haftmann@41542
     8
import subprocess
krauss@42392
     9
from datetime import datetime
haftmann@41542
    10
import re
haftmann@41542
    11
haftmann@41542
    12
import util
haftmann@41542
    13
krauss@42823
    14
from mira import schedule, misc
krauss@42192
    15
from mira.environment import scheduler
haftmann@46931
    16
from mira import repositories
krauss@42192
    17
haftmann@41542
    18
# build and evaluation tools
haftmann@41542
    19
krauss@50599
    20
DEFAULT_TIMEOUT = 2 * 60 * 60
krauss@50599
    21
SMLNJ_TIMEOUT = 72 * 60 * 60
krauss@50599
    22
krauss@50598
    23
def prepare_isabelle_repository(loc_isabelle, loc_dependency_heaps, more_settings=''):
krauss@42821
    24
krauss@42821
    25
    # patch settings
haftmann@41542
    26
    extra_settings = '''
krauss@48785
    27
krauss@50596
    28
init_components "/home/isabelle/contrib" "$ISABELLE_HOME/Admin/components/main"
krauss@50596
    29
init_components "/home/isabelle/contrib" "$ISABELLE_HOME/Admin/components/optional"
krauss@50596
    30
init_components "/home/isabelle/contrib" "$ISABELLE_HOME/Admin/components/nonfree"
haftmann@48182
    31
krauss@48783
    32
''' + more_settings
haftmann@41542
    33
haftmann@41542
    34
    writer = open(path.join(loc_isabelle, 'etc', 'settings'), 'a')
haftmann@41542
    35
    writer.write(extra_settings)
haftmann@41542
    36
    writer.close()
haftmann@41542
    37
haftmann@41542
    38
krauss@45164
    39
def isabelle_getenv(isabelle_home, var):
krauss@45164
    40
krauss@45164
    41
    _, out = env.run_process('%s/bin/isabelle' % isabelle_home, 'getenv', var)
krauss@45164
    42
    return out.split('=', 1)[1].strip()
krauss@45164
    43
krauss@45164
    44
haftmann@41542
    45
def extract_isabelle_run_timing(logdata):
haftmann@41542
    46
haftmann@41542
    47
    def to_secs(h, m, s):
haftmann@41542
    48
        return (int(h) * 60 + int(m)) * 60 + int(s)
haftmann@41542
    49
    pat = r'Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time'
krauss@42186
    50
    pat2 = r'Timing (\S+) \((\d+) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time, factor (\d+\.\d+)\)'
haftmann@41542
    51
    t = dict((name, {'elapsed': to_secs(eh,em,es), 'cpu': to_secs(ch,cm,cs)})
haftmann@41542
    52
             for name, eh, em, es, ch, cm, cs in re.findall(pat, logdata))
krauss@42186
    53
    for name, threads, elapsed, cpu, gc, factor in re.findall(pat2, logdata):
haftmann@41542
    54
haftmann@41542
    55
        if name not in t:
haftmann@41542
    56
            t[name] = {}
haftmann@41542
    57
haftmann@41542
    58
        t[name]['threads'] = int(threads)
haftmann@41542
    59
        t[name]['elapsed_inner'] = elapsed
haftmann@41542
    60
        t[name]['cpu_inner'] = cpu
haftmann@41542
    61
        t[name]['gc'] = gc
krauss@42186
    62
        t[name]['factor'] = factor
haftmann@41542
    63
haftmann@41542
    64
    return t
haftmann@41542
    65
haftmann@41542
    66
haftmann@41542
    67
def extract_isabelle_run_summary(logdata):
haftmann@41542
    68
krauss@41894
    69
    re_error = re.compile(r'^(?:make: )?\*\*\* (.*)$', re.MULTILINE)
haftmann@41542
    70
    summary = '\n'.join(re_error.findall(logdata))
haftmann@41542
    71
    if summary == '':
haftmann@41542
    72
        summary = 'ok'
haftmann@41542
    73
haftmann@41542
    74
    return summary
haftmann@41542
    75
haftmann@41542
    76
krauss@45164
    77
def extract_image_size(isabelle_home):
krauss@45164
    78
    
krauss@45164
    79
    isabelle_output = isabelle_getenv(isabelle_home, 'ISABELLE_OUTPUT')
krauss@50595
    80
    if not path.exists(isabelle_output):
krauss@50595
    81
        return {}
krauss@50595
    82
krauss@45164
    83
    return dict((p, path.getsize(path.join(isabelle_output, p))) for p in os.listdir(isabelle_output) if p != "log")
krauss@45164
    84
krauss@45164
    85
def extract_report_data(isabelle_home, logdata):
krauss@45164
    86
krauss@45164
    87
    return {
krauss@45164
    88
        'timing': extract_isabelle_run_timing(logdata),
krauss@45164
    89
        'image_size': extract_image_size(isabelle_home) }
krauss@45164
    90
krauss@45164
    91
krauss@48686
    92
def isabelle_build(env, case, paths, dep_paths, playground, *cmdargs, **kwargs):
haftmann@41542
    93
krauss@50599
    94
    more_settings = kwargs.get('more_settings', '')
krauss@50599
    95
    keep_results = kwargs.get('keep_results', True)
krauss@50599
    96
    timeout = kwargs.get('timeout', DEFAULT_TIMEOUT)
haftmann@41542
    97
krauss@42114
    98
    isabelle_home = paths[0]
haftmann@41542
    99
noschinl@57179
   100
    home_user_dir = path.join(isabelle_home, 'home_user')
noschinl@57179
   101
    os.makedirs(home_user_dir)
noschinl@57179
   102
krauss@48686
   103
    # copy over build results from dependencies
krauss@48686
   104
    heap_dir = path.join(isabelle_home, 'heaps')
krauss@48686
   105
    classes_dir = path.join(heap_dir, 'classes')
krauss@48686
   106
    os.makedirs(classes_dir)
krauss@42115
   107
krauss@48686
   108
    for dep_path in dep_paths:
krauss@48686
   109
        subprocess.check_call(['cp', '-a'] + glob(dep_path + '/*') + [heap_dir])
krauss@45164
   110
krauss@48686
   111
    subprocess.check_call(['ln', '-s', classes_dir, path.join(isabelle_home, 'lib', 'classes')])
krauss@48686
   112
    jars = glob(path.join(classes_dir, 'ext', '*.jar'))
krauss@48686
   113
    if jars:
krauss@48686
   114
        subprocess.check_call(['touch'] + jars)
krauss@42115
   115
krauss@48686
   116
    # misc preparations
krauss@48686
   117
    if 'lxbroy10' in misc.hostnames():  # special settings for lxbroy10
krauss@42823
   118
        more_settings += '''
bulwahn@43334
   119
ISABELLE_GHC="/usr/bin/ghc"
krauss@42823
   120
'''
krauss@42823
   121
krauss@50598
   122
    prepare_isabelle_repository(isabelle_home, None, more_settings=more_settings)
krauss@42114
   123
    os.chdir(isabelle_home)
haftmann@41542
   124
noschinl@50600
   125
    args = (['-o', 'timeout=%s' % timeout] if timeout is not None else []) + list(cmdargs)
krauss@50599
   126
krauss@48686
   127
    # invoke build tool
noschinl@57559
   128
    (return_code, log1) = env.run_process('%s/bin/isabelle' % isabelle_home, 'jedit', '-bf',
noschinl@57172
   129
            USER_HOME=home_user_dir)
noschinl@57559
   130
    (return_code, log2) = env.run_process('%s/bin/isabelle' % isabelle_home, 'build', '-s', '-v', *args,
noschinl@57559
   131
            USER_HOME=home_user_dir)
noschinl@57559
   132
    log = log1 + log2
haftmann@41542
   133
krauss@48686
   134
    # collect report
krauss@48686
   135
    return (return_code == 0, extract_isabelle_run_summary(log),
krauss@49175
   136
      extract_report_data(isabelle_home, log), {'log': log}, heap_dir if keep_results else None)
haftmann@41542
   137
haftmann@41542
   138
krauss@43689
   139
krauss@43689
   140
# Isabelle configurations
krauss@43689
   141
krauss@43689
   142
@configuration(repos = [Isabelle], deps = [])
krauss@43689
   143
def Pure(*args):
krauss@48686
   144
    """Pure Image"""
krauss@48686
   145
    return isabelle_build(*(args + ("-b", "Pure")))
krauss@43689
   146
haftmann@41542
   147
@configuration(repos = [Isabelle], deps = [(Pure, [0])])
haftmann@41542
   148
def HOL(*args):
krauss@48686
   149
    """HOL Image"""
krauss@48686
   150
    return isabelle_build(*(args + ("-b", "HOL")))
haftmann@41542
   151
haftmann@46934
   152
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@46934
   153
def HOL_Library(*args):
krauss@48686
   154
    """HOL Library"""
krauss@48686
   155
    return isabelle_build(*(args + ("-b", "HOL-Library")))
krauss@48686
   156
krauss@48686
   157
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@48688
   158
def HOLCF(*args):
krauss@48686
   159
    """HOLCF"""
krauss@48688
   160
    return isabelle_build(*(args + ("-b", "HOLCF")))
haftmann@46934
   161
haftmann@46934
   162
@configuration(repos = [Isabelle], deps = [(Pure, [0])])
haftmann@46934
   163
def ZF(*args):
krauss@48686
   164
    """HOLCF"""
krauss@48686
   165
    return isabelle_build(*(args + ("-b", "ZF")))
haftmann@46934
   166
haftmann@46934
   167
bulwahn@47895
   168
settings64='''
krauss@50593
   169
# enforce 64 bit, overriding smart detection
krauss@50593
   170
ML_PLATFORM="$ISABELLE_PLATFORM64"
krauss@50593
   171
ML_HOME="$(dirname $ML_HOME)/$ML_PLATFORM"
bulwahn@47895
   172
'''
bulwahn@47895
   173
bulwahn@47897
   174
@configuration(repos = [Isabelle], deps = [])
haftmann@41542
   175
def Isabelle_makeall(*args):
krauss@48686
   176
    """Build all sessions"""
krauss@49175
   177
    return isabelle_build(*(args + ("-j", "6", "-o", "threads=4", "-a")), more_settings=settings64, keep_results=False)
haftmann@46934
   178
haftmann@46931
   179
haftmann@41542
   180
# Mutabelle configurations
haftmann@41542
   181
haftmann@41542
   182
def invoke_mutabelle(theory, env, case, paths, dep_paths, playground):
haftmann@41542
   183
haftmann@41542
   184
    """Mutant testing for counterexample generators in Isabelle"""
haftmann@41542
   185
haftmann@41542
   186
    (loc_isabelle,) = paths
haftmann@41542
   187
    (dep_isabelle,) = dep_paths
bulwahn@43152
   188
    more_settings = '''
bulwahn@43153
   189
ISABELLE_GHC="/usr/bin/ghc"
bulwahn@43152
   190
'''
krauss@50598
   191
    prepare_isabelle_repository(loc_isabelle, dep_isabelle, more_settings = more_settings)
haftmann@41542
   192
    os.chdir(loc_isabelle)
haftmann@41542
   193
    
haftmann@41542
   194
    (return_code, log) = env.run_process('bin/isabelle',
haftmann@41542
   195
      'mutabelle', '-O', playground, theory)
haftmann@41542
   196
    
haftmann@41542
   197
    try:
haftmann@41542
   198
        mutabelle_log = util.readfile(path.join(playground, 'log'))
haftmann@41542
   199
    except IOError:
haftmann@41542
   200
        mutabelle_log = ''
haftmann@41542
   201
krauss@42472
   202
    mutabelle_data = dict(
krauss@42472
   203
        (tool, {'counterexample': c, 'no_counterexample': n, 'timeout': t, 'error': e})
krauss@42472
   204
        for tool, c, n, t, e in re.findall(r'(\S+)\s+: C: (\d+) N: (\d+) T: (\d+) E: (\d+)', log))
krauss@42472
   205
haftmann@41542
   206
    return (return_code == 0 and mutabelle_log != '', extract_isabelle_run_summary(log),
krauss@42472
   207
      {'mutabelle_results': {theory: mutabelle_data}},
haftmann@41652
   208
      {'log': log, 'mutabelle_log': mutabelle_log}, None)
haftmann@41542
   209
krauss@42948
   210
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   211
def Mutabelle_Relation(*args):
haftmann@41542
   212
    """Mutabelle regression suite on Relation theory"""
haftmann@41542
   213
    return invoke_mutabelle('Relation', *args)
haftmann@41542
   214
krauss@42948
   215
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   216
def Mutabelle_List(*args):
haftmann@41542
   217
    """Mutabelle regression suite on List theory"""
haftmann@41542
   218
    return invoke_mutabelle('List', *args)
haftmann@41542
   219
krauss@42948
   220
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   221
def Mutabelle_Set(*args):
haftmann@41542
   222
    """Mutabelle regression suite on Set theory"""
haftmann@41542
   223
    return invoke_mutabelle('Set', *args)
haftmann@41542
   224
krauss@42948
   225
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   226
def Mutabelle_Map(*args):
haftmann@41542
   227
    """Mutabelle regression suite on Map theory"""
haftmann@41542
   228
    return invoke_mutabelle('Map', *args)
haftmann@41542
   229
krauss@42948
   230
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   231
def Mutabelle_Divides(*args):
haftmann@41542
   232
    """Mutabelle regression suite on Divides theory"""
haftmann@41542
   233
    return invoke_mutabelle('Divides', *args)
haftmann@41542
   234
krauss@42948
   235
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   236
def Mutabelle_MacLaurin(*args):
haftmann@41542
   237
    """Mutabelle regression suite on MacLaurin theory"""
haftmann@41542
   238
    return invoke_mutabelle('MacLaurin', *args)
haftmann@41542
   239
krauss@42948
   240
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   241
def Mutabelle_Fun(*args):
haftmann@41542
   242
    """Mutabelle regression suite on Fun theory"""
haftmann@41542
   243
    return invoke_mutabelle('Fun', *args)
krauss@42040
   244
krauss@42393
   245
mutabelle_confs = 'Mutabelle_Relation Mutabelle_List Mutabelle_Set Mutabelle_Map Mutabelle_Divides Mutabelle_MacLaurin Mutabelle_Fun'.split(' ')
krauss@42393
   246
krauss@42393
   247
@scheduler()
krauss@42393
   248
def mutabelle_scheduler(env):
krauss@42393
   249
    """Scheduler for Mutabelle."""
krauss@42393
   250
    return schedule.age_scheduler(env, 'Isabelle', mutabelle_confs)
krauss@42040
   251
bulwahn@47896
   252
krauss@42040
   253
# Judgement Day configurations
krauss@42040
   254
krauss@42095
   255
judgement_day_provers = ('e', 'spass', 'vampire', 'z3', 'cvc3', 'yices')
krauss@42040
   256
krauss@42040
   257
def judgement_day(base_path, theory, opts, env, case, paths, dep_paths, playground):
krauss@42040
   258
    """Judgement Day regression suite"""
krauss@42040
   259
krauss@42040
   260
    isa = paths[0]
krauss@42040
   261
    dep_path = dep_paths[0]
krauss@42040
   262
krauss@42040
   263
    os.chdir(path.join(playground, '..', base_path)) # Mirabelle requires specific cwd
krauss@50594
   264
    prepare_isabelle_repository(isa, dep_path)
krauss@42040
   265
krauss@42040
   266
    output = {}
krauss@42040
   267
    success_rates = {}
krauss@42040
   268
    some_success = False
krauss@42040
   269
krauss@42040
   270
    for atp in judgement_day_provers:
krauss@42040
   271
krauss@42040
   272
        log_dir = path.join(playground, 'mirabelle_log_' + atp)
krauss@42040
   273
        os.makedirs(log_dir)
krauss@42040
   274
krauss@42040
   275
        cmd = ('%s/bin/isabelle mirabelle -q -O %s sledgehammer[prover=%s,%s] %s.thy'
krauss@42040
   276
               % (isa, log_dir, atp, opts, theory))
krauss@42040
   277
krauss@42040
   278
        os.system(cmd)
krauss@42040
   279
        output[atp] = util.readfile(path.join(log_dir, theory + '.log'))
krauss@42040
   280
krauss@42040
   281
        percentages = list(re.findall(r'Success rate: (\d+)%', output[atp]))
krauss@42040
   282
        if len(percentages) == 2:
krauss@42040
   283
            success_rates[atp] = {
krauss@42040
   284
                'sledgehammer': int(percentages[0]),
krauss@42040
   285
                'metis': int(percentages[1])}
krauss@42040
   286
            if success_rates[atp]['sledgehammer'] > 0:
krauss@42040
   287
                some_success = True
krauss@42040
   288
        else:
krauss@42040
   289
            success_rates[atp] = {}
krauss@42040
   290
krauss@42040
   291
krauss@42040
   292
    data = {'success_rates': success_rates}
krauss@42040
   293
    raw_attachments = dict((atp + "_output", output[atp]) for atp in judgement_day_provers)
krauss@42040
   294
    # FIXME: summary?
krauss@42040
   295
    return (some_success, '', data, raw_attachments, None)
krauss@42040
   296
krauss@42040
   297
krauss@42948
   298
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   299
def JD_NS(*args):
krauss@42040
   300
    """Judgement Day regression suite NS"""
krauss@42040
   301
    return judgement_day('Isabelle/src/HOL/Auth', 'NS_Shared', 'prover_timeout=10', *args)
krauss@42040
   302
krauss@42948
   303
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   304
def JD_FTA(*args):
krauss@42040
   305
    """Judgement Day regression suite FTA"""
krauss@42040
   306
    return judgement_day('Isabelle/src/HOL/Library', 'Fundamental_Theorem_Algebra', 'prover_timeout=10', *args)
krauss@42040
   307
krauss@42948
   308
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   309
def JD_Hoare(*args):
krauss@42040
   310
    """Judgement Day regression suite Hoare"""
krauss@42058
   311
    return judgement_day('Isabelle/src/HOL/IMPP', 'Hoare', 'prover_timeout=10', *args)
krauss@42040
   312
krauss@42948
   313
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   314
def JD_SN(*args):
krauss@42040
   315
    """Judgement Day regression suite SN"""
krauss@42058
   316
    return judgement_day('Isabelle/src/HOL/Proofs/Lambda', 'StrongNorm', 'prover_timeout=10', *args)
krauss@42040
   317
krauss@42116
   318
krauss@42192
   319
JD_confs = 'JD_NS JD_FTA JD_Hoare JD_SN JD_Arrow JD_FFT JD_Jinja JD_QE JD_S2S'.split(' ')
krauss@42192
   320
krauss@42192
   321
@scheduler()
krauss@42197
   322
def judgement_day_scheduler(env):
krauss@42192
   323
    """Scheduler for Judgement Day."""
krauss@42192
   324
    return schedule.age_scheduler(env, 'Isabelle', JD_confs)
krauss@42192
   325
krauss@42192
   326
krauss@42116
   327
# SML/NJ
krauss@42116
   328
krauss@42116
   329
smlnj_settings = '''
krauss@42116
   330
ML_SYSTEM=smlnj
wenzelm@53658
   331
ML_HOME="/home/smlnj/110.76/bin"
wenzelm@48443
   332
ML_OPTIONS="@SMLdebug=/dev/null @SMLalloc=1024"
krauss@42116
   333
ML_PLATFORM=$(eval $("$ML_HOME/.arch-n-opsys" 2>/dev/null); echo "$HEAP_SUFFIX")
krauss@42116
   334
'''
krauss@42116
   335
krauss@48686
   336
@configuration(repos = [Isabelle], deps = [(Pure, [0])])
krauss@42116
   337
def SML_HOL(*args):
krauss@42116
   338
    """HOL image built with SML/NJ"""
krauss@50599
   339
    return isabelle_build(*(args + ("-b", "HOL")), more_settings=smlnj_settings, timeout=SMLNJ_TIMEOUT)
krauss@42116
   340
krauss@42116
   341
@configuration(repos = [Isabelle], deps = [])
krauss@42116
   342
def SML_makeall(*args):
krauss@48686
   343
    """SML/NJ build of all possible sessions"""
krauss@50599
   344
    return isabelle_build(*(args + ("-j", "3", "-a")), more_settings=smlnj_settings, timeout=SMLNJ_TIMEOUT)
krauss@48686
   345
krauss@48686
   346