meshed.scrap.gk_with_networkx

seriously modified version of yahoo/graphkit

class meshed.scrap.gk_with_networkx.Data(**kwargs)[source]

This wraps any data that is consumed or produced by a Operation. This data should also know how to serialize itself appropriately. This class an “abstract” class that should be extended by any class working with data in the HiC framework.

class meshed.scrap.gk_with_networkx.NetworkOperation(**kwargs)[source]
set_execution_method(method)[source]

Determine how the network will be executed. :param method: str

If “parallel”, execute graph operations concurrently using a threadpool.

class meshed.scrap.gk_with_networkx.Operation(name: str = 'None', needs: list | None = None, provides: list | None = None, params: dict = <factory>)[source]

This is an abstract class representing a data transformation. To use this, please inherit from this class and customize the .compute method to your specific application.

Names may be given to this layer and its inputs and outputs. This is important when connecting layers and data in a Network object, as the names are used to construct the graph. :param str name: The name the operation (e.g. conv1, conv2, etc..) :param list needs: Names of input data objects this layer requires. :param list provides: Names of output data objects this provides. :param dict params: A dict of key/value pairs representing parameters

associated with your operation. These values will be accessible using the .params attribute of your object. NOTE: It’s important that any values stored in this argument must be pickelable.

compute(inputs)[source]

This method must be implemented to perform this layer’s feed-forward computation on a given set of inputs. :param list inputs:

A list of Data objects on which to run the layer’s feed-forward computation.

Returns list:

Should return a list of Data objects representing the results of running the feed-forward computation on inputs.

class meshed.scrap.gk_with_networkx.optional[source]

Input values in needs may be designated as optional using this modifier. If this modifier is applied to an input value, that value will be input to the operation if it is available. The function underlying the operation should have a parameter with the same name as the input value in needs, and the input value will be passed as a keyword argument if it is available.

Here is an example of an operation that uses an optional argument:

from graphkit import operation, compose
from graphkit.modifiers import optional

# Function that adds either two or three numbers.
def myadd(a, b, c=0):
    return a + b + c

# Designate c as an optional argument.
graph = compose('mygraph')(
    operator(name='myadd', needs=['a', 'b', optional('c')], provides='sum')(myadd)
)

# The graph works with and without 'c' provided as input.
assert graph({'a': 5, 'b': 2, 'c': 4})['sum'] == 11
assert graph({'a': 5, 'b': 2})['sum'] == 7