Esempio n. 1
0
    def _create_new_op(self, *args, **kwargs):
        """
        Handles an operation call to the current node and returns the new node
        built using the operation call.
        """
        # Create a new `Operation` object for the
        # incoming operation call
        op = Operation.create_op(self.proxied_node._new_op_name, *args,
                                 **kwargs)

        # Generate next node id
        headnode: HeadNode = self.proxied_node.get_head()
        headnode.node_counter += 1

        # Create a new `Node` object to house the operation
        newnode = Node(get_head=self.proxied_node.get_head,
                       node_id=headnode.node_counter,
                       operation=op,
                       parent=self.proxied_node)

        self.proxied_node.nchildren += 1

        # Append to the list of nodes for this computation graph
        headnode.graph_nodes.appendleft(newnode)

        # Logger debug statements
        logger.debug("Created new {} node".format(op.name))

        return get_proxy_for(op, newnode)
Esempio n. 2
0
 def _create_new_op(self, *args, **kwargs):
     """
     Handles an operation call to the current node and returns the new node
     built using the operation call.
     """
     op = Operation.create_op(self.proxied_node._new_op_name, *args,
                              **kwargs)
     newnode = _create_new_node(self.proxied_node, op)
     return get_proxy_for(op, newnode)
Esempio n. 3
0
 def create_variations(self) -> VariationsProxy:
     """
     Creates a node responsible to signal the creation of variations in the
     distributed computation graph, returning a specialized proxy to that
     node. This function is usually called from DistRDF.VariationsFor.
     """
     return VariationsProxy(
         _create_new_node(self.proxied_node,
                          Operation.create_op("VariationsFor")))
Esempio n. 4
0
    def __setstate__(self, state):
        """
        Retrieves the state dictionary of the current
        node and sets the instance variables.

        Args:
            state (dict): This is the state dictionary that needs to be
                converted to a `Node` object.

        """
        self.children = state['children']
        if state.get('operation_name'):
            self.operation = Operation.create_op(state['operation_name'],
                                                 *state['operation_args'],
                                                 **state["operation_kwargs"])
        else:
            self.operation = None
Esempio n. 5
0
    def _create_new_op(self, *args, **kwargs):
        """
        Handles an operation call to the current node and returns the new node
        built using the operation call.
        """
        # Create a new `Operation` object for the
        # incoming operation call
        op = Operation.create_op(self.proxied_node._new_op_name, *args,
                                 **kwargs)

        # Create a new `Node` object to house the operation
        newnode = Node(operation=op, get_head=self.proxied_node.get_head)

        # Logger debug statements
        logger.debug("Created new {} node".format(op.name))

        # Add the new node as a child of the current node
        self.proxied_node.children.append(newnode)

        return get_proxy_for(op, newnode)
Esempio n. 6
0
    def create_variations(self) -> VariationsProxy:
        """
        Creates a node responsible to signal the creation of variations in the
        distributed computation graph, returning a specialized proxy to that
        node. This function is usually called from DistRDF.VariationsFor.
        """

        # Generate next node id
        headnode: HeadNode = self.proxied_node.get_head()
        headnode.node_counter += 1

        newnode = VariationsNode(
            get_head=self.proxied_node.get_head,
            node_id=headnode.node_counter,
            operation=Operation.create_op("VariationsFor"),
            parent=self.proxied_node)

        self.proxied_node.nchildren += 1

        # Append to the list of nodes for this computation graph
        headnode.graph_nodes.appendleft(newnode)

        return VariationsProxy(newnode)
Esempio n. 7
0
 def test_action(self):
     """Action nodes are classified accurately."""
     op = Operation.create_op("Count")
     self.assertIsInstance(op, Operation.Action)
Esempio n. 8
0
 def test_histo1d_with_tuple(self):
     """A tuple can be used as a histogram model."""
     op = Operation.create_op("Histo1D", ("name", "title", 10, 0, 10), "x")
     self.assertIsInstance(op, Operation.Histo)
     self.assertEqual(op.name, "Histo1D")
     self.assertEqual(op.args, [("name", "title", 10, 0, 10), "x"])
Esempio n. 9
0
 def test_without_args_and_kwargs(self):
     """Check Operation constructor without arguments."""
     op = Operation.create_op("Define")
     self.assertEqual(op.args, [])
     self.assertEqual(op.kwargs, {})
Esempio n. 10
0
 def test_with_args_and_kwargs(self):
     """Check that named and unnamed arguments are properly set."""
     op = Operation.create_op("Define", 2, "p", a=1, b="b")
     self.assertEqual(op.args, [2, "p"])
     self.assertEqual(op.kwargs, {"a": 1, "b": "b"})
Esempio n. 11
0
 def test_without_kwargs(self):
     """Check that unnamed arguments are properly set."""
     op = Operation.create_op("Define", 1, "b")
     self.assertEqual(op.args, [1, "b"])
     self.assertEqual(op.kwargs, {})
Esempio n. 12
0
 def test_none(self):
     """Incorrect operations raise an Exception."""
     with self.assertRaises(ValueError):
         Operation.create_op("random")
Esempio n. 13
0
 def test_instant_action(self):
     """Instant actions are classified accurately."""
     op = Operation.create_op("Snapshot")
     self.assertIsInstance(op, Operation.InstantAction)
Esempio n. 14
0
 def test_histond_without_model(self):
     """Creating a histogram without model raises ValueError."""
     with self.assertRaises(ValueError):
         _ = Operation.create_op("HistoND", ["a", "b", "c", "d"])
Esempio n. 15
0
 def test_histond_with_thndmodel(self):
     """THnDModel"""
     op = Operation.create_op("HistoND", ROOT.RDF.THnDModel(),
                              ["a", "b", "c", "d"])
     self.assertIsInstance(op, Operation.Histo)
     self.assertEqual(op.name, "HistoND")
Esempio n. 16
0
 def test_histo3d_with_th3dmodel(self):
     """TH3DModel"""
     op = Operation.create_op("Histo3D", ROOT.RDF.TH3DModel(), "x", "y",
                              "z")
     self.assertIsInstance(op, Operation.Histo)
     self.assertEqual(op.name, "Histo3D")
Esempio n. 17
0
 def test_histo3d_without_model(self):
     """Creating a histogram without model raises ValueError."""
     with self.assertRaises(ValueError):
         _ = Operation.create_op("Histo3D", "x", "y", "z")
Esempio n. 18
0
 def test_transformation(self):
     """Transformation nodes are classified accurately."""
     op = Operation.create_op("Define")
     self.assertIsInstance(op, Operation.Transformation)