Exemplo n.º 1
0
def main():
    logger.info('Parsing Spec...')
    spec = S.parse_file('example/simplestring.tyrell')
    logger.info('Parsing succeeded')

    logger.info('Building synthesizer...')
    synthesizer = Synthesizer(
        # enumerator=SmtEnumerator(spec, depth=3, loc=1), # plus(@param1, @param0) / plus(@param0, @param1)
        enumerator=SmtEnumerator(
            spec, depth=4,
            loc=3),  # plus(plus(@param0, const(_apple_)), @param1)
        decider=ExampleConstraintDecider(
            spec=spec,
            interpreter=ToyInterpreter(),
            examples=[
                # Example(input=["a", "b"], output="ab"), # plus(@param0, @param1)
                # Example(input=["b", "a"], output="ab"), # plus(@param1, @param0)
                Example(input=["a", "b"], output="a_apple_b"),
            ],
        ))
    logger.info('Synthesizing programs...')

    prog = synthesizer.synthesize()
    if prog is not None:
        logger.info('Solution found: {}'.format(prog))
    else:
        logger.info('Solution not found!')
Exemplo n.º 2
0
def main():
    logger.info('Parsing Spec...')
    spec = S.parse_file('example/toy.tyrell')
    logger.info('Parsing succeeded')

    logger.info('Building synthesizer...')
    synthesizer = Synthesizer(
        enumerator=SmtEnumerator(spec, depth=3, loc=2),
        decider=ExampleConstraintDecider(
            spec=spec,
            interpreter=ToyInterpreter(),
            examples=[
                # we want to synthesize the program (x-y)*y (depth=3, loc=2)
                # which is also equivalent to x*y-y*y (depth=3, loc=3)
                Example(input=[4, 3], output=3),
                Example(input=[6, 3], output=9),
                Example(input=[1, 2], output=-2),
                Example(input=[1, 1], output=0),
            ]))
    logger.info('Synthesizing programs...')

    prog = synthesizer.synthesize()
    if prog is not None:
        logger.info('Solution found: {}'.format(prog))
    else:
        logger.info('Solution not found!')
Exemplo n.º 3
0
def cli(spec_file, verbosity):
    '''
    Parse the given Tyrell DSL spec file
    '''
    logger.setLevel(verbosity)
    try:
        tyrell_spec = S.parse_file(spec_file)
        print_spec(tyrell_spec)
    except (S.ParseError, S.ParseTreeProcessingError) as e:
        logger.error('Spec parsing error: {}'.format(e))
Exemplo n.º 4
0
def main():
    global number
    parser = argparse.ArgumentParser()
    parser.add_argument('-i0', '--input0', type=str)
    parser.add_argument('-o', '--output', type=str)
    parser.add_argument('-l', '--length', type=int)
    parser.add_argument('-d', '--depth', type=int)
    parser.add_argument('-t', '--tyrellpath', type=str)
    parser.add_argument('-m', '--plotmax', type=float)
    args = parser.parse_args()
    loc_val = args.length
    depth = args.depth
    # Input and Output must be in CSV format.
    input0 = args.input0
    output = args.output

    # This is required by Ruben.
    init_input_tbl('input0', input0)
    init_tbl('output', output)
    build_tab('output').max_input = args.plotmax

    logger.info('Parsing Spec...')
    spec = S.parse_file(args.tyrellpath)
    logger.info('Parsing succeeded')

    logger.info('Building synthesizer...')
    r_interpreter = RInterpreter()

    synthesizer = Synthesizer(
        #loc: # of function productions
        # enumerator=SmtEnumerator(spec, depth=2, loc=1),
        # enumerator=SmtEnumerator(spec, depth=3, loc=2),

        enumerator=SmtEnumerator(spec, depth=depth, loc=loc_val, evaluator=Evaluator(r_interpreter)),
        decider=SmtBasicDecider(
            spec=spec,
            interpreter=r_interpreter,
            examples=[
                # Example(input=[DataFrame2(benchmark1_input)], output=benchmark1_output),
                Example(input=['input0'], output='output'),
            ],
            equal_output=eq_r
        )
    )
    logger.info('Synthesizing programs...')
    synthesizer.set_table(Table)
    prog = synthesizer.synthesize()
    logger.info('Number of candidates: {}'.format(number))
    if prog is not None:
        logger.info('Selected solution: {}'.format(prog))
    else:
        logger.info('Solution not found!')
    sys.stderr.flush()
Exemplo n.º 5
0
def main():

    ##### Input-output constraint
    benchmark1_input = robjects.r('''
    dat <- read.table(text="
    round var1 var2 nam        val
    round1   22   33 foo 0.16912201
    round2   11   44 foo 0.18570826
    round1   22   33 bar 0.12410581
    round2   11   44 bar 0.03258235
    ", header=T)
    dat
   ''')

    benchmark1_output = robjects.r('''
    dat2 <- read.table(text="
    nam val_round1 val_round2 var1_round1 var1_round2 var2_round1 var2_round2
    bar  0.1241058 0.03258235          22          11          33          44
    foo  0.1691220 0.18570826          22          11          33          44
    ", header=T)
    dat2
   ''')

    logger.info('Parsing Spec...')
    spec = S.parse_file('example/morpheus.tyrell')
    logger.info('Parsing succeeded')

    logger.info('Building synthesizer...')
    synthesizer = Synthesizer(
        #loc: # of function productions
        # enumerator=SmtEnumerator(spec, depth=2, loc=1),
        # enumerator=SmtEnumerator(spec, depth=3, loc=2),
        enumerator=SmtEnumerator(spec, depth=4, loc=3),
        decider=ExampleConstraintDecider(
            spec=spec,
            interpreter=MorpheusInterpreter(),
            examples=[
                # Example(input=[DataFrame2(benchmark1_input)], output=benchmark1_output),
                Example(input=['dat'], output='dat2'),
            ],
            equal_output=eq_r
        )
    )
    logger.info('Synthesizing programs...')

    prog = synthesizer.synthesize()
    if prog is not None:
        logger.info('Solution found: {}'.format(prog))
    else:
        logger.info('Solution not found!')
Exemplo n.º 6
0
def main(seed):
	global conn
	conn = create_connection("squares.db")
	# c = conn.cursor()
	# benchmark1_input = ""
	# c.execute("select * from faculty;")
	# rows = c.fetchall()
	# for r in rows:
	# 	# print(str(r))
	# 	benchmark1_input += str(r)
	# print(benchmark1_input)
	benchmark1_output = ""
	c = conn.cursor()
	c.execute("SELECT fid, fname FROM faculty natural join class;")
	rows = c.fetchall()
	for r in rows:
		benchmark1_output += str(r)
		# print(r)
	# print(benchmark1_output)

	logger.info('Parsing Spec...')
	spec = S.parse_file('example/squares.tyrell')
	logger.info('Parsing succeeded')

	logger.info('Building synthesizer...')
	synthesizer = Synthesizer(
		#loc: # of function productions
		# enumerator=SmtEnumerator(spec, depth=2, loc=1),
		# enumerator=SmtEnumerator(spec, depth=3, loc=2),
		enumerator=SmtEnumerator(spec, depth=4, loc=3),
		# enumerator=RandomEnumerator(
		# 	spec, max_depth=4, seed=seed),
		decider=ExampleConstraintDecider(
			spec=spec,
			interpreter=SquaresInterpreter(),
			examples=[
				Example(input=None, output=benchmark1_output),
			],
			equal_output=eq_r
		)
	)
	logger.info('Synthesizing programs...')

	prog = synthesizer.synthesize()
	if prog is not None:
		logger.info('Solution found: {}'.format(prog))
	else:
		logger.info('Solution not found!')
	conn.close()
Exemplo n.º 7
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('-i0', '--input0', type=str)
    parser.add_argument('-i1', '--input1', type=str)
    parser.add_argument('-o', '--output', type=str)
    parser.add_argument('-l', '--length', type=int)
    args = parser.parse_args()
    loc_val = args.length
    # Input and Output must be in CSV format.
    input0 = args.input0
    input1 = args.input1
    output = args.output
    # This is required by Ruben.
    depth_val = loc_val + 1
    print(input0, input1, output, loc_val)
    init_tbl('input0', input0)
    #FIXME: ignore the second input table for now.
    init_tbl('output', output)

    logger.info('Parsing Spec...')
    spec = S.parse_file('example/morpheus.tyrell')
    logger.info('Parsing succeeded')

    # Reading the n-gram model.
    sketches = [line.strip() for line in open("./ngram.txt", 'r')]

    logger.info('Building synthesizer...')
    synthesizer = Synthesizer(
        #loc: # of function productions
        enumerator=BidirectEnumerator(spec,
                                      depth=depth_val,
                                      loc=loc_val,
                                      sk_queue=sketches),
        decider=ExampleConstraintPruningDecider(
            spec=spec,
            interpreter=MorpheusInterpreter(),
            examples=[
                # Example(input=[DataFrame2(benchmark1_input)], output=benchmark1_output),
                Example(input=['input0'], output='output'),
            ],
            equal_output=eq_r))
    logger.info('Synthesizing programs...')

    prog = synthesizer.synthesize()
    if prog is not None:
        logger.info('Solution found: {}'.format(prog))
    else:
        logger.info('Solution not found!')
Exemplo n.º 8
0
def main():
    logger.info('Parsing Spec...')
    spec = S.parse_file('example/deepcoder.tyrell')
    logger.info('Parsing succeeded')

    logger.info('Building synthesizer...')
    synthesizer = Synthesizer(
        enumerator=SmtEnumerator(spec, depth=5, loc=5),
        decider=ExampleConstraintDecider(
            spec=spec,
            interpreter=DeepCoderInterpreter(),
            examples=[
                Example(input=[[6, 2, 4, 7, 9], [5, 3, 6, 1, 0]], output=27),
            ],
            # equal_output=eq_deepcoder
        ))
    logger.info('Synthesizing programs...')

    prog = synthesizer.synthesize()
    if prog is not None:
        logger.info('Solution found: {}'.format(prog))
    else:
        logger.info('Solution not found!')
Exemplo n.º 9
0
    enumerator = SmtEnumerator(spec, depth=depth, loc=loc)
    decider = ExampleConstraintDecider(spec=spec,
                                       interpreter=Interpreter(),
                                       examples=make_examples(examples))

    return enumerator, decider


def exhaustive(spec, max_depth, examples):
    enumerator = ExhaustiveEnumerator(spec, max_depth)
    decider = ExampleDecider(Interpreter(), make_examples(examples))

    return enumerator, decider


spec = parse_file('example/outsystems.tyrell')
examples = [
    (["John", "Doe"], 'doejohn'),
    # (["John   ", "  Doe"], 'doejohn'),
    # (["   John   ", "  Doe   "], 'doejohn'),
    # (["Jane", "Smith"], 'smithjane'),
    # (["Jane   ", "  Smith"], 'smithjane'),
    # (["   Jane   ", "  Smith   "], 'smithjane'),
]


def smt_main(spec):
    # for loc in range(1, 6):  # bug
    synthesize(*smt(spec, depth=6, loc=4, examples=examples))

Exemplo n.º 10
0
def synthesize(inputs, output, oracle_output, prune, extra_consts):

    global full_table
    full_table = oracle_output

    logger.setLevel('INFO')
    """ synthesizer table transformation programs from input-output examples
    Args:
        inputs: a list of input tables (represented as a list of named tuples)
        output: a symbolic table (of class symbolic.SymTable)
        full_output:  the oracle output table, the task would need to generalize to it
        extra_consts: extra constants provided to the solver
    Returns:
        a list of transformation programs s.t. p(inputs) = output
    """

    #print("output table:\n", output)
    #print("input table:\n", inputs[0])
    loc_val = 2
    output_data = json.dumps(output.instantiate())
    full_data = json.dumps(oracle_output.instantiate())
    input_data = json.dumps(inputs[0], default=default)
    init_tbl_json_str('input0', input_data)
    init_tbl_json_str('output', output_data)
    # if prune == 'morpheus':
    #     init_tbl_json_str('output', full_data)
    # else:
    #     init_tbl_json_str('output', output_data)
    print(robjects.r('input0'))
    print(robjects.r('output'))

    depth_val = loc_val + 1
    logger.info('Parsing spec ...')

    # provide additional string constants to the solver
    grammar_base = "dsl/tidyverse.tyrell.base"
    grammar_file = "dsl/__tidyverse__.tyrell"
    synth_utils.update_search_grammar(extra_consts, grammar_base, grammar_file)

    spec = S.parse_file(grammar_file)
    logger.info('Parsing succeeded')

    logger.info('Building synthesizer ...')
    global iter_num
    iter_num = 0
    for loc in range(1, loc_val + 1):
        eq_fun = subset_eq
        if prune == 'none':
            eq_fun = proj_eq

        enumerator = BidirectEnumerator(spec, depth=loc + 1, loc=loc)
        decider = BidirectionalDecider(spec=spec,
                                       interpreter=MorpheusInterpreter(),
                                       examples=[
                                           Example(input=['input0'],
                                                   output='output'),
                                       ],
                                       prune=prune,
                                       equal_output=eq_fun)
        if prune == 'morpheus':
            enumerator = SmtEnumerator(spec, depth=loc + 1, loc=loc)
            decider = ExampleConstraintPruningDecider(
                spec=spec,
                interpreter=MorpheusInterpreter(),
                examples=[
                    # Example(input=[DataFrame2(benchmark1_input)], output=benchmark1_output),
                    Example(input=['input0'], output='output'),
                ],
                equal_output=eq_fun)

        synthesizer = Synthesizer(enumerator=enumerator, decider=decider)
        logger.info('Synthesizing programs ...')

        prog = synthesizer.synthesize()
        if prog is not None:
            logger.info('Solution found: {}'.format(prog))
            return [prog]
        else:
            logger.info('Solution not found!')

    return []