Пример #1
0
def test_connector(
        clist, column_names, weights, delays, expected_clist, expected_weights,
        expected_delays, expected_extra_parameters,
        expected_extra_parameter_names):
    MockSimulator.setup()
    connector = FromListConnector(clist, column_names=column_names)
    if expected_clist is not None:
        assert(numpy.array_equal(connector.conn_list, expected_clist))
    else:
        assert(numpy.array_equal(connector.conn_list, clist))

    # Check extra parameters are as expected
    extra_params = connector.get_extra_parameters()
    extra_param_names = connector.get_extra_parameter_names()
    assert(numpy.array_equal(extra_params, expected_extra_parameters))
    assert(numpy.array_equal(
        extra_param_names, expected_extra_parameter_names))
    if extra_params is not None:
        assert(len(extra_params.shape) == 2)
        assert(extra_params.shape[1] == len(extra_param_names))
        for i in range(len(extra_param_names)):
            assert(extra_params[:, i].shape == (len(clist), ))

    # Check weights and delays are used or ignored as expected
    block = connector.create_synaptic_block(
        weights, delays, [], 0, [], 0, Slice(0, 10), Slice(0, 10), 1)
    assert(numpy.array_equal(block["weight"], numpy.array(expected_weights)))
    assert(numpy.array_equal(block["delay"], numpy.array(expected_delays)))
Пример #2
0
def test_csa_one_to_one_connector():
    unittest_setup()
    connector = CSAConnector(csa.oneToOne)
    weight = 1.0
    delay = 2.0
    synapse_info = SynapseInformation(connector=None,
                                      pre_population=MockPopulation(10, "Pre"),
                                      post_population=MockPopulation(
                                          10, "Post"),
                                      prepop_is_view=False,
                                      postpop_is_view=False,
                                      rng=None,
                                      synapse_dynamics=None,
                                      synapse_type=None,
                                      receptor_type=None,
                                      is_virtual_machine=False,
                                      synapse_type_from_dynamics=False,
                                      weights=weight,
                                      delays=delay)
    connector.set_projection_information(synapse_info)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block([pre_vertex_slice],
                                            [post_vertex_slice],
                                            pre_vertex_slice,
                                            post_vertex_slice, 0, synapse_info)
    assert (len(block) > 0)
    assert (all(item["source"] == item["target"] for item in block))
    assert (all(item["weight"] == 1.0 for item in block))
    assert (all(item["delay"] == 2.0 for item in block))
def test_connector(clist, column_names, weights, delays, expected_clist,
                   expected_weights, expected_delays,
                   expected_extra_parameters, expected_extra_parameter_names):
    MockSimulator.setup()
    connector = FromListConnector(clist, column_names=column_names)
    if expected_clist is not None:
        assert (numpy.array_equal(connector.conn_list, expected_clist))
    else:
        assert (numpy.array_equal(connector.conn_list, clist))

    # Check extra parameters are as expected
    extra_params = connector.get_extra_parameters()
    extra_param_names = connector.get_extra_parameter_names()
    assert (numpy.array_equal(extra_params, expected_extra_parameters))
    assert (numpy.array_equal(extra_param_names,
                              expected_extra_parameter_names))
    if extra_params is not None:
        assert (len(extra_params.shape) == 2)
        assert (extra_params.shape[1] == len(extra_param_names))
        for i in range(len(extra_param_names)):
            assert (extra_params[:, i].shape == (len(clist), ))

    # Check weights and delays are used or ignored as expected
    pre_slice = Slice(0, 10)
    post_slice = Slice(0, 10)
    mock_synapse_info = MockSynapseInfo(MockPopulation(10, "Pre"),
                                        MockPopulation(10, "Post"), weights,
                                        delays)
    block = connector.create_synaptic_block([pre_slice], 0, [post_slice], 0,
                                            pre_slice, post_slice, 1,
                                            mock_synapse_info)
    assert (numpy.array_equal(block["weight"], numpy.array(expected_weights)))
    assert (numpy.array_equal(block["delay"], numpy.array(expected_delays)))
Пример #4
0
def test_csa_from_list_connector():
    unittest_setup()
    conn_list = [(i, i + 1 % 10) for i in range(10)]
    connector = CSAConnector(conn_list)
    weight = 1.0
    delay = 2.0
    mock_synapse_info = SynapseInformation(
        connector=None,
        pre_population=MockPopulation(10, "Pre"),
        post_population=MockPopulation(10, "Post"),
        prepop_is_view=False,
        postpop_is_view=False,
        rng=None,
        synapse_dynamics=None,
        synapse_type=None,
        is_virtual_machine=False,
        weights=weight,
        delays=delay)
    connector.set_projection_information(mock_synapse_info)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block([pre_vertex_slice],
                                            [post_vertex_slice],
                                            pre_vertex_slice,
                                            post_vertex_slice, 0,
                                            mock_synapse_info)
    assert (len(block) > 0)
    assert (all(item["source"] == conn[0]
                for item, conn in zip(block, conn_list)))
    assert (all(item["target"] == conn[1]
                for item, conn in zip(block, conn_list)))
    assert (all(item["weight"] == 1.0 for item in block))
    assert (all(item["delay"] == 2.0 for item in block))
Пример #5
0
def test_csa_random_connector():
    unittest_setup()
    connector = CSAConnector(csa.random(0.05))
    weight = 1.0
    delay = 2.0
    mock_synapse_info = SynapseInformation(
        connector=None,
        pre_population=MockPopulation(10, "Pre"),
        post_population=MockPopulation(10, "Post"),
        prepop_is_view=False,
        postpop_is_view=False,
        rng=None,
        synapse_dynamics=None,
        synapse_type=None,
        is_virtual_machine=False,
        weights=weight,
        delays=delay)
    connector.set_projection_information(mock_synapse_info)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block([pre_vertex_slice],
                                            [post_vertex_slice],
                                            pre_vertex_slice,
                                            post_vertex_slice, 0,
                                            mock_synapse_info)
    assert (len(block) >= 0)
    assert (all(item["weight"] == 1.0 for item in block))
    assert (all(item["delay"] == 2.0 for item in block))
Пример #6
0
def test_csa_block_connector():
    MockSimulator.setup()
    try:
        # This creates a block of size (2, 5) with a probability of 0.5; then
        # within the block an individual connection has a probability of 0.3
        connector = CSAConnector(
            csa.block(2, 5) * csa.random(0.5) * csa.random(0.3))
        weight = 1.0
        delay = 2.0
        mock_synapse_info = MockSynapseInfo(MockPopulation(10, "pre"),
                                            MockPopulation(10, "post"), weight,
                                            delay)
        connector.set_projection_information(1000.0, mock_synapse_info)
        pre_vertex_slice = Slice(0, 10)
        post_vertex_slice = Slice(0, 10)
        block = connector.create_synaptic_block([pre_vertex_slice], 0,
                                                [post_vertex_slice], 0,
                                                pre_vertex_slice,
                                                post_vertex_slice, 0,
                                                mock_synapse_info)
        assert (len(block) >= 0)
        assert (all(item["weight"] == 1.0 for item in block))
        assert (all(item["delay"] == 2.0 for item in block))
    except TypeError:
        raise SkipTest("https://github.com/INCF/csa/issues/17")
    except RuntimeError:
        if sys.version_info >= (3, 7):
            raise SkipTest("https://github.com/INCF/csa/issues/16")
        raise
Пример #7
0
def test_connector_split():
    unittest_setup()
    n_sources = 1000
    n_targets = 1000
    n_connections = 10000
    pre_neurons_per_core = 57
    post_neurons_per_core = 59
    sources = numpy.random.randint(0, n_sources, n_connections)
    targets = numpy.random.randint(0, n_targets, n_connections)
    pre_slices = [
        Slice(i, i + pre_neurons_per_core - 1)
        for i in range(0, n_sources, pre_neurons_per_core)
    ]
    post_slices = [
        Slice(i, i + post_neurons_per_core - 1)
        for i in range(0, n_targets, post_neurons_per_core)
    ]

    connection_list = numpy.dstack((sources, targets))[0]
    connector = MockFromListConnector(connection_list)
    weight = 1.0
    delay = 1.0
    synapse_info = SynapseInformation(
        connector=None,
        pre_population=MockPopulation(n_sources, "Pre"),
        post_population=MockPopulation(n_targets, "Post"),
        prepop_is_view=False,
        postpop_is_view=False,
        rng=None,
        synapse_dynamics=None,
        synapse_type=None,
        is_virtual_machine=False,
        weights=weight,
        delays=delay)
    has_block = set()
    try:
        # Check each connection is in the right place
        for pre_slice in pre_slices:
            for post_slice in post_slices:
                block = connector.create_synaptic_block(
                    pre_slices, post_slices, pre_slice, post_slice, 1,
                    synapse_info)
                for source in block["source"]:
                    assert (pre_slice.lo_atom <= source <= pre_slice.hi_atom)
                for target in block["target"]:
                    assert (post_slice.lo_atom <= target <= post_slice.hi_atom)
                for item in block:
                    has_block.add((item["source"], item["target"]))

        # Check each connection has a place
        for source, target in zip(sources, targets):
            assert (source, target) in has_block

        # Check the split only happens once
        assert connector._split_count == 1
    except AssertionError as e:
        print(connection_list)
        raise e
Пример #8
0
def test_connector(clist, column_names, weights, delays, expected_clist,
                   expected_weights, expected_delays,
                   expected_extra_parameters, expected_extra_parameter_names):
    spynnaker8.setup()
    temp = tempfile.NamedTemporaryFile(delete=False)
    with temp as f:
        header = ''
        if column_names is not None:
            columns = ["i", "j"]
            columns.extend(column_names)
            header = 'columns = {}'.format(columns)
        if clist is not None and len(clist):
            numpy.savetxt(f, clist, header=header)
        elif len(header):
            f.write("# {}\n".format(header))

    connector = FromFileConnector(temp.name)
    if expected_clist is not None:
        assert (numpy.array_equal(connector.conn_list, expected_clist))
    else:
        assert (numpy.array_equal(connector.conn_list, clist))

    # Check extra parameters are as expected
    extra_params = connector.get_extra_parameters()
    extra_param_names = connector.get_extra_parameter_names()
    assert (numpy.array_equal(extra_params, expected_extra_parameters))
    assert (numpy.array_equal(extra_param_names,
                              expected_extra_parameter_names))
    if extra_params is not None:
        assert (len(extra_params.shape) == 2)
        assert (extra_params.shape[1] == len(extra_param_names))
        for i in range(len(extra_param_names)):
            assert (extra_params[:, i].shape == (len(clist), ))

    # Check weights and delays are used or ignored as expected
    pre_slice = Slice(0, 10)
    post_slice = Slice(0, 10)
    synapse_info = SynapseInformation(connector=None,
                                      pre_population=MockPopulation(10, "Pre"),
                                      post_population=MockPopulation(
                                          10, "Post"),
                                      prepop_is_view=False,
                                      postpop_is_view=False,
                                      rng=None,
                                      synapse_dynamics=None,
                                      synapse_type=None,
                                      receptor_type=None,
                                      is_virtual_machine=False,
                                      synapse_type_from_dynamics=False,
                                      weights=weights,
                                      delays=delays)
    block = connector.create_synaptic_block([pre_slice], [post_slice],
                                            pre_slice, post_slice, 1,
                                            synapse_info)
    assert (numpy.array_equal(block["weight"], numpy.array(expected_weights)))
    assert (numpy.array_equal(block["delay"], numpy.array(expected_delays)))
Пример #9
0
    def _get_estimate_synaptic_blocks_size(self, post_vertex_slice, in_edges,
                                           machine_time_step):
        """ Get an estimate of the synaptic blocks memory size
        """

        memory_size = self._get_static_synaptic_matrix_sdram_requirements()

        for in_edge in in_edges:
            if isinstance(in_edge, ProjectionApplicationEdge):

                # Get an estimate of the number of post vertices by
                # assuming that all of them are the same size as this one
                post_slices = [
                    Slice(
                        lo_atom,
                        min(in_edge.post_vertex.n_atoms,
                            lo_atom + post_vertex_slice.n_atoms - 1))
                    for lo_atom in range(0, in_edge.post_vertex.n_atoms,
                                         post_vertex_slice.n_atoms)
                ]
                post_slice_index = int(
                    math.floor(
                        float(post_vertex_slice.lo_atom) /
                        float(post_vertex_slice.n_atoms)))

                # Get an estimate of the number of pre-vertices - clearly
                # this will not be correct if the SDRAM usage is high!
                # TODO: Can be removed once we move to population-based keys
                n_atoms_per_machine_vertex = sys.maxint
                if isinstance(in_edge.pre_vertex, AbstractHasGlobalMaxAtoms):
                    n_atoms_per_machine_vertex = \
                        in_edge.pre_vertex.get_max_atoms_per_core()
                if in_edge.pre_vertex.n_atoms < n_atoms_per_machine_vertex:
                    n_atoms_per_machine_vertex = in_edge.pre_vertex.n_atoms

                pre_slices = [
                    Slice(
                        lo_atom,
                        min(in_edge.pre_vertex.n_atoms,
                            lo_atom + n_atoms_per_machine_vertex - 1))
                    for lo_atom in range(0, in_edge.pre_vertex.n_atoms,
                                         n_atoms_per_machine_vertex)
                ]

                pre_slice_index = 0
                for pre_vertex_slice in pre_slices:
                    memory_size += self._get_size_of_synapse_information(
                        in_edge.synapse_information, pre_slices,
                        pre_slice_index, post_slices, post_slice_index,
                        pre_vertex_slice, post_vertex_slice,
                        in_edge.n_delay_stages, machine_time_step)
                    pre_slice_index += 1

        return memory_size
Пример #10
0
def test_csa_random_connector():
    MockSimulator.setup()
    connector = CSAConnector(csa.random(0.05))
    connector.set_projection_information(
        MockPopulation(10, "pre"), MockPopulation(10, "post"),
        MockRNG(), 1000.0)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block(
        1.0, 2.0, [pre_vertex_slice], 0, [post_vertex_slice], 0,
        pre_vertex_slice, post_vertex_slice, 0)
    assert(len(block) >= 0)
    assert(all(item["weight"] == 1.0 for item in block))
    assert(all(item["delay"] == 2.0 for item in block))
def test_connector_split():
    MockSimulator.setup()
    n_sources = 1000
    n_targets = 1000
    n_connections = 10000
    pre_neurons_per_core = 57
    post_neurons_per_core = 59
    sources = numpy.random.randint(0, n_sources, n_connections)
    targets = numpy.random.randint(0, n_targets, n_connections)
    pre_slices = [
        Slice(i, i + pre_neurons_per_core - 1)
        for i in range(0, n_sources, pre_neurons_per_core)
    ]
    post_slices = [
        Slice(i, i + post_neurons_per_core - 1)
        for i in range(0, n_targets, post_neurons_per_core)
    ]

    connection_list = numpy.dstack((sources, targets))[0]
    connector = MockFromListConnector(connection_list)
    weight = 1.0
    delay = 1.0
    mock_synapse_info = MockSynapseInfo(MockPopulation(n_sources, "Pre"),
                                        MockPopulation(n_targets, "Post"),
                                        weight, delay)
    has_block = set()
    try:
        # Check each connection is in the right place
        for i, pre_slice in enumerate(pre_slices):
            for j, post_slice in enumerate(post_slices):
                block = connector.create_synaptic_block(
                    pre_slices, i, post_slices, j, pre_slice, post_slice, 1,
                    mock_synapse_info)
                for source in block["source"]:
                    assert (pre_slice.lo_atom <= source <= pre_slice.hi_atom)
                for target in block["target"]:
                    assert (post_slice.lo_atom <= target <= post_slice.hi_atom)
                for item in block:
                    has_block.add((item["source"], item["target"]))

        # Check each connection has a place
        for source, target in zip(sources, targets):
            assert (source, target) in has_block

        # Check the split only happens once
        assert connector._split_count == 1
    except AssertionError:
        print(connection_list)
        reraise(*sys.exc_info())
Пример #12
0
    def __read_connections(self, transceiver, placement, synapses_address):
        """ Read connections from an address on the machine

        :param Transceiver transceiver: How to read the data from the machine
        :param Placement placement: Where the matrix is on the machine
        :param int synapses_address:
            The base address of the synaptic matrix region
        :return: A list of arrays of connections, each with dtype
            AbstractSynapseDynamics.NUMPY_CONNECTORS_DTYPE
        :rtype: ~numpy.ndarray
        """
        pre_slice = Slice(0, self.__app_edge.pre_vertex.n_atoms + 1)
        connections = list()

        if self.__syn_mat_offset is not None:
            block = self.__get_block(transceiver, placement, synapses_address)
            splitter = self.__app_edge.post_vertex.splitter
            connections.append(convert_to_connections(
                self.__synapse_info, pre_slice, self.__post_vertex_slice,
                self.__max_row_info.undelayed_max_words,
                self.__n_synapse_types, self.__weight_scales, block,
                False, splitter.max_support_delay()))

        if self.__delay_syn_mat_offset is not None:
            block = self.__get_delayed_block(
                transceiver, placement, synapses_address)
            splitter = self.__app_edge.post_vertex.splitter
            connections.append(convert_to_connections(
                self.__synapse_info, pre_slice, self.__post_vertex_slice,
                self.__max_row_info.delayed_max_words, self.__n_synapse_types,
                self.__weight_scales, block, True,
                splitter.max_support_delay()))

        return connections
Пример #13
0
def test_csa_block_connector():
    MockSimulator.setup()
    # This creates a block of size (2, 5) with a probability of 0.5; then
    # within the block an individual connection has a probability of 0.3
    connector = CSAConnector(
        csa.block(2, 5) * csa.random(0.5) * csa.random(0.3))
    connector.set_projection_information(
        MockPopulation(10, "pre"), MockPopulation(10, "post"),
        MockRNG(), 1000.0)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block(
        1.0, 2.0, [pre_vertex_slice], 0, [post_vertex_slice], 0,
        pre_vertex_slice, post_vertex_slice, 0)
    assert(len(block) >= 0)
    assert(all(item["weight"] == 1.0 for item in block))
    assert(all(item["delay"] == 2.0 for item in block))
Пример #14
0
    def __call__(self,
                 machine,
                 machine_graph,
                 n_samples_per_recording,
                 sampling_frequency,
                 application_graph=None,
                 graph_mapper=None):
        """ call that adds LPG vertices on Ethernet connected chips as\
            required.

        :param machine: the spinnaker machine as discovered
        :param application_graph: the application graph
        :param machine_graph: the machine graph
        :return: mapping between LPG params and LPG vertex
        """

        # create progress bar
        progress_bar = ProgressBar(len(list(machine.chips)),
                                   string_describing_what_being_progressed=(
                                       "Adding Chip power monitors to Graph"))

        for chip in progress_bar.over(machine.chips):

            # build constraint
            constraint = ChipAndCoreConstraint(chip.x, chip.y)

            # build machine vert
            machine_vertex = ChipPowerMonitorMachineVertex(
                label="chip_power_monitor_machine_vertex_for_chip({}:{})".
                format(chip.x, chip.y),
                sampling_frequency=sampling_frequency,
                n_samples_per_recording=n_samples_per_recording,
                constraints=[constraint])

            # add vert to graph
            machine_graph.add_vertex(machine_vertex)

            # deal with app graphs if needed
            if application_graph is not None:

                # build app vertex
                vertex_slice = Slice(0, 0)
                application_vertex = \
                    ChipPowerMonitorApplicationVertex(
                        label="chip_power_monitor_application_vertex_for"
                              "_chip({}:{})".format(chip.x, chip.y),
                        constraints=[constraint],
                        sampling_frequency=sampling_frequency,
                        n_samples_per_recording=n_samples_per_recording)

                # add to graph
                application_graph.add_vertex(application_vertex)

                # update graph mapper
                graph_mapper.add_vertex_mapping(machine_vertex, vertex_slice,
                                                application_vertex)
Пример #15
0
def test_connector(
        clist, column_names, weights, delays, expected_clist, expected_weights,
        expected_delays, expected_extra_parameters,
        expected_extra_parameter_names):
    MockSimulator.setup()
    temp = tempfile.NamedTemporaryFile(delete=False)
    with temp as f:
        header = ''
        if column_names is not None:
            columns = ["i", "j"]
            columns.extend(column_names)
            header = 'columns = {}'.format(columns)
        if clist is not None and len(clist):
            numpy.savetxt(f, clist, header=header)
        elif len(header):
            f.write("# {}\n".format(header))

    connector = FromFileConnector(temp.name)
    if expected_clist is not None:
        assert(numpy.array_equal(connector.conn_list, expected_clist))
    else:
        assert(numpy.array_equal(connector.conn_list, clist))

    # Check extra parameters are as expected
    extra_params = connector.get_extra_parameters()
    extra_param_names = connector.get_extra_parameter_names()
    assert(numpy.array_equal(extra_params, expected_extra_parameters))
    assert(numpy.array_equal(
        extra_param_names, expected_extra_parameter_names))
    if extra_params is not None:
        assert(len(extra_params.shape) == 2)
        assert(extra_params.shape[1] == len(extra_param_names))
        for i in range(len(extra_param_names)):
            assert(extra_params[:, i].shape == (len(clist), ))

    # Check weights and delays are used or ignored as expected
    pre_slice = Slice(0, 10)
    post_slice = Slice(0, 10)
    block = connector.create_synaptic_block(
        weights, delays, [pre_slice], 0, [post_slice], 0, pre_slice,
        post_slice, 1)
    assert(numpy.array_equal(block["weight"], numpy.array(expected_weights)))
    assert(numpy.array_equal(block["delay"], numpy.array(expected_delays)))
Пример #16
0
def test_csa_from_list_connector():
    MockSimulator.setup()
    conn_list = [(i, i + 1 % 10) for i in range(10)]
    connector = CSAConnector(conn_list)
    connector.set_projection_information(
        MockPopulation(10, "pre"), MockPopulation(10, "post"),
        MockRNG(), 1000.0)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block(
        1.0, 2.0, [pre_vertex_slice], 0, [post_vertex_slice], 0,
        pre_vertex_slice, post_vertex_slice, 0)
    assert(len(block) > 0)
    assert(all(item["source"] == conn[0]
               for item, conn in zip(block, conn_list)))
    assert(all(item["target"] == conn[1]
               for item, conn in zip(block, conn_list)))
    assert(all(item["weight"] == 1.0 for item in block))
    assert(all(item["delay"] == 2.0 for item in block))
Пример #17
0
    def write_on_chip_matrix_data(self, generator_data, block_addr):
        """ Prepare to write a matrix using an on-chip generator

        :param list(GeneratorData) generator_data: List of data to add to
        :param int block_addr:
            The address in the synaptic matrix region to start writing at
        :return: The updated block address
        :rtype: int
        """

        if self.__use_app_keys:
            # Reserve the space in the matrix for an application-level key,
            # and tell the pop table
            (block_addr, syn_addr, del_addr, syn_max_addr,
             del_max_addr) = self.__reserve_app_blocks(block_addr)

            pre_slices =\
                self.__app_edge.pre_vertex.splitter.get_out_going_slices()[0]
            if self.__max_row_info.delayed_max_n_synapses == 0:
                # If we are not using delays (as we have to sync with delays)
                # Generate for theoretical maximum pre-slices that the
                # generator can handle; Note that the generator can't handle
                # full pre-vertices without running out of memory in general,
                # so we break it down, but as little as possible
                max_atom = self.__app_edge.pre_vertex.n_atoms - 1
                pre_slices = [
                    Slice(lo_atom,
                          min(lo_atom + MAX_GENERATED_ATOMS - 1, max_atom))
                    for lo_atom in range(0, max_atom + 1, MAX_GENERATED_ATOMS)
                ]
            for pre_slice in pre_slices:
                syn_addr, syn_mat_offset = self.__next_app_on_chip_address(
                    syn_addr, syn_max_addr, pre_slice)
                del_addr, d_mat_offset = self.__next_app_delay_on_chip_address(
                    del_addr, del_max_addr, pre_slice)
                generator_data.append(
                    self.__get_generator_data(syn_mat_offset, d_mat_offset,
                                              pre_slices, pre_slice))
            for pre_slice in pre_slices:
                self.__write_on_chip_delay_data(pre_slices, pre_slice)
            return block_addr

        # Go through the edges of the application edge and write data for the
        # generator
        for m_edge in self.__m_edges:
            matrix = self.__get_matrix(m_edge)
            block_addr, syn_mat_offset = matrix.next_on_chip_address(
                block_addr)
            block_addr, d_mat_offset = matrix.next_delay_on_chip_address(
                block_addr)

            # Create the generator data and note it exists for this post vertex
            generator_data.append(
                matrix.get_generator_data(syn_mat_offset, d_mat_offset))
        return block_addr
Пример #18
0
def test_connector(clist, column_names, weights, delays, expected_clist,
                   expected_weights, expected_delays,
                   expected_extra_parameters, expected_extra_parameter_names):
    unittest_setup()
    connector = FromListConnector(clist, column_names=column_names)
    if expected_clist is not None:
        assert (numpy.array_equal(connector.conn_list, expected_clist))
    else:
        assert (numpy.array_equal(connector.conn_list, clist))

    # Check extra parameters are as expected
    extra_params = connector.get_extra_parameters()
    extra_param_names = connector.get_extra_parameter_names()
    assert (numpy.array_equal(extra_params, expected_extra_parameters))
    assert (numpy.array_equal(extra_param_names,
                              expected_extra_parameter_names))
    if extra_params is not None:
        assert (len(extra_params.shape) == 2)
        assert (extra_params.shape[1] == len(extra_param_names))
        for i in range(len(extra_param_names)):
            assert (extra_params[:, i].shape == (len(clist), ))

    # Check weights and delays are used or ignored as expected
    pre_slice = Slice(0, 10)
    post_slice = Slice(0, 10)
    synapse_info = SynapseInformation(connector=None,
                                      pre_population=MockPopulation(10, "Pre"),
                                      post_population=MockPopulation(
                                          10, "Post"),
                                      prepop_is_view=False,
                                      postpop_is_view=False,
                                      rng=None,
                                      synapse_dynamics=None,
                                      synapse_type=None,
                                      is_virtual_machine=False,
                                      weights=weights,
                                      delays=delays)
    block = connector.create_synaptic_block([pre_slice], [post_slice],
                                            pre_slice, post_slice, 1,
                                            synapse_info)
    assert (numpy.array_equal(block["weight"], numpy.array(expected_weights)))
    assert (numpy.array_equal(block["delay"], numpy.array(expected_delays)))
Пример #19
0
def test_csa_one_to_one_connector():
    MockSimulator.setup()
    connector = CSAConnector(csa.oneToOne)
    weight = 1.0
    delay = 2.0
    mock_synapse_info = MockSynapseInfo(MockPopulation(10, "pre"),
                                        MockPopulation(10, "post"), weight,
                                        delay)
    connector.set_projection_information(1000.0, mock_synapse_info)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block([pre_vertex_slice], 0,
                                            [post_vertex_slice], 0,
                                            pre_vertex_slice,
                                            post_vertex_slice, 0,
                                            mock_synapse_info)
    assert (len(block) > 0)
    assert (all(item["source"] == item["target"] for item in block))
    assert (all(item["weight"] == 1.0 for item in block))
    assert (all(item["delay"] == 2.0 for item in block))
Пример #20
0
def test_csa_block_connector():
    unittest_setup()
    try:
        # This creates a block of size (2, 5) with a probability of 0.5; then
        # within the block an individual connection has a probability of 0.3
        connector = CSAConnector(
            csa.block(2, 5) * csa.random(0.5) * csa.random(0.3))
        weight = 1.0
        delay = 2.0
        mock_synapse_info = SynapseInformation(
            connector=None,
            pre_population=MockPopulation(10, "Pre"),
            post_population=MockPopulation(10, "Post"),
            prepop_is_view=False,
            postpop_is_view=False,
            rng=None,
            synapse_dynamics=None,
            synapse_type=None,
            receptor_type=None,
            is_virtual_machine=False,
            synapse_type_from_dynamics=False,
            weights=weight,
            delays=delay)

        connector.set_projection_information(mock_synapse_info)
        pre_vertex_slice = Slice(0, 10)
        post_vertex_slice = Slice(0, 10)
        block = connector.create_synaptic_block([pre_vertex_slice], 0,
                                                [post_vertex_slice], 0,
                                                pre_vertex_slice,
                                                post_vertex_slice, 0,
                                                mock_synapse_info)
        assert (len(block) >= 0)
        assert (all(item["weight"] == 1.0 for item in block))
        assert (all(item["delay"] == 2.0 for item in block))
    except TypeError as e:
        raise SkipTest("https://github.com/INCF/csa/issues/17") from e
    except RuntimeError as e:
        if sys.version_info >= (3, 7):
            raise SkipTest("https://github.com/INCF/csa/issues/16") from e
        raise e
Пример #21
0
    def __get_fixed_slices(self):
        """ Get a list of fixed slices from the Application vertex

        :rtype: list(~pacman.model.graphs.common.Slice)
        """
        if self.__slices is not None:
            return self.__slices
        atoms_per_core = self._governed_app_vertex.get_max_atoms_per_core()
        n_atoms = self._governed_app_vertex.n_atoms
        self.__slices = [Slice(low, min(low + atoms_per_core - 1, n_atoms - 1))
                         for low in range(0, n_atoms, atoms_per_core)]
        return self.__slices
def test_could_connect():
    connector = FromListConnector([[0, 0], [1, 2], [2, 0], [3, 3], [2, 6],
                                   [1, 8], [4, 1], [5, 0], [6, 2], [4, 8]])
    pre_slices = [Slice(0, 3), Slice(4, 6), Slice(7, 9)]
    post_slices = [Slice(0, 2), Slice(3, 5), Slice(6, 9)]
    for pre_slice in pre_slices:
        for post_slice in post_slices:
            count = connector.get_n_connections(pre_slices, post_slices,
                                                pre_slice.hi_atom,
                                                post_slice.hi_atom)
            if count:
                assert (connector.could_connect(None, pre_slice, post_slice))
            else:
                assert (not connector.could_connect(None, pre_slice,
                                                    post_slice))
Пример #23
0
    def _generate_data_specification(self, spec, machine_time_step,
                                     time_scale_factor, n_machine_time_steps,
                                     ip_tags):
        """ this is used to support application vertex calling this directly

        :param spec: data spec
        :param machine_time_step: machine time step
        :param time_scale_factor: time scale factor
        :param n_machine_time_steps: n_machine time steps
        :param ip_tags: iptags
        :rtype: None
        """
        spec.comment("\n*** Spec for ChipPowerMonitor Instance ***\n\n")

        # Construct the data images needed for the Neuron:
        self._reserve_memory_regions(spec)
        self._write_setup_info(spec, machine_time_step, time_scale_factor,
                               n_machine_time_steps, Slice(0, 1), ip_tags)
        self._write_configuration_region(spec)

        # End-of-Spec:
        spec.end_specification()
Пример #24
0
def test_could_connect():
    unittest_setup()
    connector = FromListConnector([[0, 0], [1, 2], [2, 0], [3, 3], [2, 6],
                                   [1, 8], [4, 1], [5, 0], [6, 2], [4, 8]])
    pre_slices = [Slice(0, 3), Slice(4, 6), Slice(7, 9)]
    post_slices = [Slice(0, 2), Slice(3, 5), Slice(6, 9)]
    for pre_slice in pre_slices:
        pre_vertex = MockMachineVertex(pre_slice, pre_slices)
        for post_slice in post_slices:
            post_vertex = MockMachineVertex(post_slice, post_slices)
            count = connector.get_n_connections(pre_slices, post_slices,
                                                pre_slice.hi_atom,
                                                post_slice.hi_atom)
            if count:
                assert (connector.could_connect(None, pre_vertex, post_vertex))
            else:
                assert (not connector.could_connect(None, pre_vertex,
                                                    post_vertex))
Пример #25
0
    def test_write_synaptic_matrix_and_master_population_table(self):
        MockSimulator.setup()

        default_config_paths = os.path.join(
            os.path.dirname(abstract_spinnaker_common.__file__),
            AbstractSpiNNakerCommon.CONFIG_FILE_NAME)

        config = conf_loader.load_config(
            AbstractSpiNNakerCommon.CONFIG_FILE_NAME, default_config_paths)
        config.set("Simulation", "one_to_one_connection_dtcm_max_bytes", 40)

        machine_time_step = 1000.0

        pre_app_vertex = SimpleApplicationVertex(10)
        pre_vertex = SimpleMachineVertex(resources=None)
        pre_vertex_slice = Slice(0, 9)
        post_app_vertex = SimpleApplicationVertex(10)
        post_vertex = SimpleMachineVertex(resources=None)
        post_vertex_slice = Slice(0, 9)
        post_slice_index = 0
        one_to_one_connector_1 = OneToOneConnector(None)
        one_to_one_connector_1.set_projection_information(
            pre_app_vertex, post_app_vertex, None, machine_time_step)
        one_to_one_connector_1.set_weights_and_delays(1.5, 1.0)
        one_to_one_connector_2 = OneToOneConnector(None)
        one_to_one_connector_2.set_projection_information(
            pre_app_vertex, post_app_vertex, None, machine_time_step)
        one_to_one_connector_2.set_weights_and_delays(2.5, 2.0)
        all_to_all_connector = AllToAllConnector(None)
        all_to_all_connector.set_projection_information(
            pre_app_vertex, post_app_vertex, None, machine_time_step)
        all_to_all_connector.set_weights_and_delays(4.5, 4.0)
        direct_synapse_information_1 = SynapseInformation(
            one_to_one_connector_1, SynapseDynamicsStatic(), 0)
        direct_synapse_information_2 = SynapseInformation(
            one_to_one_connector_2, SynapseDynamicsStatic(), 1)
        all_to_all_synapse_information = SynapseInformation(
            all_to_all_connector, SynapseDynamicsStatic(), 0)
        app_edge = ProjectionApplicationEdge(
            pre_app_vertex, post_app_vertex, direct_synapse_information_1)
        app_edge.add_synapse_information(direct_synapse_information_2)
        app_edge.add_synapse_information(all_to_all_synapse_information)
        machine_edge = ProjectionMachineEdge(
            app_edge.synapse_information, pre_vertex, post_vertex)
        partition_name = "TestPartition"

        graph = MachineGraph("Test")
        graph.add_vertex(pre_vertex)
        graph.add_vertex(post_vertex)
        graph.add_edge(machine_edge, partition_name)

        graph_mapper = GraphMapper()
        graph_mapper.add_vertex_mapping(
            pre_vertex, pre_vertex_slice, pre_app_vertex)
        graph_mapper.add_vertex_mapping(
            post_vertex, post_vertex_slice, post_app_vertex)
        graph_mapper.add_edge_mapping(machine_edge, app_edge)

        weight_scales = [4096.0, 4096.0]

        key = 0
        routing_info = RoutingInfo()
        routing_info.add_partition_info(PartitionRoutingInfo(
            [BaseKeyAndMask(key, 0xFFFFFFF0)],
            graph.get_outgoing_edge_partition_starting_at_vertex(
                pre_vertex, partition_name)))

        temp_spec = tempfile.mktemp()
        spec_writer = FileDataWriter(temp_spec)
        spec = DataSpecificationGenerator(spec_writer, None)
        master_pop_sz = 1000
        master_pop_region = 0
        all_syn_block_sz = 2000
        synapse_region = 1
        spec.reserve_memory_region(master_pop_region, master_pop_sz)
        spec.reserve_memory_region(synapse_region, all_syn_block_sz)

        synapse_type = MockSynapseType()

        synaptic_manager = SynapticManager(
            synapse_type=synapse_type, ring_buffer_sigma=5.0,
            spikes_per_second=100.0, config=config)
        synaptic_manager._write_synaptic_matrix_and_master_population_table(
            spec, [post_vertex_slice], post_slice_index, post_vertex,
            post_vertex_slice, all_syn_block_sz, weight_scales,
            master_pop_region, synapse_region, routing_info, graph_mapper,
            graph, machine_time_step)
        spec.end_specification()
        spec_writer.close()

        spec_reader = FileDataReader(temp_spec)
        executor = DataSpecificationExecutor(
            spec_reader, master_pop_sz + all_syn_block_sz)
        executor.execute()

        master_pop_table = executor.get_region(0)
        synaptic_matrix = executor.get_region(1)

        all_data = bytearray()
        all_data.extend(master_pop_table.region_data[
            :master_pop_table.max_write_pointer])
        all_data.extend(synaptic_matrix.region_data[
            :synaptic_matrix.max_write_pointer])
        master_pop_table_address = 0
        synaptic_matrix_address = master_pop_table.max_write_pointer
        direct_synapses_address = struct.unpack_from(
            "<I", synaptic_matrix.region_data)[0]
        direct_synapses_address += synaptic_matrix_address + 8
        indirect_synapses_address = synaptic_matrix_address + 4
        placement = Placement(None, 0, 0, 1)
        transceiver = MockTransceiverRawData(all_data)

        # Get the master population table details
        items = synaptic_manager._poptable_type\
            .extract_synaptic_matrix_data_location(
                key, master_pop_table_address, transceiver,
                placement.x, placement.y)

        # The first entry should be direct, but the rest should be indirect;
        # the second is potentially direct, but has been restricted by the
        # restriction on the size of the direct matrix
        assert len(items) == 3

        # TODO: This has been changed because direct matrices are disabled!
        assert not items[0][2]
        assert not items[1][2]
        assert not items[2][2]

        data_1, row_len_1 = synaptic_manager._retrieve_synaptic_block(
            transceiver=transceiver, placement=placement,
            master_pop_table_address=master_pop_table_address,
            indirect_synapses_address=indirect_synapses_address,
            direct_synapses_address=direct_synapses_address, key=key,
            n_rows=pre_vertex_slice.n_atoms, index=0,
            using_extra_monitor_cores=False)
        connections_1 = synaptic_manager._synapse_io.read_synapses(
            direct_synapse_information_1, pre_vertex_slice, post_vertex_slice,
            row_len_1, 0, 2, weight_scales, data_1, None,
            app_edge.n_delay_stages, machine_time_step)

        # The first matrix is a 1-1 matrix, so row length is 1
        assert row_len_1 == 1

        # Check that all the connections have the right weight and delay
        assert len(connections_1) == post_vertex_slice.n_atoms
        assert all([conn["weight"] == 1.5 for conn in connections_1])
        assert all([conn["delay"] == 1.0 for conn in connections_1])

        data_2, row_len_2 = synaptic_manager._retrieve_synaptic_block(
            transceiver=transceiver, placement=placement,
            master_pop_table_address=master_pop_table_address,
            indirect_synapses_address=indirect_synapses_address,
            direct_synapses_address=direct_synapses_address, key=key,
            n_rows=pre_vertex_slice.n_atoms, index=1,
            using_extra_monitor_cores=False)
        connections_2 = synaptic_manager._synapse_io.read_synapses(
            direct_synapse_information_2, pre_vertex_slice, post_vertex_slice,
            row_len_2, 0, 2, weight_scales, data_2, None,
            app_edge.n_delay_stages, machine_time_step)

        # The second matrix is a 1-1 matrix, so row length is 1
        assert row_len_2 == 1

        # Check that all the connections have the right weight and delay
        assert len(connections_2) == post_vertex_slice.n_atoms
        assert all([conn["weight"] == 2.5 for conn in connections_2])
        assert all([conn["delay"] == 2.0 for conn in connections_2])

        data_3, row_len_3 = synaptic_manager._retrieve_synaptic_block(
            transceiver=transceiver, placement=placement,
            master_pop_table_address=master_pop_table_address,
            indirect_synapses_address=indirect_synapses_address,
            direct_synapses_address=direct_synapses_address, key=key,
            n_rows=pre_vertex_slice.n_atoms, index=2,
            using_extra_monitor_cores=False)
        connections_3 = synaptic_manager._synapse_io.read_synapses(
            all_to_all_synapse_information, pre_vertex_slice,
            post_vertex_slice, row_len_3, 0, 2, weight_scales, data_3, None,
            app_edge.n_delay_stages, machine_time_step)

        # The third matrix is an all-to-all matrix, so length is n_atoms
        assert row_len_3 == post_vertex_slice.n_atoms

        # Check that all the connections have the right weight and delay
        assert len(connections_3) == \
            post_vertex_slice.n_atoms * pre_vertex_slice.n_atoms
        assert all([conn["weight"] == 4.5 for conn in connections_3])
        assert all([conn["delay"] == 4.0 for conn in connections_3])
Пример #26
0
def test_connectors(n_pre, n_post, n_in_slice, create_connector, weight,
                    delay):

    MockSimulator.setup()

    max_target = 0
    max_source = 0
    for seed in range(1000):
        numpy.random.seed(seed)
        connector = create_connector()
        connector.set_projection_information(
            pre_population=MockPopulation(n_pre, "Pre"),
            post_population=MockPopulation(n_post, "Post"),
            rng=None,
            machine_time_step=1000)
        connector.set_weights_and_delays(weight, delay)

        pre_slices = [
            Slice(i, i + n_in_slice - 1) for i in range(0, n_pre, n_in_slice)
        ]
        post_slices = [
            Slice(i, i + n_in_slice - 1) for i in range(0, n_post, n_in_slice)
        ]
        pre_slice_index = 0
        post_slice_index = 0
        pre_vertex_slice = pre_slices[pre_slice_index]
        post_vertex_slice = post_slices[post_slice_index]
        synapse_type = 0
        pre_slice = pre_slices[pre_slice_index]
        post_slice = post_slices[post_slice_index]
        pre_range = numpy.arange(pre_slice.lo_atom, pre_slice.hi_atom + 2)
        post_range = numpy.arange(post_slice.lo_atom, post_slice.hi_atom + 2)

        max_delay = connector.get_delay_maximum()
        max_weight = connector.get_weight_maximum(pre_slices, pre_slice_index,
                                                  post_slices,
                                                  post_slice_index,
                                                  pre_vertex_slice,
                                                  post_vertex_slice)
        max_row_length = connector.get_n_connections_from_pre_vertex_maximum(
            pre_slices, pre_slice_index, post_slices, post_slice_index,
            pre_vertex_slice, post_vertex_slice)
        max_col_length = connector.get_n_connections_to_post_vertex_maximum(
            pre_slices, pre_slice_index, post_slices, post_slice_index,
            pre_vertex_slice, post_vertex_slice)
        synaptic_block = connector.create_synaptic_block(
            pre_slices, pre_slice_index, post_slices, post_slice_index,
            pre_vertex_slice, post_vertex_slice, synapse_type)
        source_histogram = numpy.histogram(synaptic_block["source"],
                                           pre_range)[0]
        target_histogram = numpy.histogram(synaptic_block["target"],
                                           post_range)[0]
        matrix_max_weight = (max(synaptic_block["weight"])
                             if len(synaptic_block) > 0 else 0)
        matrix_max_delay = (max(synaptic_block["delay"])
                            if len(synaptic_block) > 0 else 0)

        max_source = max((max(source_histogram), max_source))
        max_target = max((max(target_histogram), max_target))

        if len(post_slices) > post_slice_index + 1:
            test_post_slice = post_slices[post_slice_index + 1]
            test_synaptic_block = connector.create_synaptic_block(
                pre_slices, pre_slice_index, post_slices, post_slice_index + 1,
                pre_vertex_slice, test_post_slice, synapse_type)
            if len(test_synaptic_block) > 0:
                assert not numpy.array_equal(test_synaptic_block,
                                             synaptic_block)
        if len(pre_slices) > pre_slice_index + 1:
            test_pre_slice = pre_slices[pre_slice_index + 1]
            test_synaptic_block = connector.create_synaptic_block(
                pre_slices, pre_slice_index + 1, post_slices, post_slice_index,
                test_pre_slice, post_vertex_slice, synapse_type)
            if len(test_synaptic_block) > 0:
                assert not numpy.array_equal(test_synaptic_block,
                                             synaptic_block)

        try:
            assert max(source_histogram) <= max_row_length
            assert max(target_histogram) <= max_col_length
            assert matrix_max_weight <= max_weight
            assert matrix_max_delay <= max_delay
        except Exception:
            print connector.__class__.__name__
            print max_row_length, max(source_histogram), source_histogram
            print max_col_length, max(target_histogram), target_histogram
            print max_weight, matrix_max_weight, synaptic_block["weight"]
            print max_delay, matrix_max_delay, synaptic_block["delay"]
            raise
    print(connector.__class__.__name__, max_row_length, max_source,
          max_col_length, max_target)