Пример #1
0
def test_DebugUtils():
    code_tree = CodeTree('./code_base/basis_code.jcb', Example)

    hashes = set()
    code_by_hash = {}

    for use, variants in code_tree.variant_by_stackuse.items():
        for variant in variants:
            for code_item in code_tree.alleles_by_variant[variant]:
                hash = code_tree.hash_code(code_item)

                if hash in hashes:
                    for a, b in zip(code_by_hash[hash], code_item):
                        assert a.data == b.data

                hashes.add(hash)
                code_by_hash[hash] = code_item
Пример #2
0
    def __init__(self, code_base_fn, reward_data_fn, abstract_relation):
        CodeTree.__init__(self, code_base_fn, abstract_relation)

        if reward_data_fn is not None:
            self.train_reward_function(reward_data_fn)
Пример #3
0
def main(projectRoot, dirsNotToEnter):
   
    print('Creating CodeTree for %s' %(projectRoot))
    codeTree = CodeTree()
    codeTree.create(projectRoot, dirsNotToEnter)
    return codeTree
Пример #4
0
def main(projectRoot):

    print('Creating CodeTree for %s' % (projectRoot))
    codeTree = CodeTree()
    codeTree.create(projectRoot)
    return codeTree
Пример #5
0
def main(projectRoot):
   
    print('Creating CodeTree for %s' %(projectRoot))
    codeTree = CodeTree()
    codeTree.create(projectRoot)
    return codeTree
Пример #6
0
def test_instance_everything():
	a = Answer([[1, 0], [0, 1]])
	assert isinstance(a, Answer)
	assert Answer.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Bebop()
	assert isinstance(a, Bebop)
	assert Bebop.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Block('hello', Block.type_error)
	assert isinstance(a, Block)
	assert Block.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Bond(None, None)
	assert isinstance(a, Bond)
	assert Bond.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = BopBack()
	assert isinstance(a, BopBack)
	assert BopBack.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = BopForward()
	assert isinstance(a, BopForward)
	assert BopForward.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Code((Function(len, [Block.type_picture], Block.type_picture), Function(len, [Block.type_picture], Block.type_picture)))
	assert isinstance(a, Code)
	assert Code.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	code = a

	a = CodeBase()
	assert isinstance(a, CodeBase)
	assert CodeBase.__base__ == Container
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = CodeEval(Example)
	assert isinstance(a, CodeEval)
	assert CodeEval.__base__ == Field
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = CodeGen(None, None, Example)
	assert isinstance(a, CodeGen)
	assert CodeGen.__base__ == CodeTree
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = CodeTree(None, Example)
	assert isinstance(a, CodeTree)
	assert CodeTree.__base__ == CodeEval
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Core(code, [Block.new_picture(list_of_list=[[3, 2], [2, 3]])])
	assert isinstance(a, Core)
	assert Core.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Container()
	assert isinstance(a, Container)
	assert Container.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Context()
	assert isinstance(a, Context)
	assert Context.__base__ == Container
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Example([[3, 2], [2, 3]], [[1, 0], [0, 1]], False)
	assert isinstance(a, Example)
	assert Example.__base__ == Bond
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Field(Example)
	assert isinstance(a, Field)
	assert Field.__base__ == Bebop
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Function(len, Block.type_nothing, Block.type_nothing)
	assert isinstance(a, Function)
	assert Function.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = MCTS(None, None, Example)
	assert isinstance(a, MCTS)
	assert MCTS.__base__ == CodeGen
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = MctsNode()
	assert isinstance(a, MctsNode)
	assert MctsNode.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Problem()
	assert isinstance(a, Problem)
	assert Problem.__base__ == Container
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Question([[3, 2], [2, 3]])
	assert isinstance(a, Question)
	assert Question.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Search()
	assert isinstance(a, Search)
	assert Search.__base__ == object
	with pytest.raises(AttributeError):
		_ = a.__base__

	a = Source(('nop'))
	assert isinstance(a, Source)
	assert Source.__base__ == Block
	with pytest.raises(AttributeError):
		_ = a.__base__
Пример #7
0
def test_CodeTree():
    code_tree = CodeTree('./code_base/basis_code.jcb', Example)

    code_tree.build_opcodes_by_types()

    assert isinstance(code_tree.opcode_by_arg_type[Block.type_picture], dict)
    assert isinstance(
        code_tree.opcode_by_arg_type[Block.type_picture][Block.type_picture],
        dict)
    assert isinstance(
        code_tree.opcode_by_arg_type[Block.type_picture][Block.type_nothing],
        list)

    assert isinstance(code_tree.opcode_by_ret_type[Block.type_picture], list)
    assert Block.type_core not in code_tree.opcode_by_ret_type

    args_pic_nesw = code_tree.opcode_by_arg_type[Block.type_picture][
        Block.type_NESW][Block.type_nothing]

    assert BopForward.bopforward_pic_nesw_extend in args_pic_nesw

    code_tree.build_codeitems_from_codebase()
    code_tree.build_isomorphisms()

    nvs = 0
    nva = 0
    nci = 0
    np0 = 0
    npp = 0
    for use, variants in code_tree.variant_by_stackuse.items():
        nvs += 1
        for variant in variants:
            nva += 1
            for code_item in code_tree.alleles_by_variant[variant]:
                nci += 1

                assert code_item in code_tree.prior_by_codeitem

                if code_tree.prior_by_codeitem[code_item] == 0:
                    np0 += 1
                else:
                    npp += 1

    assert nvs >= 4 and nva > 250 and nci > 300 and np0 > 140 and npp > 150

    code_tree.aggregate_priors()

    sum_priors = 0
    for prior in code_tree.prior_by_codeitem.values():
        assert prior >= 1e-9 and prior <= 1
        sum_priors += prior

    sum_mp = 0
    items = 0
    last_prior = 0
    for use, moves in code_tree.item_prior_by_stackuse.items():
        nvs -= 1

        for i, (item, prior) in enumerate(moves):
            if i > 0:
                assert prior <= last_prior

            items += 1
            sum_mp += prior
            last_prior = prior

    assert nvs == 0 and math.isclose(sum_mp, sum_priors) and items == npp + np0