From fb5101e683bf4e91c5abaac5d5f27181fc3339e6 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Wed, 25 Oct 2023 15:12:54 +0000 Subject: [PATCH] [NodeExport] Add node export class skeleton. --- aidge_core/__init__.py | 1 + aidge_core/export/__init__.py | 1 + aidge_core/export/node_export.py | 63 ++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 aidge_core/export/__init__.py create mode 100644 aidge_core/export/node_export.py diff --git a/aidge_core/__init__.py b/aidge_core/__init__.py index ad18a8ef1..c65dcc6cf 100644 --- a/aidge_core/__init__.py +++ b/aidge_core/__init__.py @@ -8,3 +8,4 @@ http://www.eclipse.org/legal/epl-2.0. SPDX-License-Identifier: EPL-2.0 """ from aidge_core.aidge_core import * # import so generated by PyBind +from aidge_core.export import ExportNode diff --git a/aidge_core/export/__init__.py b/aidge_core/export/__init__.py new file mode 100644 index 000000000..00b44121d --- /dev/null +++ b/aidge_core/export/__init__.py @@ -0,0 +1 @@ +from .node_export import * diff --git a/aidge_core/export/node_export.py b/aidge_core/export/node_export.py new file mode 100644 index 000000000..794fec814 --- /dev/null +++ b/aidge_core/export/node_export.py @@ -0,0 +1,63 @@ +import aidge_core + +from abc import ABC, abstractmethod + + +class ExportNode(ABC): + """Abstract class to interface node with export generation. + """ + + @abstractmethod + def __init__(self, aidge_node: aidge_core.Node) -> None: + """Create ExportNode and retieve attirubtes from ``aidge_node``: + + - name: aidge Node name + - attributes: dictionnary of attributes of the aidge Operator linked to the node, attributes name follow aidge naming convention + - parameters: List of parameters node, order in the list is the same as the one defined by the aidge operator + + """ + super().__init__() + self.node = aidge_node + self.operator = aidge_node.get_operator() + self.name = self.node.name() + self.attributes = {} # Attributes are auto fetched from aidge operators + if isinstance(self.operator, aidge_core.Attributes): + for attr_name in self.operator.get_attrs_name(): + self.attributes[attr_name] = self.operator.get_attr(attr_name) + + # rename is_leaf ? + self.is_last = len(self.node.get_children()) == 0 + + + self.inputs = [] + self.outputs = [] + self.inputs_dims = [] + self.outputs_dims = [] + + for idx, parent_node in enumerate(self.node.get_parents()): + self.inputs.append(parent_node) + if parent_node is not None: + self.inputs_dims.append(self.operator.input(idx).dims()) + else: + self.inputs_dims.append(None) + + # TODO + for idx, child_node in enumerate(self.node.get_children()): + self.outputs.append(child_node) + if child_node is not None: + self.outputs_dims.append(self.operator.output(idx).dims()) + else: + self.outputs_dims.append(None) + + @abstractmethod + def export(self, export_folder:str, list_configs:list): + """Define how to export the node definition. + """ + pass + + @abstractmethod + def forward(self, list_actions:list): + """Define how to generate code to perform a forward pass. + """ + pass + -- GitLab