From 861edd50f3e2ce1604df2017b6e634d1fe650f37 Mon Sep 17 00:00:00 2001
From: angloth <angus.lothian@hotmail.com>
Date: Thu, 27 Feb 2020 16:53:17 +0100
Subject: [PATCH] Add abstract method get_op_name to Operation and implement it
 for the existing core operations

---
 b_asic/core_operations.py | 19 ++++++++++++++-----
 b_asic/operation.py       |  8 +++++++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py
index c766d06c..08c95261 100644
--- a/b_asic/core_operations.py
+++ b/b_asic/core_operations.py
@@ -6,6 +6,7 @@ TODO: More info.
 from b_asic.port import InputPort, OutputPort
 from b_asic.operation import OperationId, Operation
 from b_asic.basic_operation import BasicOperation
+from b_asic.graph_id import GraphIDType
 from numbers import Number
 
 
@@ -15,7 +16,7 @@ class Input(Operation):
 	TODO: More info.
 	"""
 
-	# TODO: Implement.
+	# TODO: Implement all functions.
 	pass
 
 
@@ -36,6 +37,8 @@ class Constant(BasicOperation):
 	def evaluate(self, inputs: list) -> list:
 		return [self.param("value")]
 
+	def get_op_name(self) -> GraphIDType:
+		return "const"
 
 class Addition(BasicOperation):
 	"""
@@ -48,12 +51,15 @@ class Addition(BasicOperation):
 		Construct an Addition.
 		"""
 		super().__init__(identifier)
-		self._input_ports = [InputPort(), InputPort()] # TODO: Generate appropriate ID for ports.
-		self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
+		self._input_ports = [InputPort(1), InputPort(1)] # TODO: Generate appropriate ID for ports.
+		self._output_ports = [OutputPort(1)] # TODO: Generate appropriate ID for ports.
 
 	def evaluate(self, inputs: list) -> list:
 		return [inputs[0] + inputs[1]]
 
+	def get_op_name(self) -> GraphIDType:
+		return "add"
+ 
 
 class ConstantMultiplication(BasicOperation):
 	"""
@@ -66,11 +72,14 @@ class ConstantMultiplication(BasicOperation):
 		Construct a ConstantMultiplication.
 		"""
 		super().__init__(identifier)
-		self._input_ports = [InputPort()] # TODO: Generate appropriate ID for ports.
-		self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
+		self._input_ports = [InputPort(1)] # TODO: Generate appropriate ID for ports.
+		self._output_ports = [OutputPort(1)] # TODO: Generate appropriate ID for ports.
 		self._parameters["coefficient"] = coefficient
 
 	def evaluate(self, inputs: list) -> list:
 		return [inputs[0] * self.param("coefficient")]
 
+	def get_op_name(self) -> GraphIDType:
+		return "const_mul"
+
 # TODO: More operations.
diff --git a/b_asic/operation.py b/b_asic/operation.py
index afe1df79..2c35b20b 100644
--- a/b_asic/operation.py
+++ b/b_asic/operation.py
@@ -10,6 +10,7 @@ from typing import NewType, List, Dict, Optional, Any, TYPE_CHECKING
 if TYPE_CHECKING:
 	from b_asic.port import InputPort, OutputPort
 	from b_asic.simulation import SimulationState
+	from b_asic.graph_id import GraphIDType
 
 class Operation(ABC):
 	"""
@@ -87,7 +88,7 @@ class Operation(ABC):
 		"""
 		Simulate the circuit until its iteration count matches that of the simulation state,
 		then return the resulting output vector.
-		"""
+		"""		
 		pass
 
 	@abstractmethod
@@ -98,5 +99,10 @@ class Operation(ABC):
 		"""
 		pass
 
+	@abstractmethod
+	def get_op_name(self) -> "GraphIDType":
+		"""Returns a string representing the operation name of the operation."""
+		pass
+
 	# TODO: More stuff.
 
-- 
GitLab