Admin/mira.py
author krauss
Fri Apr 01 16:29:58 2011 +0200 (2011-04-01)
changeset 42197 5f311600ba26
parent 42192 906780d5138e
child 42392 0045b85101c9
permissions -rw-r--r--
fixed accidental redefinition
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
haftmann@41542
     9
import re
haftmann@41542
    10
haftmann@41542
    11
import util
haftmann@41542
    12
krauss@42192
    13
from mira import schedule
krauss@42192
    14
from mira.environment import scheduler
krauss@42192
    15
haftmann@41542
    16
haftmann@41542
    17
# build and evaluation tools
haftmann@41542
    18
krauss@42113
    19
def prepare_isabelle_repository(loc_isabelle, loc_contrib, loc_dependency_heaps, parallelism = True, more_settings=''):
haftmann@41542
    20
haftmann@41542
    21
    loc_contrib = path.expanduser(loc_contrib)
haftmann@41542
    22
    if not path.exists(loc_contrib):
haftmann@41542
    23
        raise IOError('Bad file: %s' % loc_contrib)
haftmann@41542
    24
    subprocess.check_call(['ln', '-s', loc_contrib, '%s/contrib' % loc_isabelle])
haftmann@41542
    25
haftmann@41542
    26
    contributed_components = path.join(loc_isabelle, 'Admin', 'contributed_components')
haftmann@41542
    27
    if path.exists(contributed_components):
haftmann@41542
    28
        components = []
haftmann@41542
    29
        for component in util.readfile_lines(contributed_components):
haftmann@41542
    30
            loc_component = path.join(loc_isabelle, component)
haftmann@41542
    31
            if path.exists(loc_component):
haftmann@41542
    32
                components.append(loc_component)
haftmann@41542
    33
        writer = open(path.join(loc_isabelle, 'etc', 'components'), 'a')
haftmann@41542
    34
        for component in components:
haftmann@41542
    35
            writer.write(component + '\n')
haftmann@41542
    36
        writer.close()
haftmann@41542
    37
haftmann@41542
    38
    if loc_dependency_heaps:
haftmann@41542
    39
        isabelle_path = loc_dependency_heaps + '/$ISABELLE_IDENTIFIER:$ISABELLE_OUTPUT'
haftmann@41542
    40
    else:
haftmann@41542
    41
        isabelle_path = '$ISABELLE_OUTPUT'
haftmann@41542
    42
haftmann@41542
    43
    if parallelism:
haftmann@41542
    44
        parallelism_options = '-M max'
haftmann@41542
    45
    else:
haftmann@41542
    46
        parallelism_options = '-M 1 -q 0'
haftmann@41542
    47
haftmann@41542
    48
    extra_settings = '''
haftmann@41542
    49
ISABELLE_HOME_USER="$ISABELLE_HOME/home_user"
haftmann@41542
    50
ISABELLE_OUTPUT="$ISABELLE_HOME/heaps"
haftmann@41542
    51
ISABELLE_BROWSER_INFO="$ISABELLE_HOME/browser_info"
haftmann@41542
    52
ISABELLE_PATH="%s"
haftmann@41542
    53
haftmann@41542
    54
ISABELLE_USEDIR_OPTIONS="$ISABELLE_USEDIR_OPTIONS %s -t true -v true -d pdf -g true -i true"
krauss@42109
    55
Z3_NON_COMMERCIAL="yes"
krauss@42113
    56
%s
krauss@42113
    57
''' % (isabelle_path, parallelism_options, more_settings)
haftmann@41542
    58
haftmann@41542
    59
    writer = open(path.join(loc_isabelle, 'etc', 'settings'), 'a')
haftmann@41542
    60
    writer.write(extra_settings)
haftmann@41542
    61
    writer.close()
haftmann@41542
    62
haftmann@41542
    63
haftmann@41542
    64
def extract_isabelle_run_timing(logdata):
haftmann@41542
    65
haftmann@41542
    66
    def to_secs(h, m, s):
haftmann@41542
    67
        return (int(h) * 60 + int(m)) * 60 + int(s)
haftmann@41542
    68
    pat = r'Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time'
krauss@42186
    69
    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
    70
    t = dict((name, {'elapsed': to_secs(eh,em,es), 'cpu': to_secs(ch,cm,cs)})
haftmann@41542
    71
             for name, eh, em, es, ch, cm, cs in re.findall(pat, logdata))
krauss@42186
    72
    for name, threads, elapsed, cpu, gc, factor in re.findall(pat2, logdata):
haftmann@41542
    73
haftmann@41542
    74
        if name not in t:
haftmann@41542
    75
            t[name] = {}
haftmann@41542
    76
haftmann@41542
    77
        t[name]['threads'] = int(threads)
haftmann@41542
    78
        t[name]['elapsed_inner'] = elapsed
haftmann@41542
    79
        t[name]['cpu_inner'] = cpu
haftmann@41542
    80
        t[name]['gc'] = gc
krauss@42186
    81
        t[name]['factor'] = factor
haftmann@41542
    82
haftmann@41542
    83
    return t
haftmann@41542
    84
haftmann@41542
    85
haftmann@41542
    86
def extract_isabelle_run_summary(logdata):
haftmann@41542
    87
krauss@41894
    88
    re_error = re.compile(r'^(?:make: )?\*\*\* (.*)$', re.MULTILINE)
haftmann@41542
    89
    summary = '\n'.join(re_error.findall(logdata))
haftmann@41542
    90
    if summary == '':
haftmann@41542
    91
        summary = 'ok'
haftmann@41542
    92
haftmann@41542
    93
    return summary
haftmann@41542
    94
haftmann@41542
    95
haftmann@41542
    96
def isabelle_usedir(env, isa_path, isabelle_usedir_opts, base_image, dir_name):
haftmann@41542
    97
haftmann@41542
    98
    return env.run_process('%s/bin/isabelle' % isa_path, 'usedir',
haftmann@41542
    99
        isabelle_usedir_opts, base_image, dir_name)
haftmann@41542
   100
haftmann@41542
   101
haftmann@41542
   102
def isabelle_dependency_only(env, case, paths, dep_paths, playground):
haftmann@41542
   103
krauss@42114
   104
    isabelle_home = paths[0]
krauss@42114
   105
    result = path.join(isabelle_home, 'heaps')
haftmann@41542
   106
    os.makedirs(result)
haftmann@41542
   107
    for dep_path in dep_paths:
haftmann@41542
   108
        subprocess.check_call(['cp', '-R'] + glob(dep_path + '/*') + [result])
haftmann@41542
   109
haftmann@41542
   110
    return (True, 'ok', {}, {}, result)
haftmann@41542
   111
haftmann@41542
   112
krauss@42113
   113
def build_isabelle_image(subdir, base, img, env, case, paths, dep_paths, playground, more_settings=''):
haftmann@41542
   114
krauss@42114
   115
    isabelle_home = paths[0]
haftmann@41542
   116
    dep_path = dep_paths[0]
krauss@42120
   117
    prepare_isabelle_repository(isabelle_home, env.settings.contrib, dep_path, more_settings=more_settings)
krauss@42114
   118
    os.chdir(path.join(isabelle_home, 'src', subdir))
haftmann@41542
   119
krauss@42114
   120
    (return_code, log) = isabelle_usedir(env, isabelle_home, '-b', base, img)
haftmann@41542
   121
krauss@42114
   122
    result = path.join(isabelle_home, 'heaps')
haftmann@41542
   123
    return (return_code == 0, extract_isabelle_run_summary(log),
haftmann@41542
   124
      {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
haftmann@41542
   125
haftmann@41542
   126
krauss@42140
   127
def isabelle_make(subdir, env, case, paths, dep_paths, playground, more_settings='', target='all', keep_results=False):
krauss@42115
   128
krauss@42115
   129
    isabelle_home = paths[0]
krauss@42115
   130
    dep_path = dep_paths[0] if dep_paths else None
krauss@42115
   131
    prepare_isabelle_repository(isabelle_home, env.settings.contrib, dep_path, more_settings=more_settings)
krauss@42115
   132
    os.chdir(path.join(isabelle_home, subdir))
krauss@42115
   133
krauss@42115
   134
    (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'make', '-k', target)
krauss@42115
   135
krauss@42140
   136
    result = path.join(isabelle_home, 'heaps') if keep_results else None
krauss@42115
   137
    return (return_code == 0, extract_isabelle_run_summary(log),
krauss@42140
   138
      {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
krauss@42115
   139
krauss@42115
   140
krauss@42121
   141
def isabelle_makeall(env, case, paths, dep_paths, playground, more_settings='', target='all', make_options=()):
haftmann@41542
   142
krauss@42114
   143
    isabelle_home = paths[0]
krauss@42115
   144
    dep_path = dep_paths[0] if dep_paths else None
krauss@42114
   145
    prepare_isabelle_repository(isabelle_home, env.settings.contrib, dep_path, more_settings=more_settings)
krauss@42114
   146
    os.chdir(isabelle_home)
haftmann@41542
   147
krauss@42121
   148
    (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'makeall', '-k', *(make_options + (target,)))
haftmann@41542
   149
haftmann@41542
   150
    return (return_code == 0, extract_isabelle_run_summary(log),
haftmann@41542
   151
      {'timing': extract_isabelle_run_timing(log)}, {'log': log}, None)
haftmann@41542
   152
haftmann@41542
   153
haftmann@41542
   154
# Isabelle configurations
haftmann@41542
   155
haftmann@41542
   156
@configuration(repos = [Isabelle], deps = [])
haftmann@41542
   157
def Pure(env, case, paths, dep_paths, playground):
haftmann@41542
   158
    """Pure image"""
haftmann@41542
   159
krauss@42114
   160
    isabelle_home = paths[0]
krauss@42114
   161
    prepare_isabelle_repository(isabelle_home, env.settings.contrib, '')
krauss@42114
   162
    os.chdir(path.join(isabelle_home, 'src', 'Pure'))
haftmann@41542
   163
krauss@42114
   164
    (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'make', 'Pure')
haftmann@41542
   165
krauss@42114
   166
    result = path.join(isabelle_home, 'heaps')
haftmann@41542
   167
    return (return_code == 0, extract_isabelle_run_summary(log),
haftmann@41542
   168
      {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
haftmann@41542
   169
haftmann@41542
   170
@configuration(repos = [Isabelle], deps = [(Pure, [0])])
haftmann@41542
   171
def FOL(*args):
haftmann@41542
   172
    """FOL image"""
haftmann@41542
   173
    return build_isabelle_image('FOL', 'Pure', 'FOL', *args)
haftmann@41542
   174
haftmann@41542
   175
@configuration(repos = [Isabelle], deps = [(Pure, [0])])
haftmann@41542
   176
def HOL(*args):
haftmann@41542
   177
    """HOL image"""
haftmann@41542
   178
    return build_isabelle_image('HOL', 'Pure', 'HOL', *args)
haftmann@41542
   179
haftmann@41542
   180
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   181
def HOL_HOLCF(*args):
haftmann@41542
   182
    """HOL-HOLCF image"""
haftmann@41542
   183
    return build_isabelle_image('HOL/HOLCF', 'HOL', 'HOLCF', *args)
haftmann@41542
   184
haftmann@41542
   185
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   186
def HOL_Nominal(*args):
haftmann@41542
   187
    """HOL-Nominal image"""
haftmann@41542
   188
    return build_isabelle_image('HOL/Nominal', 'HOL', 'HOL-Nominal', *args)
haftmann@41542
   189
haftmann@41542
   190
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   191
def HOL_Word(*args):
haftmann@41542
   192
    """HOL-Word image"""
haftmann@41542
   193
    return build_isabelle_image('HOL/Word', 'HOL', 'HOL-Word', *args)
haftmann@41542
   194
haftmann@41542
   195
@configuration(repos = [Isabelle], deps = [
haftmann@41542
   196
    (HOL, [0]),
haftmann@41542
   197
    (HOL_HOLCF, [0]),
haftmann@41542
   198
    (HOL_Nominal, [0]),
haftmann@41542
   199
    (HOL_Word, [0])
haftmann@41542
   200
  ])
haftmann@41542
   201
def AFP_images(*args):
haftmann@41542
   202
    """Isabelle images needed for the AFP"""
haftmann@41542
   203
    return isabelle_dependency_only(*args)
haftmann@41542
   204
haftmann@41542
   205
@configuration(repos = [Isabelle], deps = [
haftmann@41542
   206
    (AFP_images, [0])
haftmann@41542
   207
  ])
haftmann@41542
   208
def Isabelle_makeall(*args):
haftmann@41542
   209
    """Isabelle makeall"""
haftmann@41542
   210
    return isabelle_makeall(*args)
haftmann@41542
   211
haftmann@41542
   212
haftmann@41542
   213
# Mutabelle configurations
haftmann@41542
   214
haftmann@41542
   215
def invoke_mutabelle(theory, env, case, paths, dep_paths, playground):
haftmann@41542
   216
haftmann@41542
   217
    """Mutant testing for counterexample generators in Isabelle"""
haftmann@41542
   218
haftmann@41542
   219
    (loc_isabelle,) = paths
haftmann@41542
   220
    (dep_isabelle,) = dep_paths
haftmann@41542
   221
    prepare_isabelle_repository(loc_isabelle, env.settings.contrib, dep_isabelle)
haftmann@41542
   222
    os.chdir(loc_isabelle)
haftmann@41542
   223
    
haftmann@41542
   224
    (return_code, log) = env.run_process('bin/isabelle',
haftmann@41542
   225
      'mutabelle', '-O', playground, theory)
haftmann@41542
   226
    
haftmann@41542
   227
    try:
haftmann@41542
   228
        mutabelle_log = util.readfile(path.join(playground, 'log'))
haftmann@41542
   229
    except IOError:
haftmann@41542
   230
        mutabelle_log = ''
haftmann@41542
   231
haftmann@41542
   232
    return (return_code == 0 and mutabelle_log != '', extract_isabelle_run_summary(log),
haftmann@41652
   233
      {'timing': extract_isabelle_run_timing(log)},
haftmann@41652
   234
      {'log': log, 'mutabelle_log': mutabelle_log}, None)
haftmann@41542
   235
haftmann@41542
   236
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   237
def Mutabelle_Relation(*args):
haftmann@41542
   238
    """Mutabelle regression suite on Relation theory"""
haftmann@41542
   239
    return invoke_mutabelle('Relation', *args)
haftmann@41542
   240
haftmann@41542
   241
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   242
def Mutabelle_List(*args):
haftmann@41542
   243
    """Mutabelle regression suite on List theory"""
haftmann@41542
   244
    return invoke_mutabelle('List', *args)
haftmann@41542
   245
haftmann@41542
   246
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   247
def Mutabelle_Set(*args):
haftmann@41542
   248
    """Mutabelle regression suite on Set theory"""
haftmann@41542
   249
    return invoke_mutabelle('Set', *args)
haftmann@41542
   250
haftmann@41542
   251
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   252
def Mutabelle_Map(*args):
haftmann@41542
   253
    """Mutabelle regression suite on Map theory"""
haftmann@41542
   254
    return invoke_mutabelle('Map', *args)
haftmann@41542
   255
haftmann@41542
   256
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   257
def Mutabelle_Divides(*args):
haftmann@41542
   258
    """Mutabelle regression suite on Divides theory"""
haftmann@41542
   259
    return invoke_mutabelle('Divides', *args)
haftmann@41542
   260
haftmann@41542
   261
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   262
def Mutabelle_MacLaurin(*args):
haftmann@41542
   263
    """Mutabelle regression suite on MacLaurin theory"""
haftmann@41542
   264
    return invoke_mutabelle('MacLaurin', *args)
haftmann@41542
   265
haftmann@41542
   266
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
haftmann@41542
   267
def Mutabelle_Fun(*args):
haftmann@41542
   268
    """Mutabelle regression suite on Fun theory"""
haftmann@41542
   269
    return invoke_mutabelle('Fun', *args)
krauss@42040
   270
krauss@42040
   271
krauss@42040
   272
# Judgement Day configurations
krauss@42040
   273
krauss@42095
   274
judgement_day_provers = ('e', 'spass', 'vampire', 'z3', 'cvc3', 'yices')
krauss@42040
   275
krauss@42040
   276
def judgement_day(base_path, theory, opts, env, case, paths, dep_paths, playground):
krauss@42040
   277
    """Judgement Day regression suite"""
krauss@42040
   278
krauss@42040
   279
    isa = paths[0]
krauss@42040
   280
    dep_path = dep_paths[0]
krauss@42040
   281
krauss@42040
   282
    os.chdir(path.join(playground, '..', base_path)) # Mirabelle requires specific cwd
krauss@42040
   283
    prepare_isabelle_repository(isa, env.settings.contrib, dep_path)
krauss@42040
   284
krauss@42040
   285
    output = {}
krauss@42040
   286
    success_rates = {}
krauss@42040
   287
    some_success = False
krauss@42040
   288
krauss@42040
   289
    for atp in judgement_day_provers:
krauss@42040
   290
krauss@42040
   291
        log_dir = path.join(playground, 'mirabelle_log_' + atp)
krauss@42040
   292
        os.makedirs(log_dir)
krauss@42040
   293
krauss@42040
   294
        cmd = ('%s/bin/isabelle mirabelle -q -O %s sledgehammer[prover=%s,%s] %s.thy'
krauss@42040
   295
               % (isa, log_dir, atp, opts, theory))
krauss@42040
   296
krauss@42040
   297
        os.system(cmd)
krauss@42040
   298
        output[atp] = util.readfile(path.join(log_dir, theory + '.log'))
krauss@42040
   299
krauss@42040
   300
        percentages = list(re.findall(r'Success rate: (\d+)%', output[atp]))
krauss@42040
   301
        if len(percentages) == 2:
krauss@42040
   302
            success_rates[atp] = {
krauss@42040
   303
                'sledgehammer': int(percentages[0]),
krauss@42040
   304
                'metis': int(percentages[1])}
krauss@42040
   305
            if success_rates[atp]['sledgehammer'] > 0:
krauss@42040
   306
                some_success = True
krauss@42040
   307
        else:
krauss@42040
   308
            success_rates[atp] = {}
krauss@42040
   309
krauss@42040
   310
krauss@42040
   311
    data = {'success_rates': success_rates}
krauss@42040
   312
    raw_attachments = dict((atp + "_output", output[atp]) for atp in judgement_day_provers)
krauss@42040
   313
    # FIXME: summary?
krauss@42040
   314
    return (some_success, '', data, raw_attachments, None)
krauss@42040
   315
krauss@42040
   316
krauss@42040
   317
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   318
def JD_NS(*args):
krauss@42040
   319
    """Judgement Day regression suite NS"""
krauss@42040
   320
    return judgement_day('Isabelle/src/HOL/Auth', 'NS_Shared', 'prover_timeout=10', *args)
krauss@42040
   321
krauss@42040
   322
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   323
def JD_FTA(*args):
krauss@42040
   324
    """Judgement Day regression suite FTA"""
krauss@42040
   325
    return judgement_day('Isabelle/src/HOL/Library', 'Fundamental_Theorem_Algebra', 'prover_timeout=10', *args)
krauss@42040
   326
krauss@42040
   327
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   328
def JD_Hoare(*args):
krauss@42040
   329
    """Judgement Day regression suite Hoare"""
krauss@42058
   330
    return judgement_day('Isabelle/src/HOL/IMPP', 'Hoare', 'prover_timeout=10', *args)
krauss@42040
   331
krauss@42040
   332
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
krauss@42040
   333
def JD_SN(*args):
krauss@42040
   334
    """Judgement Day regression suite SN"""
krauss@42058
   335
    return judgement_day('Isabelle/src/HOL/Proofs/Lambda', 'StrongNorm', 'prover_timeout=10', *args)
krauss@42040
   336
krauss@42116
   337
krauss@42192
   338
JD_confs = 'JD_NS JD_FTA JD_Hoare JD_SN JD_Arrow JD_FFT JD_Jinja JD_QE JD_S2S'.split(' ')
krauss@42192
   339
krauss@42192
   340
@scheduler()
krauss@42197
   341
def judgement_day_scheduler(env):
krauss@42192
   342
    """Scheduler for Judgement Day."""
krauss@42192
   343
    return schedule.age_scheduler(env, 'Isabelle', JD_confs)
krauss@42192
   344
krauss@42192
   345
krauss@42116
   346
# SML/NJ
krauss@42116
   347
krauss@42116
   348
smlnj_settings = '''
krauss@42116
   349
ML_SYSTEM=smlnj
krauss@42116
   350
ML_HOME="/home/smlnj/110.72/bin"
krauss@42116
   351
ML_OPTIONS="@SMLdebug=/dev/null @SMLalloc=256"
krauss@42116
   352
ML_PLATFORM=$(eval $("$ML_HOME/.arch-n-opsys" 2>/dev/null); echo "$HEAP_SUFFIX")
krauss@42116
   353
'''
krauss@42116
   354
krauss@42116
   355
@configuration(repos = [Isabelle], deps = [])
krauss@42116
   356
def SML_HOL(*args):
krauss@42116
   357
    """HOL image built with SML/NJ"""
krauss@42140
   358
    return isabelle_make('src/HOL', *args, more_settings=smlnj_settings, target='HOL', keep_results=True)
krauss@42116
   359
krauss@42116
   360
@configuration(repos = [Isabelle], deps = [])
krauss@42116
   361
def SML_makeall(*args):
krauss@42116
   362
    """Makeall built with SML/NJ"""
krauss@42138
   363
    return isabelle_makeall(*args, more_settings=smlnj_settings, target='smlnj', make_options=('-j', '3'))