From 1f8edd253849102efd739ee585231f55a76a2008 Mon Sep 17 00:00:00 2001 From: Bryan Ngo Date: Mon, 1 Apr 2024 22:22:15 -0700 Subject: [PATCH] fix renaming output, overriding child inputs --- hammer/flowgraph/flowgraph.py | 39 +++++++++++------------------ tests/test_flowgraph.py | 46 ----------------------------------- 2 files changed, 14 insertions(+), 71 deletions(-) diff --git a/hammer/flowgraph/flowgraph.py b/hammer/flowgraph/flowgraph.py index 7d679d63e..30b087c7d 100644 --- a/hammer/flowgraph/flowgraph.py +++ b/hammer/flowgraph/flowgraph.py @@ -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" @@ -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": "", @@ -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)) @@ -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: @@ -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. diff --git a/tests/test_flowgraph.py b/tests/test_flowgraph.py index a39f0361f..0bbff710a 100644 --- a/tests/test_flowgraph.py +++ b/tests/test_flowgraph.py @@ -1,11 +1,9 @@ -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, @@ -13,7 +11,6 @@ HammerToolHookAction ) -from hammer import flowgraph from hammer.flowgraph import convert_to_acyclic, Graph, Node, Status from hammer.logging import HammerVLSILogging @@ -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]: