Example #1
0
 def _get_all_possible_recordable_variables(self):
     variables = OrderedSet()
     if isinstance(self._population._vertex, AbstractSpikeRecordable):
         variables.add(SPIKES)
     if isinstance(self._population._vertex, AbstractNeuronRecordable):
         variables.update(
             self._population._vertex.get_recordable_variables())
     return variables
Example #2
0
def test_update():
    o = OrderedSet()
    o.add(1)
    o.add(2)
    o.add(3)
    o.update([3, 4, 5])
    for item in (5, 4, 3, 2, 1):
        assert o.pop() == item
    with pytest.raises(KeyError):
        o.pop()
Example #3
0
    def get_all_possible_recordable_variables(self):
        """ All variables that could be recorded.

        :rtype: set(str)
        """
        variables = OrderedSet()
        if isinstance(self.__vertex, AbstractSpikeRecordable):
            variables.add(SPIKES)
        if isinstance(self.__vertex, AbstractNeuronRecordable):
            variables.update(self.__vertex.get_recordable_variables())
        return variables
    def _find_one_to_one_vertices(vertex, graph):
        """ Find vertices which have one to one connections with the given\
            vertex, and where their constraints don't force them onto\
            different chips.

        :param MachineGraph graph:
            the graph to look for other one to one vertices
        :param MachineVertex vertex:
            the vertex to use as a basis for one to one connections
        :return: set of one to one vertices
        :rtype: set(MachineVertex)
        """
        # Virtual vertices can't be forced on other chips
        if isinstance(vertex, AbstractVirtual):
            return []
        found_vertices = OrderedSet()
        vertices_seen = {vertex}

        # look for one to ones leaving this vertex
        outgoing = graph.get_edges_starting_at_vertex(vertex)
        vertices_to_try = deque(
            edge.post_vertex for edge in outgoing
            if edge.post_vertex not in vertices_seen)
        while vertices_to_try:
            next_vertex = vertices_to_try.pop()
            if next_vertex not in vertices_seen and \
                    not isinstance(next_vertex, AbstractVirtual):
                vertices_seen.add(next_vertex)
                if is_single(graph.get_edges_ending_at_vertex(next_vertex)):
                    found_vertices.add(next_vertex)
                    outgoing = graph.get_edges_starting_at_vertex(next_vertex)
                    vertices_to_try.extend(
                        edge.post_vertex for edge in outgoing
                        if edge.post_vertex not in vertices_seen)

        # look for one to ones entering this vertex
        incoming = graph.get_edges_ending_at_vertex(vertex)
        vertices_to_try = deque(
            edge.pre_vertex for edge in incoming
            if edge.pre_vertex not in vertices_seen)
        while vertices_to_try:
            next_vertex = vertices_to_try.pop()
            if next_vertex not in vertices_seen:
                vertices_seen.add(next_vertex)
                if is_single(graph.get_edges_starting_at_vertex(next_vertex)):
                    found_vertices.add(next_vertex)
                    incoming = graph.get_edges_ending_at_vertex(next_vertex)
                    vertices_to_try.extend(
                        edge.pre_vertex for edge in incoming
                        if edge.pre_vertex not in vertices_seen)

        found_vertices.update(get_vertices_on_same_chip(vertex, graph))
        return found_vertices
Example #5
0
    def _sort_vertices_for_one_to_one_connection(self, machine_graph,
                                                 same_chip_vertex_groups):
        """

        :param machine_graph: the graph to place
        :return: list of sorted vertices
        """
        sorted_vertices = list()
        found_list = set()

        # order vertices based on constraint priority
        vertices = sort_vertices_by_known_constraints(machine_graph.vertices)

        for vertex in vertices:
            if vertex not in found_list:

                # vertices that are one to one connected with vertex and are
                # not forced off chip
                connected_vertices = self._find_one_to_one_vertices(
                    vertex, machine_graph)

                # create list for each vertex thats connected haven't already
                #  been seen before
                new_list = OrderedSet()
                for found_vertex in connected_vertices:
                    if found_vertex not in found_list:
                        new_list.add(found_vertex)

                # looks for vertices that have same chip constraints but not
                # found by the one to one connection search.
                same_chip_vertices = list()
                for found_vertex in new_list:
                    for same_chip_constrained_vertex in \
                            same_chip_vertex_groups[found_vertex]:
                        if same_chip_constrained_vertex not in new_list:
                            same_chip_vertices.append(
                                same_chip_constrained_vertex)

                # add these newly found vertices to the list
                new_list.update(same_chip_vertices)

                sorted_vertices.append(new_list)
                found_list.update(new_list)

        # locate vertices which have no output or input, and add them for
        # placement
        for vertex in vertices:
            if vertex not in found_list:
                sorted_vertices.append([vertex])
        return sorted_vertices
Example #6
0
    def _clean_variables(self, variables):
        """ Sorts out variables for processing usage

        :param variables: list of variables names, or 'all', or single.
        :return: ordered set of variables strings.
        """
        # if variable is a base string, plonk into a array for ease of
        # conversion
        if isinstance(variables, string_types):
            variables = [variables]

        # if all are needed to be extracted, extract each and plonk into the
        # neo block segment. ensures whatever was in variables stays in
        # variables, regardless of all
        if 'all' in variables:
            variables = OrderedSet(variables)
            variables.remove('all')
            variables.update(self._get_all_recording_variables())
        return variables
def get_vertices_on_same_chip(vertex, graph):
    """ Get the vertices that must be on the same chip as the given vertex

    :param AbstractVertex vertex: The vertex to search with
    :param Graph graph: The graph containing the vertex
    :rtype: set(AbstractVertex)
    """
    # Virtual vertices can't be forced on different chips
    if isinstance(vertex, AbstractVirtual):
        return []
    same_chip_as_vertices = OrderedSet()
    for constraint in vertex.constraints:
        if isinstance(constraint, SameChipAsConstraint):
            same_chip_as_vertices.add(constraint.vertex)

    same_chip_as_vertices.update(
        edge.post_vertex for edge in graph.get_edges_starting_at_vertex(vertex)
        if edge.traffic_type == EdgeTrafficType.SDRAM)
    return same_chip_as_vertices