h1st.core.node module

class h1st.core.node.Node(containable: h1st.core.node_containable.NodeContainable = None, id: str = None)[source]

Bases: object

Base class for h1st Node

__init__(containable: h1st.core.node_containable.NodeContainable = None, id: str = None)[source]
Parameters
  • containable – instance of subclass of NodeContainable to attach to the node

  • id – the node’s id

property id
property edges

list of tuple(next_node, edge_label) which next_node is connected from this node edge_label = ‘yes’/’no’ in case of condition nodes edge_label = None in case of normal nodes

Type

returns

property graph
property transform_input
property transform_output
add(node: Optional[Union[Node, h1st.core.node_containable.NodeContainable]] = None, yes: Optional[Union[Node, h1st.core.node_containable.NodeContainable]] = None, no: Optional[Union[Node, h1st.core.node_containable.NodeContainable]] = None, id: str = None) → Union[h1st.core.node.Node, List[h1st.core.node.Node]][source]

The bridge function to add nodes to a graph. This will invoke the Graph.add() function and will then connect this node to newly added nodes.

call(command: Optional[str], inputs: Dict[str, Any]) → Dict[source]

Subclass may need to override this function to perform the execution depending the type of node. This function is invoked by the framework and user will never need to call it.

to_dot_node(visitor)[source]

Subclass will need to implement this function to construct and return the graphviz compatible node

test_output(inputs: Any = None, schema=None, command='predict')[source]

Invokes the call function the node with given input data, then verifies if output of the node conforming with the output schema of this node. Framework will look up the output schema for this node in the schemas object loaded by the graph from schemas.py using id of this node.

Parameters
  • inputs – input data to invoke the call function of the node

  • schema – provided schema to validate with output

  • command – the command param to invoke the call function of the node

class h1st.core.node.Action(containable: h1st.core.node_containable.NodeContainable = None, id: str = None)[source]

Bases: h1st.core.node.Node

@TODO: use .add(yes = (Model2(), “model2”)) instead ?

H1st non-conditional node. It is used to add a NodeContainable instance with an ID to yes/no branch of a conditional node

Add nodes for yes/no branch of a conditional node
import h1st as h1

class MyGraph(h1.Graph)
    def __init__(self):
        yes, no = self.start()
            .add(h1.Decision(Model1()))
            .add(
                yes = h1.Action(Model2(), id="model2"), # with an id
                no = Model3()                           # without an id
            )

        yes.add(Model4())
        no.add(Model5())

        self.end()
to_dot_node(visitor)[source]

Constructs and returns the graphviz compatible node

class h1st.core.node.Decision(containable: h1st.core.node_containable.NodeContainable = None, id: str = None, result_field='results', decision_field='prediction')[source]

Bases: h1st.core.node.Action

H1st conditional node

Graph with conditional node
import h1st as h1

class MyGraph(h1.Graph)
    def __init__(self):
        yes, no = self.start()
            .add(h1.Decision(Model1()))
            .add(
                yes = Model2()
                no = Model3()
            )

        yes.add(Model4())
        no.add(Model5())

        self.end()
Graph with conditional node using custom result_field and decision_field
import h1st as h1

class Model1(h1.Model):
    def predict(data):
        return {
            'predictions': [
                {gx: 10, gy: 20, label: True},
                {gx: 11, gy: 21, label: True},
                {gx: 12, gy: 22, label: False},
            ]
        }

class MyGraph(h1.Graph)
    def __init__(self):
        yes, no = self.start()
            .add(h1.Decision(Model1(), result_field='predictions', decision_field='label'))
            .add(
                yes = Model2()
                no = Model3()
            )

        yes.add(Model4())
        no.add(Model5())

        self.end()
__init__(containable: h1st.core.node_containable.NodeContainable = None, id: str = None, result_field='results', decision_field='prediction')[source]
Parameters
  • containable – instance of subclass of NodeContainable to attach to the node

  • id – the node’s id

  • result_field – the key to extract the data collection from dictionary output of a conditional node

  • decision_field – the field name to decide which item of the collection belongs to yes branch or no branch

to_dot_node(visitor)[source]

Constructs and returns the graphviz compatible node