From e878ce910542dcab8c3328edfb0548dad9f1bc07 Mon Sep 17 00:00:00 2001
From: NAUD Maxence <maxence.naud@cea.fr>
Date: Sun, 20 Oct 2024 22:52:36 +0000
Subject: [PATCH] Small fixes - Remove underscore in 'MetaOperator_Op' for
 python when one was present - remove the number-of-input option from a test
 where it was not removed

---
 aidge_core/show_graphview.py                  | 86 +++++++++----------
 .../operator/pybind_MetaOperatorDefs.cpp      |  2 +-
 unit_tests/graphRegex/Test_GraphRegex.cpp     |  4 +-
 3 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/aidge_core/show_graphview.py b/aidge_core/show_graphview.py
index ddf0fc4b4..633298f10 100644
--- a/aidge_core/show_graphview.py
+++ b/aidge_core/show_graphview.py
@@ -4,24 +4,24 @@ import builtins
 import aidge_core
 import numpy as np
 from pathlib import Path
- 
+
 def _retrieve_operator_attrs(node : aidge_core.Node) -> dict[str, int, float, bool, None]:
     """
     Returns the dictionary containing the attributes of a given Node.
 
-    :param graph: A Node in the list of ordered nodes. 
+    :param graph: A Node in the list of ordered nodes.
     :type graph: aidge_core.Node
 
     :return: A dictionary with the Node's attributes.
     :rtype: dict[str, int, float, bool, None]
-    """       
+    """
 
     if node.get_operator().attr is not None:
         node_attr_dict =  node.get_operator().attr.dict()
         for key,value in node_attr_dict.items():
             if not type(value).__name__ in dir(builtins):
                 node_attr_dict[key] = value.name
-    
+
     else:
         node_attr_dict = {}
 
@@ -29,49 +29,49 @@ def _retrieve_operator_attrs(node : aidge_core.Node) -> dict[str, int, float, bo
 
 def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_embed : bool, write_trainable_params_ext : bool, path_trainable_params : Path, params_file_format : str) -> dict[str, int, float, bool, None]:
     """
-    Creates a dictionary to store the information of a given ordered GraphView. 
+    Creates a dictionary to store the information of a given ordered GraphView.
 
     :param ordered_nodes: A list with the GraphView's ordered nodes.
     :type graph: list
-    :param write_trainable_params_embed: Whether or not to write the eventual trainable parameters of the Nodes in the same file as the dict (embed). 
+    :param write_trainable_params_embed: Whether or not to write the eventual trainable parameters of the Nodes in the same file as the dict (embed).
     :type write_trainable_params_embed: bool
-    :param write_trainable_params_ext: Whether or not to write the eventual trainable parameters of the Nodes in an external file. 
+    :param write_trainable_params_ext: Whether or not to write the eventual trainable parameters of the Nodes in an external file.
     :type write_trainable_params_ext: bool
     :param path_trainable_params: Path of the external file used to store the Nodes' trainable parameters.
     :type path_trainable_params: Path
     :param params_file_format: Format of the external file used to store the Nodes' trainable parameters. Options: ``npz`` or ``json``. Default : ``json``. Requires ``write_trainable_params_ext``.
     :type params_file_format: str
-    
+
     :return: A dictionary with the GraphView description.
     :rtype: dict[str, int, float, bool, None]
-    """            
+    """
 
     graphview_dict = {'graph': []}
 
     for node in ordered_nodes:
-        
+
         if node is not None:
-            node_dict = {'name' : node.name(), 
+            node_dict = {'name' : node.name(),
                          'optype' : node.get_operator().type(),
                          'nb_inputs' : node.get_operator().nb_inputs(),
                          'nb_outputs' : node.get_operator().nb_outputs()}
-            
+
             inputs = []
             for input_idx in range(node.get_operator().nb_inputs()):
                 input_dict = {'dims' : node.get_operator().get_input(input_idx).dims(),
                               'data_type' : str(node.get_operator().get_input(input_idx).dtype()),
-                              'data_format' : str(node.get_operator().get_input(input_idx).dformat())}              
-                inputs.append(input_dict)    
-            
+                              'data_format' : str(node.get_operator().get_input(input_idx).dformat())}
+                inputs.append(input_dict)
+
             node_dict['inputs'] = inputs
 
             outputs = []
             for output_idx in range(node.get_operator().nb_outputs()):
                 output_dict = {'dims' : node.get_operator().get_output(output_idx).dims(),
                                'data_type' : str(node.get_operator().get_output(output_idx).dtype()),
-                              'data_format' : str(node.get_operator().get_output(output_idx).dformat())}              
-                outputs.append(output_dict)    
-            
+                              'data_format' : str(node.get_operator().get_output(output_idx).dformat())}
+                outputs.append(output_dict)
+
             node_dict['outputs'] = outputs
 
             parents = node.get_parents()
@@ -79,8 +79,8 @@ def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_e
                 if parents[0] is None: parents.append(parents.pop(0))
             else:
                 pass
-    
-            parents_inputs = [] 
+
+            parents_inputs = []
             for parent in parents:
                 if parent is not None:
                     for output_idx in range(parent.get_operator().nb_outputs()):
@@ -91,7 +91,7 @@ def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_e
                 elif parent is None:
                     for input_idx in list(range(node.get_operator().nb_inputs())):
                         if input_idx not in [item[1] for item in parents_inputs]:
-                                parents_inputs.append((None, input_idx))  
+                                parents_inputs.append((None, input_idx))
 
             parents_inputs.sort(key=lambda x: x[1])
             node_dict['parents'] = parents_inputs
@@ -103,15 +103,15 @@ def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_e
                         if child.get_operator().get_input(input_idx).dims() == node.get_operator().get_output(output_idx).dims():
                             children_outputs.append((child.name(), output_idx))
             node_dict['children'] = children_outputs
-        
+
             # Check if my node is a metaop
             attributes_dict = {}
-            if isinstance(node.get_operator(), aidge_core.MetaOperator_Op):
+            if isinstance(node.get_operator(), aidge_core.MetaOperatorOp):
                 attributes_dict['micro_graph'] = []
                 for micro_node in node.get_operator().get_micro_graph().get_nodes():
-                    micro_node_dict = {'name' : micro_node.name(), 
+                    micro_node_dict = {'name' : micro_node.name(),
                                         'optype' : micro_node.type()}
-                    
+
                     micro_node_attr_dict =  _retrieve_operator_attrs(micro_node)
                     micro_node_dict['attributes'] = micro_node_attr_dict
                     attributes_dict['micro_graph'].append(micro_node_dict)
@@ -124,7 +124,7 @@ def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_e
 
             if node.type() == 'Producer':
                 if write_trainable_params_ext:
-                    
+
                     params_file_format.casefold()
 
                     if params_file_format=='npz':
@@ -134,14 +134,14 @@ def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_e
                     elif params_file_format=='json':
                         tensor = np.array(node.get_operator().get_output(0))
                         tensor_dict = {
-                            node.name() : 
+                            node.name() :
                             {
                                 'dims' : tensor.shape,
                                 'data_type' : str(tensor.dtype),
                                 'tensor_data' : tensor.tolist()
-                            }   
+                            }
                         }
-                                   
+
                         with open(Path(path_trainable_params, node.name() + '.json'), 'w') as fp:
                             json.dump(tensor_dict, fp, indent=4)
 
@@ -150,10 +150,10 @@ def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_e
                     else:
                         raise Exception("File format to write trainable parameters not recognized.")
 
-                
+
                 elif write_trainable_params_embed:
                     node_dict['tensor_data'] = np.array(node.get_operator().get_output(0)).tolist()
-                
+
                 else:
                     pass
 
@@ -161,13 +161,13 @@ def _create_dict(ordered_nodes : list[aidge_core.Node], write_trainable_params_e
 
         else: # node is None
             pass
-    
+
     return graphview_dict
 
 def _write_dict_json(graphview_dict : dict[str, int, float, bool, None], json_path : str) -> None:
     """
     Writes dictionary containing GraphView description to a JSON file.
-    
+
     :param graphview_dict: A dictionary with the GraphView description.
     :type graphview_dict: dict[str, int, float, bool, None]
     :param json_path: Path to write JSON file.
@@ -178,18 +178,18 @@ def _write_dict_json(graphview_dict : dict[str, int, float, bool, None], json_pa
         json.dump(graphview_dict, fp, indent=4)
 
     return None
-    
-def gview_to_json(gview : aidge_core.GraphView, json_path : Path, write_trainable_params_embed : bool = False, write_trainable_params_ext : bool = False, params_file_format : str = 'json') -> None:   
+
+def gview_to_json(gview : aidge_core.GraphView, json_path : Path, write_trainable_params_embed : bool = False, write_trainable_params_ext : bool = False, params_file_format : str = 'json') -> None:
     """
     Generates the description for a GraphView in the JSON format.
-    
+
     :param graph: A GraphView of Aidge.
     :type graph: aidge_core.GraphView
     :param json_path: Path to write JSON file.
     :type json_path: Path
-    :param write_trainable_params_embed: Whether or not to write the eventual trainable parameters of the Nodes in the same file as the dict (embed). 
+    :param write_trainable_params_embed: Whether or not to write the eventual trainable parameters of the Nodes in the same file as the dict (embed).
     :type write_trainable_params_embed: bool, optional
-    :param write_trainable_params_ext: Whether or not to write the eventual trainable parameters of the Nodes in an external file. 
+    :param write_trainable_params_ext: Whether or not to write the eventual trainable parameters of the Nodes in an external file.
     :type write_trainable_params_ext: bool, optional
     :param params_file_format: Format of the external file used to store the Nodes' trainable parameters. Options: ``npz`` or ``json``. Default : ``json``. Requires ``write_trainable_params_ext``.
     :type params_file_format: str, optional
@@ -201,7 +201,7 @@ def gview_to_json(gview : aidge_core.GraphView, json_path : Path, write_trainabl
     elif not json_path.is_dir():
         if json_path.suffix == '.json':
             pass
-        else: 
+        else:
             raise Exception('If ``json_path`` contains a filename it must be of JSON format.')
 
     if write_trainable_params_ext:
@@ -212,14 +212,14 @@ def gview_to_json(gview : aidge_core.GraphView, json_path : Path, write_trainabl
     if isinstance(gview, aidge_core.GraphView):
         # Sort GraphView in topological order
         ordered_nodes = gview.get_ordered_nodes()
-    
-        # Create dict from GraphView 
+
+        # Create dict from GraphView
         graphview_dict = _create_dict(ordered_nodes, write_trainable_params_embed, write_trainable_params_ext, path_trainable_params, params_file_format)
-        
+
         # Write dict to JSON
         _write_dict_json(graphview_dict, json_path)
 
     else:
         raise Exception("Graph must be an instance of aidge_core.GraphView.")
-        
+
     return None
\ No newline at end of file
diff --git a/python_binding/operator/pybind_MetaOperatorDefs.cpp b/python_binding/operator/pybind_MetaOperatorDefs.cpp
index 5f6cc12fc..5f173068a 100644
--- a/python_binding/operator/pybind_MetaOperatorDefs.cpp
+++ b/python_binding/operator/pybind_MetaOperatorDefs.cpp
@@ -194,7 +194,7 @@ void init_MetaOperatorDefs(py::module &m) {
 //   declare_PaddedMaxPoolingOp<3>(m);
   declare_LSTMOp(m);
 
-  py::class_<MetaOperator_Op, std::shared_ptr<MetaOperator_Op>, OperatorTensor>(m, "MetaOperator_Op", py::multiple_inheritance())
+  py::class_<MetaOperator_Op, std::shared_ptr<MetaOperator_Op>, OperatorTensor>(m, "MetaOperatorOp", py::multiple_inheritance())
   .def(py::init<const char *, const std::shared_ptr<GraphView>&, const std::vector<InputCategory>&>(),
           py::arg("type"),
           py::arg("graph"),
diff --git a/unit_tests/graphRegex/Test_GraphRegex.cpp b/unit_tests/graphRegex/Test_GraphRegex.cpp
index 68ac509e7..79e471d44 100644
--- a/unit_tests/graphRegex/Test_GraphRegex.cpp
+++ b/unit_tests/graphRegex/Test_GraphRegex.cpp
@@ -153,9 +153,9 @@ TEST_CASE("GraphRegexUser") {
 
       // generate the original GraphView
         auto matmul0 = MatMul("matmul0");
-        auto add0 = Add(2, "add0");
+        auto add0 = Add("add0");
         auto matmul1 = MatMul("matmul1");
-        auto add1 = Add(2, "add1");
+        auto add1 = Add("add1");
 
         auto b0 = Producer({5}, "B0");
         auto w0 = Producer({5, 5}, "W0");
-- 
GitLab