def generate_python_object(self, length): if self.partial: return program_generators.generate_python_source_and_partial_python_source( length, self.program_generator_config) else: return program_generators.generate_python_source( length, self.program_generator_config)
def test_encode_example(self): config = ArithmeticRepeatsConfig(base=10, length=5) python_source = program_generators.generate_python_source( config.length, config) cfg = python_programs.to_cfg(python_source) program_encoder = encoders.get_program_encoder(config) feature = control_flow_graph_feature.ControlFlowGraphFeature( include_back_edges=False, encoder=program_encoder) feature.encode_example((cfg, python_source))
def main(argv): del argv # Unused. config = arithmetic_repeats_config.ArithmeticRepeatsConfig( base=10, length=30, max_repeat_statements=10, max_repetitions=9, max_repeat_block_size=20, repeat_probability=0.2, permit_nested_repeats=True, ) python_source = program_generators.generate_python_source( config.length, config) cfg = python_programs.to_cfg(python_source) num_graphs = len(os.listdir('/tmp/control_flow_graphs/')) path = '/tmp/control_flow_graphs/cfg{:03d}.png'.format(num_graphs) control_flow_graphviz.render(cfg, include_src=python_source, path=path)
def test_evaluate_cfg_on_random_program(self): initial_value = 1 # v0 = 1 initial_values = {'v0': initial_value} config = arithmetic_repeats_config.ArithmeticRepeatsConfig( base=10, length=10, max_repeat_statements=10, max_repetitions=9, max_repeat_block_size=5, repeat_probability=0.2, permit_nested_repeats=True, ) python_source = program_generators.generate_python_source( config.length, config) cfg = python_programs.to_cfg(python_source) values = python_interpreter.evaluate_cfg(self.executor, cfg, initial_values=initial_values) self.assertIn('v0', values)