def test_exit_all_const_nodes(self): """Test that runtime runs correctly if all nodes are constant.""" with dl.DeltaGraph() as graph: self.const_save_exit(n=add(n1=1, n2=2)) with self.assertRaises(RuntimeError): dl.DeltaPySimulator(graph).run(100)
def test_cannot_fold_through_semi_const_multi_body(self): """If a node has both constant and non-constant bodies, then this node cannot be folded. .. note:: This behaviors might change so only the selected body (during execution) will define if the node can/cannot be folded. """ with DeltaGraph() as graph: n1 = add(4, foo_semi_const_1_t(3)) n2 = add_non_const(4, foo_semi_const_1_t(2)) # nodes producing constants are turned to constant nodes for node in graph.find_node_by_name('node'): self.assertIsInstance(node.body, PyConstBody) # this one is a non-constant one now self.assertIsInstance(n1.body, PyFuncBody) # this one is still a non-constant self.assertIsInstance(n2.body, PyFuncBody) self.assertTrue(graph.check())
def test_exit_const_node(self): """Test that a DeltaRuntimeExit in a constant node does not cause an error. """ with dl.DeltaGraph() as graph: do_nothing(n=self.const_save_exit(n=add(n1=1, n2=2))) with self.assertRaises(RuntimeError): dl.DeltaPySimulator(graph).run()
def setUp(self): """ Create the graph: return_4 -> add -> add_member -> print -> saver / return_2 / """ self.saver = dl.lib.StateSaver(int) with dl.DeltaGraph() as graph: inst = OtherClass(2) const = add(return_4(), return_2()) num = inst.add_member(const) self.saver.save_and_exit(num) self.graph = graph self.runtime = dl.DeltaPySimulator(graph)
def test_simple_folding_const_inputs(self): """Test that nodes producing constants are constant nodes.""" with DeltaGraph() as graph: n1 = add(4, 3) n2 = add_non_const(4, 2) # nodes producing constants are turned to constant nodes for node in graph.find_node_by_name('node'): self.assertIsInstance(node.body, PyConstBody) # this one is turned to a constant node as well self.assertIsInstance(n1.body, PyConstBody) # this one would have done so as well, but we disallowed it self.assertIsInstance(n2.body, PyFuncBody) self.assertTrue(graph.check())
def test_simple_folding_non_const_inputs(self): """Test that nodes with non constant inputs cannot fold to become constant. """ with DeltaGraph() as graph: n1 = add(4, foo_non_const(3)) n2 = add_non_const(4, foo_non_const(2)) # nodes producing constants are turned to constant nodes for node in graph.find_node_by_name('node'): self.assertIsInstance(node.body, PyConstBody) # this one is a non-constant one now self.assertIsInstance(n1.body, PyFuncBody) # this one is still a non-constant self.assertIsInstance(n2.body, PyFuncBody) self.assertTrue(graph.check())