From f638f460bcb7cd5de76d05c201cca6cd13a41a8a Mon Sep 17 00:00:00 2001 From: Mathis Richter Date: Thu, 3 Mar 2022 20:56:43 +0100 Subject: [PATCH 1/3] Fixing #210, where virtual ports block Process discovery in the compiler. Signed-off-by: Mathis Richter --- src/lava/magma/compiler/compiler.py | 8 ++--- .../ports/test_virtual_ports_in_process.py | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/lava/magma/compiler/compiler.py b/src/lava/magma/compiler/compiler.py index 7e3ac47ef..7152d4b8d 100644 --- a/src/lava/magma/compiler/compiler.py +++ b/src/lava/magma/compiler/compiler.py @@ -87,16 +87,16 @@ def _find_processes(self, # add processes connecting to the main process for in_port in proc.in_ports.members + proc.var_ports.members: - for con in in_port.in_connections: + for con in in_port.get_src_ports(): new_list.append(con.process) - for con in in_port.out_connections: + for con in in_port.get_dst_ports(): new_list.append(con.process) # add processes connecting from the main process for out_port in proc.out_ports.members + proc.ref_ports.members: - for con in out_port.in_connections: + for con in out_port.get_src_ports(): new_list.append(con.process) - for con in out_port.out_connections: + for con in out_port.get_dst_ports(): new_list.append(con.process) for proc in set(new_list): diff --git a/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py b/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py index deb9cef91..bbd37baa6 100644 --- a/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py +++ b/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py @@ -7,6 +7,7 @@ import numpy as np import functools as ft +from lava.magma.compiler.compiler import Compiler from lava.magma.core.decorator import requires, tag, implements from lava.magma.core.model.py.model import PyLoihiProcessModel from lava.magma.core.model.sub.model import AbstractSubProcessModel @@ -297,6 +298,38 @@ def test_varport_to_varport_read_in_a_hierarchical_process(self) -> None: f'{expected[output!=expected] =}\n' ) + def test_compiler_finds_all_processes(self) -> None: + """Tests whether in Process graphs with virtual ports, all Processes + are found, no matter from which Process the search is started.""" + + source = OutPortProcess(data=self.input_data) + sink = InPortProcess(shape=self.shape) + + virtual_port1 = MockVirtualPort(new_shape=self.new_shape, + axes=self.axes) + virtual_port2 = MockVirtualPort(new_shape=self.shape, + axes=tuple(np.argsort(self.axes))) + + source.out_port._connect_forward( + [virtual_port1], AbstractPort, assert_same_shape=False + ) + virtual_port1._connect_forward( + [virtual_port2], AbstractPort, assert_same_shape=False + ) + virtual_port2.connect(sink.in_port) + + compiler = Compiler() + # Test whether all Processes are found when starting the search from + # the source Process + found_procs = compiler._find_processes(source) + expected_procs = [sink, source] + self.assertEqual(found_procs, expected_procs) + + # Test whether all Processes are found when starting the search from + # the destination Process + found_procs = compiler._find_processes(sink) + self.assertEqual(found_procs, expected_procs) + def test_chaining_multiple_virtual_ports(self) -> None: """Tests whether two virtual ReshapePorts can be chained through the flatten() method.""" From feb56900fa6a5640085d26c225ddabd3e67979b4 Mon Sep 17 00:00:00 2001 From: Mathis Richter Date: Thu, 3 Mar 2022 21:32:12 +0100 Subject: [PATCH 2/3] Fixing possible race condition in unit test Signed-off-by: Mathis Richter --- .../magma/core/process/ports/test_virtual_ports_in_process.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py b/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py index bbd37baa6..0e9f28cda 100644 --- a/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py +++ b/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py @@ -323,12 +323,12 @@ def test_compiler_finds_all_processes(self) -> None: # the source Process found_procs = compiler._find_processes(source) expected_procs = [sink, source] - self.assertEqual(found_procs, expected_procs) + self.assertCountEqual(found_procs, expected_procs) # Test whether all Processes are found when starting the search from # the destination Process found_procs = compiler._find_processes(sink) - self.assertEqual(found_procs, expected_procs) + self.assertCountEqual(found_procs, expected_procs) def test_chaining_multiple_virtual_ports(self) -> None: """Tests whether two virtual ReshapePorts can be chained through the From 3d4fc5c9cf36c8c7ca5d47dc9a8b2074ef6594aa Mon Sep 17 00:00:00 2001 From: Mathis Richter Date: Thu, 3 Mar 2022 21:41:52 +0100 Subject: [PATCH 3/3] Fixed a docstring Signed-off-by: Mathis Richter --- .../magma/core/process/ports/test_virtual_ports_in_process.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py b/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py index 0e9f28cda..da5c36a09 100644 --- a/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py +++ b/tests/lava/magma/core/process/ports/test_virtual_ports_in_process.py @@ -331,8 +331,7 @@ def test_compiler_finds_all_processes(self) -> None: self.assertCountEqual(found_procs, expected_procs) def test_chaining_multiple_virtual_ports(self) -> None: - """Tests whether two virtual ReshapePorts can be chained through the - flatten() method.""" + """Tests whether virtual ports can be chained.""" source = OutPortProcess(data=self.input_data) sink = InPortProcess(shape=self.shape)