Esempio n. 1
0
def graph():
    k = DataflowGraph("graph")
    channel = DataflowChannel("ch", 1)
    k.add_channel(channel)
    process_a = DataflowProcess("a")
    process_a.connect_to_outgoing_channel(channel)
    process_b = DataflowProcess("b")
    process_b.connect_to_incomming_channel(channel)
    k.add_process(DataflowProcess("a"))
    k.add_process(DataflowProcess("b"))
    return k
Esempio n. 2
0
def calculate_platform_embedding(cfg):
    """Calculate the embedding for a Platform Graph

    This task expects two hydra parameters to be available, for the platform and
    for the representation. The representation has to be an embedding
    representation (MetricSpaceEmbedding or SymmetryEmbedding).
    The options are taken from the metric space embedding representation.
    The file is written to the path defined in the configuration under:
     `platform.embedding_json`

    **Hydra Parameters**:
        * **platform:** the input platform. The task expects a configuration
          dict that can be instantiated to a
          :class:`~mocasin.common.platform.Platform` object.
        * **representation:** the mapping representation to find the embedding.
        This can be either MetricSpaceEmbedding or SymmetryEmbedding.

    """
    platform = hydra.utils.instantiate(cfg["platform"])
    json_file = cfg["platform"]["embedding_json"]
    if json_file is not None and os.path.exists(json_file):
        log.info("JSON file already found. Removing and recalculating")
        os.remove(json_file)
    elif json_file is None:
        log.warning(
            "No path specified for storing the file. Embedding won't be stored."
            "\n You can specify it with: platform.embedding_json "
            "= <output-file-path>")
    if (cfg["representation"]._target_ !=
            "mocasin.representations.MetricEmbeddingRepresentation"
            and cfg["representation"]._target_ !=
            "mocasin.representations.SymmetryEmbedding"):
        raise RuntimeError(
            "The calculate platform embedding task needs to be called "
            "w/ the MetricSpaceEmbedding or SymmetryEmbedding representation."
            f" Called with {cfg['representation']._target_}")
    graph = DataflowGraph(name="EmptyGraph")
    representation = hydra.utils.instantiate(cfg["representation"], graph,
                                             platform)
    out_filename = str(cfg["out_file"])
    representation.dump_json(out_filename)
Esempio n. 3
0
    def to_dataflow_graph(self):
        """Transfers the the tgff graph into a dataflow graph
        :returns: the equivalent dataflow graph representation
        :rtype: DataflowGraph
        """
        graph = DataflowGraph(self.identifier)
        tasks = []
        channels = []

        # Create process for each node in
        for task in self.tasks:
            task = DataflowProcess(task)
            tasks.append(task)

        # Create channel for each edge in
        for key, properties in self.channels.items():
            name = key
            token_size = int(self._quantities[0][int(properties[2])])
            channel = DataflowChannel(name, token_size)

            for task in tasks:
                if task.name == properties[0]:
                    task.connect_to_outgoing_channel(channel)
                if task.name == properties[1]:
                    task.connect_to_incomming_channel(channel)

            channels.append(channel)

        # Add channels and processes to empty
        for task in tasks:
            graph.add_process(task)

        for channel in channels:
            graph.add_channel(channel)

        return graph
Esempio n. 4
0
def graph():
    k = DataflowGraph("a")
    k.add_process(DataflowProcess("a"))
    k.add_process(DataflowProcess("b"))
    return k