From 79281f4271bb58aceb42f710da6df7f2df1564a1 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 22 Oct 2024 11:44:20 +0100 Subject: [PATCH 1/5] assert not None --- pacman/model/tags/tags.py | 16 +++++++++------- .../basic_tag_allocator.py | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pacman/model/tags/tags.py b/pacman/model/tags/tags.py index 83c11537d..8f2fa321e 100644 --- a/pacman/model/tags/tags.py +++ b/pacman/model/tags/tags.py @@ -74,8 +74,10 @@ def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex): raise PacmanInvalidParameterException( "ip_tag", str(ip_tag), "Only add IP tags with this method.") existing_tag = None - if (ip_tag.board_address, ip_tag.tag) in self._ip_tags: - existing_tag = self._ip_tags[ip_tag.board_address, ip_tag.tag] + board_address = ip_tag.board_address + assert board_address is not None + if (board_address, ip_tag.tag) in self._ip_tags: + existing_tag = self._ip_tags[board_address, ip_tag.tag] if (existing_tag.ip_address != ip_tag.ip_address or not utility_calls.is_equal_or_none( existing_tag.port, ip_tag.port) or @@ -92,7 +94,7 @@ def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex): " the given board") if existing_tag is None: - self._ip_tags[(ip_tag.board_address, ip_tag.tag)] = ip_tag + self._ip_tags[(board_address, ip_tag.tag)] = ip_tag self._ip_tags_by_vertex[vertex].append(ip_tag) else: self._ip_tags_by_vertex[vertex].append(existing_tag) @@ -133,13 +135,13 @@ def add_reverse_ip_tag( "reverse_ip_tag", reverse_ip_tag, "The port has already been assigned on the given board") + board_address = reverse_ip_tag.board_address + assert board_address is not None self._reverse_ip_tags[ - (reverse_ip_tag.board_address, - reverse_ip_tag.tag)] = reverse_ip_tag + (board_address, reverse_ip_tag.tag)] = reverse_ip_tag self._reverse_ip_tags_by_vertex[vertex].append(reverse_ip_tag) if reverse_ip_tag.port is not None: - self._ports_assigned.add( - (reverse_ip_tag.board_address, reverse_ip_tag.port)) + self._ports_assigned.add((board_address, reverse_ip_tag.port)) @property def ip_tags_vertices(self) -> Iterable[Tuple[IPTag, MachineVertex]]: diff --git a/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py b/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py index 5120515ff..0106b0108 100644 --- a/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py +++ b/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py @@ -125,9 +125,11 @@ def __find_free_tag( def __create_tag( eth_chip: Chip, placement: Placement, iptag: IPtagResource, tag: int) -> IPTag: + tag_ip = iptag.ip_address + assert tag_ip is not None return IPTag( eth_chip.ip_address, placement.x, placement.y, - tag, iptag.ip_address, iptag.port, + tag, tag_ip, iptag.port, iptag.strip_sdp, iptag.traffic_identifier) From b0c08ccb61b2323efdaf00acff1cf4e8bc23c31d Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 11 Nov 2024 16:08:40 +0000 Subject: [PATCH 2/5] tag board_address should never be None --- pacman/model/tags/tags.py | 2 -- .../tag_allocator_algorithms/basic_tag_allocator.py | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pacman/model/tags/tags.py b/pacman/model/tags/tags.py index 8f2fa321e..10d48b256 100644 --- a/pacman/model/tags/tags.py +++ b/pacman/model/tags/tags.py @@ -75,7 +75,6 @@ def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex): "ip_tag", str(ip_tag), "Only add IP tags with this method.") existing_tag = None board_address = ip_tag.board_address - assert board_address is not None if (board_address, ip_tag.tag) in self._ip_tags: existing_tag = self._ip_tags[board_address, ip_tag.tag] if (existing_tag.ip_address != ip_tag.ip_address or @@ -136,7 +135,6 @@ def add_reverse_ip_tag( "The port has already been assigned on the given board") board_address = reverse_ip_tag.board_address - assert board_address is not None self._reverse_ip_tags[ (board_address, reverse_ip_tag.tag)] = reverse_ip_tag self._reverse_ip_tags_by_vertex[vertex].append(reverse_ip_tag) diff --git a/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py b/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py index 0106b0108..b4fa35a18 100644 --- a/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py +++ b/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py @@ -125,10 +125,12 @@ def __find_free_tag( def __create_tag( eth_chip: Chip, placement: Placement, iptag: IPtagResource, tag: int) -> IPTag: + ethernet_ip = eth_chip.ip_address + assert ethernet_ip is not None tag_ip = iptag.ip_address assert tag_ip is not None return IPTag( - eth_chip.ip_address, placement.x, placement.y, + ethernet_ip, placement.x, placement.y, tag, tag_ip, iptag.port, iptag.strip_sdp, iptag.traffic_identifier) @@ -137,8 +139,10 @@ def __create_reverse_tag( eth_chip: Chip, placement: Placement, reverse_iptag: ReverseIPtagResource, tag: int, port: int) -> ReverseIPTag: + ethernet_ip_address = eth_chip.ip_address + assert ethernet_ip_address is not None return ReverseIPTag( - eth_chip.ip_address, tag, port, placement.x, placement.y, placement.p, + ethernet_ip_address, tag, port, placement.x, placement.y, placement.p, reverse_iptag.sdp_port) From 321651a7d5b191800174f6e16cde0bd045fc19b7 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 11 Nov 2024 16:20:44 +0000 Subject: [PATCH 3/5] revert changes not needed --- pacman/model/tags/tags.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pacman/model/tags/tags.py b/pacman/model/tags/tags.py index 10d48b256..9fbab7e34 100644 --- a/pacman/model/tags/tags.py +++ b/pacman/model/tags/tags.py @@ -74,9 +74,8 @@ def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex): raise PacmanInvalidParameterException( "ip_tag", str(ip_tag), "Only add IP tags with this method.") existing_tag = None - board_address = ip_tag.board_address - if (board_address, ip_tag.tag) in self._ip_tags: - existing_tag = self._ip_tags[board_address, ip_tag.tag] + if (ip_tag.board_address, ip_tag.tag) in self._ip_tags: + existing_tag = self._ip_tags[ip_tag.board_address, ip_tag.tag] if (existing_tag.ip_address != ip_tag.ip_address or not utility_calls.is_equal_or_none( existing_tag.port, ip_tag.port) or From c70d561b447f943a56810a9fc7b706f1b8f6e3ba Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 11 Nov 2024 16:22:33 +0000 Subject: [PATCH 4/5] revert more changes not needed --- pacman/model/tags/tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pacman/model/tags/tags.py b/pacman/model/tags/tags.py index 9fbab7e34..577fdb3f8 100644 --- a/pacman/model/tags/tags.py +++ b/pacman/model/tags/tags.py @@ -92,7 +92,7 @@ def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex): " the given board") if existing_tag is None: - self._ip_tags[(board_address, ip_tag.tag)] = ip_tag + self._ip_tags[(ip_tag.board_address, ip_tag.tag)] = ip_tag self._ip_tags_by_vertex[vertex].append(ip_tag) else: self._ip_tags_by_vertex[vertex].append(existing_tag) From f97d635a54aef45b6319fc5c185e85e7d8095d9e Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 13 Nov 2024 08:02:10 +0000 Subject: [PATCH 5/5] tag board_address and port are never None --- pacman/model/resources/iptag_resource.py | 6 +++--- .../tag_allocator_algorithms/basic_tag_allocator.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pacman/model/resources/iptag_resource.py b/pacman/model/resources/iptag_resource.py index 72a5d2ead..4e6ea3206 100644 --- a/pacman/model/resources/iptag_resource.py +++ b/pacman/model/resources/iptag_resource.py @@ -36,7 +36,7 @@ class IPtagResource(object): "_traffic_identifier") def __init__( - self, ip_address: Optional[str], port: Optional[int], + self, ip_address: str, port: int, strip_sdp: bool, tag: Optional[int] = None, traffic_identifier: str = "DEFAULT"): """ @@ -60,7 +60,7 @@ def __init__( self._traffic_identifier = traffic_identifier @property - def ip_address(self) -> Optional[str]: + def ip_address(self) -> str: """ The IP address to assign to the tag. @@ -69,7 +69,7 @@ def ip_address(self) -> Optional[str]: return self._ip_address @property - def port(self) -> Optional[int]: + def port(self) -> int: """ The port of the tag. diff --git a/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py b/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py index b4fa35a18..39a62065a 100644 --- a/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py +++ b/pacman/operations/tag_allocator_algorithms/basic_tag_allocator.py @@ -127,11 +127,9 @@ def __create_tag( tag: int) -> IPTag: ethernet_ip = eth_chip.ip_address assert ethernet_ip is not None - tag_ip = iptag.ip_address - assert tag_ip is not None return IPTag( ethernet_ip, placement.x, placement.y, - tag, tag_ip, iptag.port, + tag, iptag.ip_address, iptag.port, iptag.strip_sdp, iptag.traffic_identifier)