diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index 17e762e770c6a076b74fb3f3c645aba863d4d5d2..e731a480cd9410cf8dfc2d9f4525f71ebb44511c 100644 --- a/b_asic/core_operations.py +++ b/b_asic/core_operations.py @@ -73,7 +73,6 @@ class Constant(AbstractOperation): def __str__(self) -> str: return f"{self.value}" - class Addition(AbstractOperation): """ Binary addition operation. @@ -1263,3 +1262,45 @@ class Shift(AbstractOperation): if not isinstance(value, int): raise TypeError("value must be an int") self.set_param("value", value) + +class Sink(AbstractOperation): + r""" + Sink operation. + + Used for ignoring the output from another operation to avoid dangling output nodes. + + Parameters + ========== + + name : Name, optional + Operation name. + """ + + _execution_time = 0 + is_linear = True + + def __init__(self, name: Name = ""): + """Construct a Sink operation.""" + super().__init__( + input_count=1, + output_count=0, + name=name, + latency_offsets={"in0": 0}, + ) + + @classmethod + def type_name(cls) -> TypeName: + return TypeName("sink") + + def evaluate(self): + raise NotImplementedError + + @property + def latency(self) -> int: + return self.latency_offsets["in0"] + + def __repr__(self) -> str: + return "Sink()" + + def __str__(self) -> str: + return "sink" diff --git a/test/test_core_operations.py b/test/test_core_operations.py index 40f15f2fa04b5750a5b18899ffc7d76cb17a8ae1..002e38c96889d38021b9e9ef19ff05f5a60a88a5 100644 --- a/test/test_core_operations.py +++ b/test/test_core_operations.py @@ -20,6 +20,8 @@ from b_asic import ( SquareRoot, Subtraction, SymmetricTwoportAdaptor, + Sink, + SFG, ) @@ -404,3 +406,16 @@ class TestDepends: bfly1 = Butterfly() assert set(bfly1.inputs_required_for_output(0)) == {0, 1} assert set(bfly1.inputs_required_for_output(1)) == {0, 1} + +class TestSink: + def test_create_sfg_with_sink(self): + bfly = Butterfly() + sfg = bfly.to_sfg() + s = Sink() + sfg1 = sfg.replace_operation(s, "out0") + sfg2 = SFG(sfg1.input_operations, sfg1.output_operations[1:]) + + assert sfg2.output_count == 1 + assert sfg2.input_count == 2 + + assert sfg.evaluate_output(1, [0,1]) == sfg2.evaluate_output(0, [0,1])