Exemple #1
0
def test():
    import numpy as np

    oracle = lambda x: x.T
    oracle = transpose3

    ex_set = []
    example = np.array([[1, 2], [1, 2]])

    # TODO: to add more than one formal parameter make sure to make first element of tuple a list
    ex_set.append((example, oracle(example)))
    input_shape = example.shape

    components = Components(
        {
            'transpose': 1,
            'eye_like': 1,
            'ones_like': 0,
            'multiply': 0,
            'add': 0,
            'matmul': 0
        }, input_shape)

    f = Formulate(ex_set, components.get_list())
    model = f.synthesize()
    f.Lval2Prog(model, components)
Exemple #2
0
def ogis(oracle):
    ex_set = []
    ishape = (2, 2)

    components = Components(
        {
            'transpose': 0,
            'eye_like': 1,
            'ones_like': 0,
            'multiply': 0,
            'add': 1,
            'matmul': 0
        }, ishape)
    ex_set.append((np.ones((2, 2)), oracle(np.ones((2, 2)))))

    example = np.eye(ishape[0])

    program_candidate = None

    while example is not None:
        ex_set.append((example, oracle(example)))

        f = Formulate(ex_set, components.get_list())
        satisfying_constraints = f.Behave_E()
        s = z3.Solver()
        s.add(satisfying_constraints)
        if (s.check() == z3.sat):
            I, unique_constraints = f.dist_constraint()
            s2 = z3.Solver()
            s2.add(unique_constraints)
            if (s2.check() == z3.sat):
                print("nonunique; getting new example")
                model = s2.model()
                example = np.array([[model.evaluate(i) for i in il]
                                    for il in I])
            else:
                print("unsat")
                #done
                program_candidate = f.Lval2Prog(s.model(), components)
                break
        else:
            print("No valid program candidate found")
            return False
    return program_candidate