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