Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need for "Ordered" dict #425

Merged
merged 6 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pacman/model/graphs/abstract_multiple_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
from spinn_utilities.default_ordered_dict import DefaultOrderedDict
from collections import defaultdict
from spinn_utilities.ordered_set import OrderedSet
from spinn_utilities.overrides import overrides
from pacman.exceptions import PacmanConfigurationException
Expand All @@ -38,8 +37,8 @@ def __init__(
identifier=identifier,
allowed_edge_types=allowed_edge_types, constraints=constraints,
label=label, traffic_weight=traffic_weight, class_name=class_name)
self._pre_vertices = OrderedDict()
self._destinations = DefaultOrderedDict(OrderedSet)
self._pre_vertices = dict()
self._destinations = defaultdict(OrderedSet)

# hard code dict of lists so that only these are acceptable.
for pre_vertex in pre_vertices:
Expand Down
4 changes: 2 additions & 2 deletions pacman/model/graphs/application/application_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import defaultdict
from .application_edge import ApplicationEdge
from .application_vertex import ApplicationVertex
from .application_edge_partition import ApplicationEdgePartition
from spinn_utilities.default_ordered_dict import DefaultOrderedDict
from spinn_utilities.ordered_set import OrderedSet
from spinn_utilities.overrides import overrides
from pacman.exceptions import (
Expand All @@ -40,7 +40,7 @@ def __init__(self, label):
"""
super().__init__(ApplicationVertex, ApplicationEdge, label)
self._outgoing_edge_partitions_by_pre_vertex = \
DefaultOrderedDict(OrderedSet)
defaultdict(OrderedSet)

def forget_machine_graph(self):
""" Forget the whole mapping from this graph to an application graph.
Expand Down
13 changes: 6 additions & 7 deletions pacman/model/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
from collections import defaultdict
from spinn_utilities.abstract_base import (
AbstractBase, abstractmethod, abstractproperty)
from spinn_utilities.default_ordered_dict import DefaultOrderedDict
from spinn_utilities.ordered_set import OrderedSet
from pacman.exceptions import (
PacmanAlreadyExistsException, PacmanInvalidParameterException)
Expand Down Expand Up @@ -72,11 +71,11 @@ def __init__(self, allowed_vertex_types, allowed_edge_types, label):
self._vertices = []
self._vertex_by_label = dict()
self._unlabelled_vertex_count = 0
self._outgoing_edge_partitions_by_name = OrderedDict()
self._outgoing_edges = DefaultOrderedDict(OrderedSet)
self._incoming_edges = DefaultOrderedDict(OrderedSet)
self._incoming_edges_by_partition_name = DefaultOrderedDict(list)
self._outgoing_edge_partition_by_edge = OrderedDict()
self._outgoing_edge_partitions_by_name = dict()
self._outgoing_edges = defaultdict(OrderedSet)
self._incoming_edges = defaultdict(OrderedSet)
self._incoming_edges_by_partition_name = defaultdict(list)
self._outgoing_edge_partition_by_edge = dict()
self._label = label

@property
Expand Down
18 changes: 9 additions & 9 deletions pacman/model/graphs/machine/machine_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import defaultdict
from .machine_vertex import MachineVertex
from .machine_edge import MachineEdge
from spinn_utilities.ordered_set import OrderedSet
from spinn_utilities.overrides import overrides
from spinn_utilities.default_ordered_dict import DefaultOrderedDict
from pacman.exceptions import (
PacmanAlreadyExistsException, PacmanInvalidParameterException)
from pacman.model.graphs import Graph
Expand Down Expand Up @@ -79,21 +79,21 @@ def __init__(self, label, application_graph=None):
else:
# Must be false as there is no App_graph
self._application_level_used = False
self._multicast_partitions = DefaultOrderedDict(
lambda: DefaultOrderedDict(set))
self._multicast_partitions = defaultdict(
lambda: defaultdict(set))
self._edge_partitions = OrderedSet()
self._fixed_route_edge_partitions_by_pre_vertex = (
DefaultOrderedDict(OrderedSet))
defaultdict(OrderedSet))
self._multicast_edge_partitions_by_pre_vertex = (
DefaultOrderedDict(OrderedSet))
defaultdict(OrderedSet))
self._sdram_edge_partitions_by_pre_vertex = (
DefaultOrderedDict(OrderedSet))
defaultdict(OrderedSet))
self._fixed_route_edge_partitions_by_post_vertex = (
DefaultOrderedDict(OrderedSet))
defaultdict(OrderedSet))
self._multicast_edge_partitions_by_post_vertex = (
DefaultOrderedDict(OrderedSet))
defaultdict(OrderedSet))
self._sdram_edge_partitions_by_post_vertex = (
DefaultOrderedDict(OrderedSet))
defaultdict(OrderedSet))

@overrides(Graph.add_edge)
def add_edge(self, edge, outgoing_edge_partition_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from collections import OrderedDict
from spinn_utilities.abstract_base import AbstractBase, abstractmethod
from pacman.exceptions import PacmanConfigurationException
from pacman.model.constraints.partitioner_constraints import (
Expand Down Expand Up @@ -85,7 +84,7 @@ def _get_map(self, edge_types):
:return: dict of vertex as key, edge types as list in value
:rtype: dict(MachineVertex, EdgeType)
"""
result = OrderedDict()
result = dict()
for vertex in self._governed_app_vertex.machine_vertices:
result[vertex] = edge_types
return result
Expand Down
5 changes: 2 additions & 3 deletions pacman/model/placements/placements.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
from pacman.exceptions import (
PacmanAlreadyPlacedError, PacmanNotPlacedError,
PacmanProcessorAlreadyOccupiedError, PacmanProcessorNotOccupiedError)
Expand Down Expand Up @@ -41,8 +40,8 @@ def __init__(self, placements=None):
:raise PacmanProcessorAlreadyOccupiedError:
If two placements are made to the same processor.
"""
self._placements = OrderedDict()
self._machine_vertices = OrderedDict()
self._placements = dict()
self._machine_vertices = dict()
if placements is not None:
self.add_placements(placements)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict


class MulticastRoutingTableByPartition(object):
""" A set of multicast routing path objects
Expand All @@ -26,7 +24,7 @@ class MulticastRoutingTableByPartition(object):
]

def __init__(self):
self._router_to_entries_map = OrderedDict()
self._router_to_entries_map = dict()

def add_path_entry(self, entry, router_x, router_y, partition):
""" Adds a multicast routing path entry
Expand All @@ -41,7 +39,7 @@ def add_path_entry(self, entry, router_x, router_y, partition):
# update router_to_entries_map
key = (router_x, router_y)
if key not in self._router_to_entries_map:
self._router_to_entries_map[key] = OrderedDict()
self._router_to_entries_map[key] = dict()

if partition not in self._router_to_entries_map[key]:
self._router_to_entries_map[key][partition] = entry
Expand Down
5 changes: 2 additions & 3 deletions pacman/model/routing_tables/multicast_routing_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import json
import gzip
from collections import OrderedDict
from pacman.exceptions import PacmanAlreadyExistsException
from .uncompressed_multicast_routing_table import \
UnCompressedMulticastRoutingTable
Expand Down Expand Up @@ -119,12 +118,12 @@ def __iter__(self):
def to_json(router_table):
json_list = []
for routing_table in router_table:
json_routing_table = OrderedDict()
json_routing_table = dict()
json_routing_table["x"] = routing_table.x
json_routing_table["y"] = routing_table.y
entries = []
for entry in routing_table.multicast_routing_entries:
json_entry = OrderedDict()
json_entry = dict()
json_entry["key"] = entry.routing_entry_key
json_entry["mask"] = entry.mask
json_entry["defaultable"] = entry.defaultable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
import csv
import gzip
import logging
Expand Down Expand Up @@ -70,7 +69,7 @@ def __init__(self, x, y, multicast_routing_entries=None):
self._y = y
self._number_of_defaulted_routing_entries = 0
self._multicast_routing_entries = list()
self._entries_by_key_mask = OrderedDict()
self._entries_by_key_mask = dict()
self._entries_by_key = dict()

if multicast_routing_entries is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
from pacman.exceptions import (PacmanConfigurationException)
from pacman.model.constraints.partitioner_constraints import (
MaxVertexAtomsConstraint, FixedVertexAtomsConstraint)
Expand Down Expand Up @@ -157,7 +156,7 @@ def order_vertices_for_dependent_splitters(self, vertices):
:return: vertices in list with new ordering
:rtype: iterable(ApplicationVertex)
"""
dependent_vertices = OrderedDict()
dependent_vertices = dict()
other_vertices = set()
for vertex in vertices:
if isinstance(vertex.splitter, AbstractDependentSplitter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
import logging
from spinn_utilities.log import FormatAdapter
from pacman.exceptions import PacmanRoutingException
Expand Down Expand Up @@ -62,7 +61,7 @@ def codify_table(table, length=32):
:param int length:
:rtype: dict(str, ~spinn_machine.MulticastRoutingEntry)
"""
code_dict = OrderedDict()
code_dict = dict()
for route in table.multicast_routing_entries:
code_dict[codify(route, length)] = route
return code_dict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import defaultdict
from spinn_utilities.progress_bar import ProgressBar
from spinn_utilities.default_ordered_dict import DefaultOrderedDict
from spinn_machine import MulticastRoutingEntry
from pacman.model.routing_tables import (
UnCompressedMulticastRoutingTable, MulticastRoutingTables)
Expand Down Expand Up @@ -89,7 +89,7 @@ def _create_routing_table(self, chip, partitions_in_table, routing_infos,
:rtype: MulticastRoutingTable
"""
table = UnCompressedMulticastRoutingTable(chip.x, chip.y)
partitions_by_app_vertex = DefaultOrderedDict(set)
partitions_by_app_vertex = defaultdict(set)
for partition in partitions_in_table:
partitions_by_app_vertex[partition.pre_vertex.app_vertex].add(
partition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
""" A collection of methods which support partitioning algorithms.
"""

from collections import OrderedDict
from spinn_utilities.ordered_set import OrderedSet
from pacman.utilities import utility_calls as utils
from pacman.exceptions import PacmanPartitionException
Expand Down Expand Up @@ -82,7 +81,7 @@ def get_same_size_vertex_groups(vertices):

# Dict of vertex to list of vertices with same size
# (repeated lists expected)
same_size_vertices = OrderedDict()
same_size_vertices = dict()

for vertex in vertices:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import functools
from collections import OrderedDict

from pacman.model.resources import ResourceContainer, ConstantSDRAM
from spinn_utilities.ordered_set import OrderedSet
Expand Down Expand Up @@ -75,7 +74,7 @@ def get_same_chip_vertex_groups(graph):
get_vertices_on_same_chip, graph=graph))
# Dict of vertex to set of vertices on same chip (repeated lists expected)
# A empty set value indicates a set that is too big.
same_chip_vertices = OrderedDict()
same_chip_vertices = dict()
for group in groups:
for vertex in group:
same_chip_vertices[vertex] = group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
import logging
from spinn_utilities.log import FormatAdapter
from spinn_utilities.ordered_set import OrderedSet
Expand Down Expand Up @@ -81,7 +80,7 @@ def get_mulitcast_edge_groups(machine_graph):
"""

# mapping between partition and shared key group it is in
partition_groups = OrderedDict()
partition_groups = dict()

# process each partition one by one in a bubble sort kinda way
for vertex in machine_graph.vertices:
Expand Down
Loading