Skip to content

Commit

Permalink
fix renaming output, overriding child inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
bdngo committed Apr 2, 2024
1 parent 8cd6220 commit 1f8edd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 71 deletions.
39 changes: 14 additions & 25 deletions hammer/flowgraph/flowgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@

import json
import os
import uuid
from dataclasses import dataclass, field, asdict
from enum import Enum
from typing import Any, Union

import networkx as nx
from networkx.readwrite import json_graph

from hammer.logging import HammerVLSILogging
from hammer.vlsi.cli_driver import CLIDriver


class Status(Enum):
"""Represents the status of a node in the flowgraph.
"""
"""Represents the status of a node in the flowgraph."""
NOT_RUN = "NOT_RUN"
RUNNING = "RUNNING"
INCOMPLETE = "INCOMPLETE"
Expand All @@ -39,18 +36,17 @@ class Node:
Returns:
Node: Complete description of an action.
"""
action: str
tool: str
pull_dir: str
push_dir: str
required_inputs: list[str]
required_outputs: list[str]
status: Status = Status.NOT_RUN
# __uuid: uuid.UUID = field(default_factory=uuid.uuid4)
driver: CLIDriver = field(default_factory=CLIDriver)
optional_inputs: list[str] = field(default_factory=list)
optional_outputs: list[str] = field(default_factory=list)
step_controls: dict[str, str] = field(default_factory=lambda: {
action: str
tool: str
pull_dir: str
push_dir: str
required_inputs: list[str]
required_outputs: list[str]
status: Status = Status.NOT_RUN
driver: CLIDriver = field(default_factory=CLIDriver)
optional_inputs: list[str] = field(default_factory=list)
optional_outputs: list[str] = field(default_factory=list)
step_controls: dict[str, str] = field(default_factory=lambda: {
"start_before_step": "",
"start_after_step": "",
"stop_before_step": "",
Expand Down Expand Up @@ -204,7 +200,7 @@ def insert_auxiliary_actions(edge_list: dict[Node, list[Node]]) -> dict[Node, li
parent.push_dir,
child.pull_dir,
parent.required_outputs,
[f"{aux_action}-out.json"],
child.required_inputs,
)
changes.append((parent_idx, child_idx, aux_node))

Expand All @@ -213,7 +209,7 @@ def insert_auxiliary_actions(edge_list: dict[Node, list[Node]]) -> dict[Node, li
parent, children = list(edge_list_copy.items())[parent_idx]

child = children[child_idx]
child.required_inputs = aux_node.required_outputs
child.required_inputs.extend(aux_node.required_outputs)

children[child_idx] = aux_node
if aux_node not in edge_list_copy:
Expand Down Expand Up @@ -299,13 +295,6 @@ def __run_single(node: Node) -> int:
ctxt.fatal(f"Step {node.action} failed")
return code

def to_json(self) -> dict:
"""Encodes a graph as a JSON string.
Returns:
str: JSON dump of a flowgraph.
"""
return json_graph.node_link_data(self.networkx)

def to_mermaid(self) -> str:
"""Converts the flowgraph into Mermaid format for visualization.
Expand Down
46 changes: 0 additions & 46 deletions tests/test_flowgraph.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import json
import os
import tempfile
import unittest
from textwrap import dedent

import networkx as nx
import pytest

from hammer.vlsi.cli_driver import (
CLIDriver,
HammerTool,
HammerToolHookAction
)

from hammer import flowgraph
from hammer.flowgraph import convert_to_acyclic, Graph, Node, Status
from hammer.logging import HammerVLSILogging

Expand Down Expand Up @@ -469,49 +466,6 @@ def test_flowgraph_hooks(self) -> None:
else:
self.assertTrue(os.path.exists(file))

@pytest.mark.skip
def test_encode_decode(self) -> None:
"""
Test that a flowgraph can be encoded and decoded.
"""
HammerVLSILogging.clear_callbacks()
HammerVLSILogging.add_callback(HammerVLSILogging.callback_buffering)

with tempfile.TemporaryDirectory() as td:
os.mkdir(os.path.join(td, "syn_dir"))
os.mkdir(os.path.join(td, "par_dir"))

with open(os.path.join(td, "syn_dir", "syn-in.yml"), 'w', encoding="utf-8") as tf1:
tf1.write(MOCK_CFG)

syn = Node(
"syn", "nop",
os.path.join(td, "syn_dir"), os.path.join(td, "s2p_dir"),
["syn-in.yml"],
["syn-out.json"],
)
s2p = Node(
"syn-to-par", "nop",
os.path.join(td, "s2p_dir"), os.path.join(td, "par_dir"),
["syn-out.json"],
["s2p-out.json"],
)
par = Node(
"par", "nop",
os.path.join(td, "par_dir"), os.path.join(td, "out_dir"),
["s2p-out.json"],
["par-out.json"],
)
g = Graph({
syn: [s2p],
s2p: [par],
par: []
})

out = json.dumps(g.to_json(), cls=flowgraph.NodeEncoder)
g_dec = json.loads(out, object_hook=flowgraph.as_node)
# print(g.to_json())
# print(json_graph.node_link_graph(g_dec).nodes)

class NodeDummyDriver(CLIDriver):
def get_extra_synthesis_hooks(self) -> list[HammerToolHookAction]:
Expand Down

0 comments on commit 1f8edd2

Please sign in to comment.