From c5e2cfc441093c2999b6ae6527ec4042891e74db Mon Sep 17 00:00:00 2001
From: Yaman Umuroglu <maltanar@gmail.com>
Date: Mon, 11 May 2020 22:47:43 +0100
Subject: [PATCH] [Analysis] rename to nodes_topologically_sorted

---
 src/finn/analysis/topology.py          |  9 +++--
 tests/analysis/test_topology_checks.py | 52 +++++++++++++-------------
 2 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/src/finn/analysis/topology.py b/src/finn/analysis/topology.py
index 3973c8d26..acdb8ed7f 100644
--- a/src/finn/analysis/topology.py
+++ b/src/finn/analysis/topology.py
@@ -81,10 +81,11 @@ def node_inputs_in_expected_order(model):
     return {"node_inputs_in_expected_order": all_OK}
 
 
-def nodes_in_expected_order(model):
-    """Verifies that the graph is topologically sorted.
+def nodes_topologically_sorted(model):
+    """Verifies that graph.node is topologically sorted. This is required by the
+    ONNX specification.
 
-    Returns {"nodes_in_expected_order": Bool}."""
+    Returns {"nodes_topologically_sorted": Bool}."""
 
     # get successors of every node and check that
     # successor index > current node index
@@ -100,4 +101,4 @@ def nodes_in_expected_order(model):
                 if index_n > index_suc:
                     all_OK = False
 
-    return {"nodes_in_expected_order": all_OK}
+    return {"nodes_topologically_sorted": all_OK}
diff --git a/tests/analysis/test_topology_checks.py b/tests/analysis/test_topology_checks.py
index 7c9a131f6..7f7f800da 100644
--- a/tests/analysis/test_topology_checks.py
+++ b/tests/analysis/test_topology_checks.py
@@ -92,45 +92,45 @@ def test_node_inputs_in_expected_order():
     assert ret["node_inputs_in_expected_order"] is False
 
 
-def test_nodes_in_expected_order():
-    # test analysis pass (nodes_in_expected_order) with different models
+def test_nodes_topologically_sorted():
+    # test analysis pass (nodes_topologically_sorted) with different models
 
     # test with data/onnx/finn-hls-model/tfc_w1_a1_after_conv_to_hls.onnx
     raw_m = get_data(
         "finn", "data/onnx/finn-hls-model/tfc_w1_a1_after_conv_to_hls.onnx"
     )
     model = ModelWrapper(raw_m)
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is True
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is True
 
     # remove first node and add it at the end
     graph = model.graph
     first_node = graph.node[0]
     graph.node.remove(first_node)
     graph.node.append(first_node)
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is False
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is False
 
     # test with data/onnx/mnist-conv/model.onnx
     raw_m = get_data("finn", "data/onnx/mnist-conv/model.onnx")
     model = ModelWrapper(raw_m)
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is True
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is True
 
     # remove first node and add it at the end
     graph = model.graph
     first_node = graph.node[0]
     graph.node.remove(first_node)
     graph.node.append(first_node)
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is False
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is False
 
     # test with manually created small network
-    Neg_node = oh.make_node("Neg", inputs=["in1"], outputs=["neg1"],)
-    Round_node = oh.make_node("Round", inputs=["neg1"], outputs=["round1"],)
+    Neg_node = oh.make_node("Neg", inputs=["in1"], outputs=["neg1"])
+    Round_node = oh.make_node("Round", inputs=["neg1"], outputs=["round1"])
 
-    Ceil_node = oh.make_node("Ceil", inputs=["neg1"], outputs=["ceil1"],)
-    Add_node = oh.make_node("Add", inputs=["round1", "ceil1"], outputs=["out1"],)
+    Ceil_node = oh.make_node("Ceil", inputs=["neg1"], outputs=["ceil1"])
+    Add_node = oh.make_node("Add", inputs=["round1", "ceil1"], outputs=["out1"])
 
     in1 = oh.make_tensor_value_info("in1", TensorProto.FLOAT, [4, 4])
     out1 = oh.make_tensor_value_info("out1", TensorProto.FLOAT, [4, 4])
@@ -150,8 +150,8 @@ def test_nodes_in_expected_order():
     onnx_model = oh.make_model(graph, producer_name="simple-model")
     model = ModelWrapper(onnx_model)
 
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is True
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is True
 
     # create same graph but with "wrong" node order
     graph = oh.make_graph(
@@ -169,22 +169,22 @@ def test_nodes_in_expected_order():
     onnx_model = oh.make_model(graph, producer_name="simple-model")
     model = ModelWrapper(onnx_model)
 
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is False
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is False
 
     # test with data/onnx/finn-hls-model/finn-hls-onnx-model.onnx
     raw_m = get_data("finn", "data/onnx/finn-hls-model/finn-hls-onnx-model.onnx")
     model = ModelWrapper(raw_m)
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is True
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is True
 
     # remove first node and add it at the end
     graph = model.graph
     first_node = graph.node[0]
     graph.node.remove(first_node)
     graph.node.append(first_node)
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is False
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is False
 
     # test with cnv_w1a1
     build_dir = "/tmp/" + os.environ["FINN_INST_NAME"]
@@ -193,13 +193,13 @@ def test_nodes_in_expected_order():
         cnv, (1, 3, 32, 32), build_dir + "/end2end_cnv_w1a1_export.onnx"
     )
     model = ModelWrapper(build_dir + "/end2end_cnv_w1a1_export.onnx")
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is True
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is True
 
     # remove first node and add it at the end
     graph = model.graph
     first_node = graph.node[0]
     graph.node.remove(first_node)
     graph.node.append(first_node)
-    ret = model.analysis(ta.nodes_in_expected_order)
-    assert ret["nodes_in_expected_order"] is False
+    ret = model.analysis(ta.nodes_topologically_sorted)
+    assert ret["nodes_topologically_sorted"] is False
-- 
GitLab