示例#1
0
文件: make.py 项目: fritzo/pomagma
def profile_cartographer(theory='skj', extra_size=0, tool='time', infer=True):
    '''
    Profile cartographer load-infer-dump on region of world.
    Available tools: time, valgrind, cachegrind, callgrind, helgrind
    '''
    size = pomagma.util.MIN_SIZES[theory] + extra_size
    with atlas.chdir(theory):
        opts = {'log_file': 'profile.log', 'log_level': 2}
        region = DB('region.normal.{:d}'.format(size))
        temp = pomagma.util.temp_name(DB('profile'))
        world = DB('world')
        world_size = atlas.get_item_count(world)
        if size >= world_size:
            print 'Using world of size {}'.format(world_size)
            region = world
        elif not os.path.exists(region):
            print 'Creating {} for profile'.format(region)
            assert os.path.exists(world), 'First initialize world map'
            with cartographer.load(theory, world, **opts) as db:
                db.trim([{'size': size, 'filename': region}])
        opts.setdefault('runner', PROFILERS.get(tool, tool))
        with cartographer.load(theory, region, **opts) as db:
            if infer:
                for priority in [0, 1]:
                    count = db.infer(priority)
                    print 'Proved {} theorems'.format(count)
            db.dump(temp)
        print 'Hash:', atlas.get_hash(temp)
        os.remove(temp)
示例#2
0
def trim(theory=THEORY, parallel=True, **options):
    '''
    Trim a set of normal regions for running analyst on small machines.
    Options: log_level, log_file
    '''
    with atlas.chdir(theory):
        options.setdefault('log_file', 'trim.log')
        with cartographer.load(theory, 'world.normal.h5', **options) as db:
            min_size = pomagma.util.MIN_SIZES[theory]
            max_size = db.info()['item_count']
            sizes = sparse_range(min_size, max_size)
            tasks = []
            for size in sizes:
                tasks.append({
                    'size': size,
                    'temperature': 0,
                    'filename': 'region.normal.{:d}.h5'.format(size)
                })
            if parallel:
                print 'Trimming {} regions of sizes {}-{}'.format(
                    len(sizes),
                    sizes[0],
                    sizes[-1])
                db.trim(tasks)
            else:
                for task in tasks:
                    print 'Trimming region of size {}'.format(task['size'])
                    db.trim([task])
示例#3
0
def theorize(theory=THEORY, **options):
    """Make conjectures based on atlas and update atlas based on theorems."""
    with atlas.chdir(theory):
        world = DB('world')
        diverge_conjectures = 'diverge_conjectures.facts'
        diverge_theorems = 'diverge_theorems.facts'
        equal_conjectures = 'equal_conjectures.facts'
        nless_theorems = 'nless_theorems.facts'
        assert already_exists(world), 'First build world map'
        options.setdefault('log_file', 'theorize.log')

        with atlas.load(theory, world, **options) as db:
            db.conjecture(diverge_conjectures, equal_conjectures)
            with pomagma.util.temp_copy(diverge_conjectures) as temp:
                theorem_count = theorist.try_prove_diverge(
                    diverge_conjectures,
                    temp,
                    diverge_theorems,
                    **options)
            if theorem_count > 0:
                db.assume(diverge_theorems)
                db.dump(world)

        with pomagma.util.temp_copy(equal_conjectures) as temp:
            theorem_count = theorist.try_prove_nless(
                theory,
                world,
                equal_conjectures,
                temp,
                nless_theorems,
                **options)
        if theorem_count > 0:
            with atlas.load(theory, world, **options) as db:
                db.assume(nless_theorems)
                db.dump(world)
示例#4
0
def _analyze(theory=THEORY, size=None, address=analyst.ADDRESS, **options):
    with atlas.chdir(theory):
        options.setdefault('log_file', 'analyst.log')
        if size is None:
            world = DB('world.normal')
        else:
            world = DB('region.normal.{}'.format(size))
        assert os.path.exists(world), 'First initialize normalized world'
        return analyst.serve(theory, world, address=address, **options)
示例#5
0
文件: make.py 项目: fritzo/pomagma
def test_analyst(theory):
    """Test analyst approximation on normalized world map."""
    opts = {'log_file': 'test.log', 'log_level': 2}
    with atlas.chdir(theory):
        world = DB('world.normal')
        assert os.path.exists(world), 'First initialize normalized world'
        with analyst.load(theory, world, **opts) as db:
            fail_count = db.test()
    assert fail_count == 0, 'Failed {} cases'.format(fail_count)
    print 'Passed analyst test'
示例#6
0
文件: batch.py 项目: imclab/pomagma
def test_analyst(theory, **options):
    '''
    Test analyst approximation on normalized world map.
    '''
    options.setdefault('log_file', 'test.log')
    with atlas.chdir(theory):
        world = 'world.normal.h5'
        assert os.path.exists(world), 'First initialize normalized world'
        with analyst.load(theory, world, **options) as db:
            fail_count = db.test()
    assert fail_count == 0, 'Failed {} cases'.format(fail_count)
    print 'Passed analyst test'
示例#7
0
def update_theory(theory=THEORY, dry_run=False, **options):
    """Update (small) world map after theory changes, and note changes.

    Options: log_level, log_file

    """
    print dry_run
    with atlas.chdir(theory):
        world = DB('world')
        updated = pomagma.util.temp_name(DB('world'))
        assert already_exists(world), 'First initialize world map'
        options.setdefault('log_file', 'update_theory.log')
        atlas.update_theory(theory, world, updated, dry_run=dry_run, **options)
示例#8
0
def translate(theory=THEORY, **options):
    '''
    Translate language of world map (e.g. when language changes).
    Options: log_level, log_file
    '''
    with atlas.chdir(theory):
        world = 'world.h5'
        init = pomagma.util.temp_name('init.h5')
        aggregate = pomagma.util.temp_name('aggregate.h5')
        assert already_exists(world), 'First initialize world map'
        options.setdefault('log_file', 'translate.log')
        init_size = pomagma.util.MIN_SIZES[theory]
        surveyor.init(theory, init, init_size, **options)
        atlas.translate(theory, init, world, aggregate, **options)
示例#9
0
def update_language(theory=THEORY, **options):
    """Update world map after language changes.

    Options: log_level, log_file

    """
    with atlas.chdir(theory):
        world = DB('world')
        init = pomagma.util.temp_name(DB('init'))
        aggregate = pomagma.util.temp_name(DB('aggregate'))
        assert already_exists(world), 'First initialize world map'
        options.setdefault('log_file', 'update_language.log')
        init_size = pomagma.util.MIN_SIZES[theory]
        surveyor.init(theory, init, init_size, **options)
        atlas.update_language(theory, init, world, aggregate, **options)
示例#10
0
文件: batch.py 项目: imclab/pomagma
def analyze(theory, size=None, address=analyst.ADDRESS, **options):
    '''
    Run analyst server on normalized world map.
    '''
    with atlas.chdir(theory):
        options.setdefault('log_file', 'analyst.log')
        if size is None:
            world = 'world.normal.h5'
        else:
            world = 'region.normal.{}.h5'.format(size)
        assert os.path.exists(world), 'First initialize normalized world'
        try:
            server = analyst.serve(theory, world, **options)
            server.wait()
        finally:
            server.stop()
示例#11
0
文件: batch.py 项目: imclab/pomagma
def init(theory, **options):
    '''
    Initialize world map for given theory.
    Options: log_level, log_file
    '''
    log_file = options.setdefault('log_file', 'init.log')
    world_size = pomagma.util.MIN_SIZES[theory]
    pomagma.util.log_print('initialize to {}'.format(world_size), log_file)
    with atlas.chdir(theory, init=True):
        survey = 'survey.h5'
        world = 'world.h5'
        with pomagma.util.temp_copy(survey) as temp:
            surveyor.init(theory, temp, world_size, **options)
        with atlas.load(theory, survey, **options) as db:
            assert not os.path.exists(world), world
            db.validate()
            db.dump(world)
示例#12
0
文件: make.py 项目: fritzo/pomagma
def profile_surveyor(theory='skj', grow_by=64, extra_size=0, tool='time'):
    """Profile surveyor on random region of world.

    Available tools: time, valgrind, cachegrind, callgrind, helgrind

    """
    size = pomagma.util.MIN_SIZES[theory] + extra_size
    with atlas.chdir(theory):
        opts = {'log_file': 'profile.log', 'log_level': 2}
        region = DB('region.normal.{:d}'.format(size))
        temp = pomagma.util.temp_name(DB('profile'))
        world = DB('world')
        if not os.path.exists(region):
            print 'Creating {} for profile'.format(region)
            assert os.path.exists(world), 'First initialize world map'
            with cartographer.load(theory, world, **opts) as db:
                db.trim([{'size': size, 'filename': region}])
        opts.setdefault('runner', PROFILERS.get(tool, tool))
        surveyor.survey(theory, region, temp, size + grow_by, **opts)
        os.remove(temp)
示例#13
0
def analyze(theory=THEORY, size=None, address=analyst.ADDRESS, **options):
    """Run analyst server on normalized world map.

    Set size=? to list available sizes.
    Options: log_level, log_file

    """
    if size == '?':
        with atlas.chdir(theory):
            files = glob.glob(DB('region.normal.*'))
            sizes = sorted(int(re.search('\d+', f).group()) for f in files)
        print 'Try one of: {}'.format(' '.join(str(s) for s in sizes))
        sys.exit(1)
    server = _analyze(theory, size, address, **options)
    try:
        server.wait()
    except KeyboardInterrupt:
        print 'stopping analyst'
    finally:
        server.stop()
示例#14
0
def analyze(theory=THEORY, size=None, address=analyst.ADDRESS, **options):
    '''
    Run analyst server on normalized world map.
    Options: log_level, log_file
    '''
    with atlas.chdir(theory):
        print 'DEBUG', theory
        print 'DEBUG', os.getcwd()
        options.setdefault('log_file', 'analyst.log')
        if size is None:
            world = 'world.normal.h5'
        else:
            world = 'region.normal.{}.h5'.format(size)
        assert os.path.exists(world), 'First initialize normalized world'
        try:
            server = analyst.serve(theory, world, address=address, **options)
            server.wait()
        except KeyboardInterrupt:
            print 'stopping analyst'
        finally:
            server.stop()
示例#15
0
def init(theory=THEORY, **options):
    """Initialize world map for given theory.

    Options: log_level, log_file

    """
    log_file = options.setdefault('log_file', 'init.log')
    world_size = pomagma.util.MIN_SIZES[theory]
    pomagma.util.log_print('initialize to {}'.format(world_size), log_file)
    with atlas.chdir(theory, init=True):
        survey = DB('survey')
        world = DB('world')
        normal = DB('world.normal')
        with pomagma.util.temp_copy(survey) as temp:
            surveyor.init(theory, temp, world_size, **options)
        with atlas.load(theory, survey, **options) as db:
            assert not already_exists(world), world
            assert not already_exists(normal), normal
            db.validate()
            db.dump(world)
            db.dump(normal)
示例#16
0
文件: make.py 项目: pomagma/pomagma
def profile_surveyor(theory, size_blocks=3, dsize_blocks=0):
    '''
    Profile surveyor through callgrind on random region of world.
    Inputs: theory, region size in blocks (1 block = 512 obs)
    '''
    size = size_blocks * 512 - 1
    dsize = dsize_blocks * 512
    min_size = pomagma.util.MIN_SIZES[theory]
    assert size >= min_size
    with atlas.chdir(theory):
        opts = {'log_file': 'profile.log', 'log_level': 2}
        region = 'region.{:d}.h5'.format(size)
        temp = pomagma.util.temp_name('profile.h5')
        world = 'world.h5'

        if not os.path.exists(region):
            assert os.path.exists(world), 'First initialize world map'
            with cartographer.load(theory, world, **opts) as db:
                db.trim({'size': size, 'filename': region})
        opts.setdefault('runner', 'valgrind --tool=callgrind')
        surveyor.survey(theory, region, temp, size + dsize, **opts)
        os.remove(temp)