Esempio n. 1
0
def test(theory=THEORY, extra_size=0, **options):
    """Test theory by building a world map.

    Options: log_level, log_file

    """
    buildtype = 'debug' if pomagma.util.debug else 'release'
    path = os.path.join(pomagma.util.DATA, 'test', buildtype, 'atlas', theory)
    if os.path.exists(path):
        os.system('rm -f {}/*'.format(path))
    else:
        os.makedirs(path)
    with pomagma.util.chdir(path), pomagma.util.mutex(block=False):
        options.setdefault('log_file', 'test.log')
        world = DB('test.world')
        diverge_conjectures = 'diverge_conjectures.facts'
        diverge_theorems = 'diverge_theorems.facts'
        equal_conjectures = 'equal_conjectures.facts'
        equal_theorems = 'equal_theorems.facts'

        size = pomagma.util.MIN_SIZES[theory] + extra_size
        surveyor.init(theory, world, size, **options)

        with cartographer.load(theory, world, **options) as db:
            db.validate()
            for priority in [0, 1]:
                while db.infer(priority):
                    db.validate()
            db.conjecture(diverge_conjectures, equal_conjectures)
            theorist.try_prove_diverge(
                diverge_conjectures,
                diverge_conjectures,
                diverge_theorems,
                **options)
            db.assume(diverge_theorems)
            db.validate()
            db.dump(world)

        theorist.try_prove_nless(
            theory,
            world,
            equal_conjectures,
            equal_conjectures,
            equal_theorems,
            **options)

        with cartographer.load(theory, world, **options) as db:
            db.assume(equal_theorems)
            db.validate()
            for priority in [0, 1]:
                while db.infer(priority):
                    db.validate()
            db.dump(world)

        with analyst.load(theory, world, **options) as db:
            fail_count = db.test_inference()
            assert fail_count == 0, 'analyst.test_inference failed'
    print 'Theory {} appears valid.'.format(theory)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
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)
Esempio n. 5
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)
Esempio n. 6
0
def _test_atlas(theory):
    '''
    Test basic operations in one theory:
        init, validate, copy, survey, aggregate,
        conjecture_diverge, conjecture_equal
    '''
    buildtype = 'debug' if pomagma.util.debug else 'release'
    path = os.path.join(pomagma.util.DATA, 'test', buildtype, 'atlas', theory)
    if os.path.exists(path):
        os.system('rm -f {}/*'.format(path))
    else:
        os.makedirs(path)
    with ExitStack() as stack:
        with_ = stack.enter_context
        with_(pomagma.util.chdir(path))
        with_(mock.patch('pomagma.util.BLOB_DIR', new=path))
        with_(pomagma.util.mutex(block=False))

        min_size = pomagma.util.MIN_SIZES[theory]
        dsize = min(64, 1 + min_size)
        sizes = [min_size + i * dsize for i in range(10)]
        opts = {'log_file': 'test.log', 'log_level': 2}
        diverge_conjectures = 'diverge_conjectures.facts'
        diverge_theorems = 'diverge_theorems.facts'
        equal_conjectures = 'equal_conjectures.facts'
        equal_theorems = 'equal_theorems.facts'

        surveyor.init(theory, DB(0), sizes[0], **opts)
        changed = atlas.update_theory(theory, DB(0), DB(1), **opts)
        assert not changed
        with cartographer.load(theory, DB(0), **opts) as db:
            db.validate()
            db.dump(DB(1))
            expected_size = atlas.get_item_count(DB(1))
            actual_size = db.info()['item_count']
            assert actual_size == expected_size
        surveyor.survey(theory, DB(1), DB(2), sizes[1], **opts)
        with cartographer.load(theory, DB(2), **opts) as db:
            db.trim([{'size': sizes[0], 'filename': DB(3)}])
        surveyor.survey(theory, DB(3), DB(4), sizes[1], **opts)
        with cartographer.load(theory, DB(2), **opts) as db:
            db.aggregate(DB(4))
            db.dump(DB(5))
        with cartographer.load(theory, DB(5), **opts) as db:
            db.aggregate(DB(0))
            db.dump(DB(6))
            digest5 = atlas.get_hash(DB(5))
            digest6 = atlas.get_hash(DB(6))
            assert digest5 == digest6

            counts = db.conjecture(diverge_conjectures, equal_conjectures)
            assert counts['diverge_count'] > 0, counts['diverge_count']
            assert counts['equal_count'] > 0, counts['equal_count']
            if theory != 'h4':
                theorem_count = theorist.try_prove_diverge(
                    diverge_conjectures,
                    diverge_conjectures,
                    diverge_theorems,
                    **opts)
                assert theorem_count > 0, theorem_count
                counts = db.assume(diverge_theorems)
                assert counts['pos'] + counts['neg'] > 0, counts
                assert counts['ignored'] == 0, counts
                db.validate()
                db.dump(DB(6))
        theorem_count = theorist.try_prove_nless(
            theory,
            DB(6),
            equal_conjectures,
            equal_conjectures,
            equal_theorems,
            **opts)
        # assert theorem_count > 0, theorem_count

        if theory != 'h4':
            with cartographer.load(theory, DB(6), **opts) as db:
                db.assume(equal_theorems)
                if theorem_count > 0:
                    assert counts['merge'] > 0, counts
                db.validate()
                for priority in [0, 1]:
                    while db.infer(priority):
                        db.validate()
                for priority in [0, 1]:
                    assert not db.infer(priority)
                db.dump(DB(7))
            with analyst.load(theory, DB(7), **opts) as db:
                fail_count = db.test_inference()
                assert fail_count == 0, 'analyst.test_inference failed'
        blobstore.validate_blobs()
Esempio n. 7
0
def _test_atlas(theory):
    '''
    Test basic operations in one theory:
        init, validate, copy, survey, aggregate,
        conjecture_diverge, conjecture_equal
    '''
    buildtype = 'debug' if pomagma.util.debug else 'release'
    path = os.path.join(pomagma.util.DATA, 'test', buildtype, 'atlas', theory)
    if os.path.exists(path):
        os.system('rm -f {}/*'.format(path))
    else:
        os.makedirs(path)
    with pomagma.util.chdir(path), pomagma.util.mutex(block=False):

        min_size = pomagma.util.MIN_SIZES[theory]
        dsize = min(64, 1 + min_size)
        sizes = [min_size + i * dsize for i in range(10)]
        opts = {'log_file': 'test.log', 'log_level': 2}
        diverge_conjectures = 'diverge_conjectures.facts'
        diverge_theorems = 'diverge_theorems.facts'
        equal_conjectures = 'equal_conjectures.facts'
        equal_theorems = 'equal_theorems.facts'

        surveyor.init(theory, '0.h5', sizes[0], **opts)
        with cartographer.load(theory, '0.h5', **opts) as db:
            db.validate()
            db.dump('1.h5')
            expected_size = pomagma.util.get_item_count('1.h5')
            actual_size = db.info()['item_count']
            assert actual_size == expected_size
        surveyor.survey(theory, '1.h5', '2.h5', sizes[1], **opts)
        with cartographer.load(theory, '2.h5', **opts) as db:
            db.trim([{'size': sizes[0], 'filename': '3.h5'}])
        surveyor.survey(theory, '3.h5', '4.h5', sizes[1], **opts)
        with cartographer.load(theory, '2.h5', **opts) as db:
            db.aggregate('4.h5')
            db.dump('5.h5')
        with cartographer.load(theory, '5.h5', **opts) as db:
            db.aggregate('0.h5')
            db.dump('6.h5')
            digest5 = pomagma.util.get_hash('5.h5')
            digest6 = pomagma.util.get_hash('6.h5')
            assert digest5 == digest6

            counts = db.conjecture(diverge_conjectures, equal_conjectures)
            assert counts['diverge_count'] > 0, counts['diverge_count']
            assert counts['equal_count'] > 0, counts['equal_count']
            if theory != 'h4':
                theorem_count = theorist.try_prove_diverge(
                    diverge_conjectures,
                    diverge_conjectures,
                    diverge_theorems,
                    **opts)
                assert theorem_count > 0, theorem_count
                counts = db.assume(diverge_theorems)
                assert counts['pos'] + counts['neg'] > 0, counts
                db.validate()
                db.dump('6.h5')
        theorem_count = theorist.try_prove_nless(
            theory,
            '6.h5',
            equal_conjectures,
            equal_conjectures,
            equal_theorems,
            **opts)
        # assert theorem_count > 0, theorem_count

        if theory != 'h4':
            with cartographer.load(theory, '6.h5', **opts) as db:
                db.assume(equal_theorems)
                if theorem_count > 0:
                    assert counts['merge'] > 0, counts
                db.validate()
                for priority in [0, 1]:
                    while db.infer(priority):
                        db.validate()
                for priority in [0, 1]:
                    assert not db.infer(priority)
                db.dump('7.h5')
            with analyst.load(theory, '7.h5', **opts) as db:
                fail_count = db.test_inference()
                assert fail_count == 0, 'analyst.test_inference failed'