• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / sPyNNaker / 6903300058

17 Nov 2023 11:18AM UTC coverage: 63.17% (+1.6%) from 61.531%
6903300058

Pull #1342

github

Christian-B
oops
Pull Request #1342: Type Annotations and Checking

1961 of 4484 branches covered (0.0%)

Branch coverage included in aggregate %.

4169 of 5103 new or added lines in 234 files covered. (81.7%)

193 existing lines in 78 files now uncovered.

12745 of 18796 relevant lines covered (67.81%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.56
/spynnaker/pyNN/extra_algorithms/neuron_expander.py
1
# Copyright (c) 2017 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
import logging
1✔
15
from typing import List, Tuple
1✔
16
from spinn_utilities.log import FormatAdapter
1✔
17
from spinn_utilities.config_holder import get_config_bool
1✔
18
from spinn_utilities.progress_bar import ProgressBar
1✔
19
from spinnman.model.enums import ExecutableType
1✔
20
from spinnman.model import ExecutableTargets
1✔
21
from spinnman.model.enums import CPUState, UserRegister
1✔
22
from pacman.model.placements import Placement
1✔
23
from spinn_front_end_common.utilities.system_control_logic import (
1✔
24
    run_system_application)
25
from spynnaker.pyNN.data import SpynnakerDataView
1✔
26
from spynnaker.pyNN.models.abstract_models import (
1✔
27
    AbstractNeuronExpandable, NEURON_EXPANDER_APLX)
28

29
logger = FormatAdapter(logging.getLogger(__name__))
1✔
30

31

32
def neuron_expander() -> None:
1✔
33
    """
34
    Run the neuron expander.
35

36
    .. note::
37
        Needs to be done after data has been loaded.
38
    """
39
    # Find the places where the neuron expander should run
40
    expander_cores, expanded_pop_vertices = _plan_expansion()
×
41

NEW
42
    with ProgressBar(expander_cores.total_processors,
×
43
                     "Expanding Neuron Data") as progress:
NEW
44
        expander_app_id = SpynnakerDataView.get_new_id()
×
NEW
45
        run_system_application(
×
46
            expander_cores, expander_app_id,
47
            get_config_bool("Reports", "write_expander_iobuf") or False,
48
            None, frozenset({CPUState.FINISHED}), False,
49
            "neuron_expander_on_{}_{}_{}.txt", progress_bar=progress,
50
            logger=logger)
51

52
    _fill_in_initial_data(expanded_pop_vertices)
×
53

54

55
def _plan_expansion() -> Tuple[
1✔
56
        ExecutableTargets, List[Tuple[AbstractNeuronExpandable, Placement]]]:
57
    """
58
    Plan the expansion of neurons and set up the regions using USER1.
59

60
    :rtype: tuple(ExecutableTargets, list(tuple(MachineVertex, Placement)))
61
    """
62
    neuron_bin = SpynnakerDataView.get_executable_path(NEURON_EXPANDER_APLX)
×
NEW
63
    txrx = SpynnakerDataView.get_transceiver()
×
64

65
    expander_cores = ExecutableTargets()
×
NEW
66
    expanded_pop_vertices: List[
×
67
        Tuple[AbstractNeuronExpandable, Placement]] = list()
68

69
    progress = ProgressBar(
×
70
        SpynnakerDataView.get_n_placements(),
71
        "Preparing to Expand Neuron Data")
72
    for placement in progress.over(SpynnakerDataView.iterate_placemements()):
×
73
        # Add all machine vertices of the population vertex to ones
74
        # that need synapse expansion
75
        vertex = placement.vertex
×
76
        if isinstance(vertex, AbstractNeuronExpandable):
×
77
            if vertex.gen_neurons_on_machine():
×
78
                expanded_pop_vertices.append((vertex, placement))
×
79
                expander_cores.add_processor(
×
80
                    neuron_bin, placement.x, placement.y, placement.p,
81
                    executable_type=ExecutableType.SYSTEM)
82
                # Write the region to USER1, as that is the best we can do
NEW
83
                txrx.write_user(
×
84
                    placement.x, placement.y, placement.p, UserRegister.USER_1,
85
                    vertex.neuron_generator_region)
86

87
    return expander_cores, expanded_pop_vertices
×
88

89

90
def _fill_in_initial_data(expanded_pop_vertices: List[
1✔
91
        Tuple[AbstractNeuronExpandable, Placement]]):
92
    """
93
    Once expander has run, fill in the connection data.
94

95
    :param list(MachineVertex, Placement) expanded_pop_vertices:
96
        List of machine vertices to read data from
97
    :param ~spinnman.transceiver.Transceiver transceiver:
98
        How to talk to the machine
99
    """
100
    progress = ProgressBar(
×
101
        len(expanded_pop_vertices), "Getting initial values")
102
    for vertex, placement in progress.over(expanded_pop_vertices):
×
103
        vertex.read_generated_initial_values(placement)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc