diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index ddeb8db7601b1c971e5cf9d51841b8f781e4df45..2044a2aa145083b279064ad16dd59915dd8bdfd5 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -565,7 +565,7 @@ class SFG(AbstractOperation): @property def operations(self) -> List[Operation]: """Get all operations of this graph in depth-first order.""" - return self._operations_dfs_order + return list(self._operations_dfs_order) def find_by_type_name( self, type_name: TypeName @@ -1137,7 +1137,8 @@ class SFG(AbstractOperation): self._components_dfs_order.extend( [new_signal, source.operation] ) - self._operations_dfs_order.append(source.operation) + if not source.operation in self._operations_dfs_order: + self._operations_dfs_order.append(source.operation) # Check if the signal has not been added before. elif ( diff --git a/test/test_operation.py b/test/test_operation.py index ae7c2949395415c9daa6111a14018f6b9336f6ad..b73c678069f8b6e1633331af4a9edd8f11e57b19 100644 --- a/test/test_operation.py +++ b/test/test_operation.py @@ -156,7 +156,7 @@ class TestToSfg: assert but1.evaluate(1, 1)[0] == but1_sfg.evaluate(1, 1)[0] assert but1.evaluate(1, 1)[1] == but1_sfg.evaluate(1, 1)[1] - assert len(but1_sfg.operations) == 8 + assert len(but1_sfg.operations) == 6 def test_add_to_sfg(self): add1 = Addition() diff --git a/test/test_sfg.py b/test/test_sfg.py index e31df451db188da677e1a5180ed18951982f55ed..4dcb1d97c6c8a2ec82d6675e36621e6c49ca3fc4 100644 --- a/test/test_sfg.py +++ b/test/test_sfg.py @@ -24,6 +24,7 @@ from b_asic.core_operations import ( SymmetricTwoportAdaptor, ) from b_asic.save_load_structure import python_to_sfg, sfg_to_python +from b_asic.special_operations import Delay class TestInit: @@ -1563,6 +1564,27 @@ class TestSFGErrors: sfg.inputs_required_for_output(1) +class TestInputDuplicationBug: + def test_input_is_not_duplicated_in_operation_list(self): + # Inputs: + in1 = Input(name="in1") + out1 = Output(name="out1") + + # Operations: + t1 = Delay(initial_value=0, name="") + t1.inputs[0].connect(in1) + add1 = t1 + in1 + + out1.inputs[0].connect(add1) + + twotapfir = SFG(inputs=[in1], outputs=[out1], name='twotapfir') + + assert ( + len([op for op in twotapfir.operations if isinstance(op, Input)]) + == 1 + ) + + class TestCriticalPath: def test_single_accumulator(self, sfg_simple_accumulator: SFG): sfg_simple_accumulator.set_latency_of_type(Addition.type_name(), 5)