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