コード例 #1
0
def init(python_object, info, config):
    """python_object -> state, reward."""
    base = info.program_generator_config.base
    tokens_per_statement = info.program_encoder.tokens_per_statement
    target_output_length = info.program_generator_config.num_digits
    mod = info.program_generator_config.mod
    output_mod = info.program_generator_config.output_mod

    executor = python_interpreter.ExecExecutor()
    if isinstance(python_object, tuple):
        python_source, partial_python_source = python_object
        cfg = python_programs.to_cfg(partial_python_source)
    else:
        python_source = python_object
        cfg = python_programs.to_cfg(python_source)

    # Run until branch decision, collecting simple statements.
    # TODO(dbieber): This should occur in exactly one location.
    # (also in control_flow_programs_features.py)
    initial_values = {'v0': 1}
    values, instructions, branches = (
        python_interpreter.evaluate_until_branch_decision(
            executor,
            cfg.start_block,
            mod=base**target_output_length,
            values=initial_values))

    state = dict(
        initial_values=initial_values,
        values=values,
        instructions=instructions,
        branches=branches,
        base=base,
        tokens_per_statement=tokens_per_statement,
        target_output_length=target_output_length,
        mod=mod,
        output_mod=output_mod,
        executor=executor,
        config=config,
        step=0,
    )
    reward = 0.0
    return state, reward
コード例 #2
0
 def setUp(self):
     super(PythonInterpreterTest, self).setUp()
     self.executor = python_interpreter.ExecExecutor()
コード例 #3
0
 def setUp(self):
   super(ControlFlowProgramsFeaturesTest, self).setUp()
   self.executor = python_interpreter.ExecExecutor()
コード例 #4
0
 def __init__(self, program_generator_config, partial, program_encoder):
   self.program_generator_config = program_generator_config
   self.partial = partial
   self.executor = python_interpreter.ExecExecutor()
   self.program_encoder = program_encoder