def test_splitting_of_multiple_forked_non_const(self): """Multiple forked outputs of a non-constant node are splitted.""" s = StateSaver(int) with DeltaGraph() as graph: val = return_12_non_const() s.save_and_exit( add_non_const( add_non_const(add_non_const(val.x, val.x), val.y), val.y)) DeltaPySimulator(graph).run() self.assertEqual(s.saved, [6])
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_splitting_to_one_node_non_const(self): """Splitted output of a non-constant node and sent to another node's different inputs.""" s = StateSaver(int) with DeltaGraph() as graph: val = return_1_non_const() s.save_and_exit(add_non_const(val, val)) DeltaPySimulator(graph).run() self.assertEqual(s.saved, [2])
def test_one_migen_node_with_separate_ctrl_on_output_valid(self): """One PyMigenBody with 2 optional output ports produces the correct valid values (for the different ports). The migen node should be generating a sequence of outputs (1, None), (None, 2), (3, None) etc... """ with DeltaGraph() as graph: alt = AlternatingOutputsMigen(tb_num_iter=100, name='alternatingOutput', lvl=logging.INFO).call(start=1) my_adder = add_non_const(alt.out_a, alt.out_b) # Checking that we have received a 1 and a 2 checker = InputCheckerWithExit(lambda x: (x == 3)) checker.check(my_adder) rt = DeltaPySimulator(graph) rt.run() self.assertEqual(checker.cond_met, True)
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())
def setUp(self): """Constructs the following graph: +---------------------------+ | SAVE | | +-----+ ^ | +--->Add +----+ | |to 10| +----+ | | +--------> | | +-----+ |ADD +---+ 2 --->| | +----+ """ self.saver = StateSaver(int) with DeltaGraph() as graph: add_ph = placeholder_node_factory() b = return_2() self.int_node = add_until_10.call(num=add_ph) add_node = add_non_const(b, self.int_node.x) add_ph.specify_by_node(add_node) self.saver.save_and_exit(self.int_node.y) self.graph = graph self.runtime = DeltaPySimulator(self.graph)