def test_splitting_of_one_forked_non_const(self): """One of forked outputs of a non-constant node is splitted.""" s1 = StateSaver(int) s2 = StateSaver(int) with DeltaGraph() as graph: val = return_12_non_const() val_x = val.x s1.save(val_x) s2.save_and_exit(val_x) rt = DeltaPySimulator(graph) rt.run() self.assertEqual(s2.saved, [1])
def setUp(self): r"""Build the graph ``` / saver1 / placeholder -- saver2 \ \ saver3 ``` """ with DeltaGraph() as my_graph: saver1 = StateSaver(bool) saver2 = StateSaver(bool) saver3 = StateSaver(bool) val = placeholder_node_factory() saver1.save(val) saver2.save(val) saver3.save(val) def true() -> bool: return True val.specify_by_func(true) self.graph = my_graph self.savers = [saver1, saver2, saver3]
def test_serialise_state_saver(self): """Serialise a state saver and load it in a new instance.""" saver = StateSaver(t=int, verbose=True) with DeltaGraph(): saver_node = saver.save(return_2_const()) saver_body = saver_node.body.as_serialised python_string = textwrap.dedent(f""" import dill saver_body = dill.loads({saver_body}) saver_body.eval(5) """) p = subprocess.run([r"python"], input=str.encode(python_string), stdout=subprocess.PIPE, check=False) output = p.stdout.decode() self.assertEqual(output, "saving 5\n")
def setUp(self): r"""Build the graph ``` / saver1 / return_1 -- saver2 \ \ saver3 ``` """ with DeltaGraph() as my_graph: saver1 = StateSaver(int) saver2 = StateSaver(int) saver3 = StateSaver(int) val = return_1() saver1.save(val) saver2.save(val) saver3.save(val) self.graph = my_graph self.savers = [saver1, saver2, saver3]