diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index c766d06c2f190b8a20763bf75f2661cb65df2fd0..08c95261290af1772d4dc9bd75edd09014d57c79 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 afe1df7916203bf48c43feb3c1f7e55ab283557d..2c35b20ba216cf19570de27e537b0de37595c96d 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.