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

SpiNNakerManchester / sPyNNaker / 6942302574

21 Nov 2023 10:15AM UTC coverage: 63.153% (+1.6%) from 61.529%
6942302574

Pull #1342

github

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

1960 of 4482 branches covered (0.0%)

Branch coverage included in aggregate %.

4148 of 5078 new or added lines in 233 files covered. (81.69%)

193 existing lines in 78 files now uncovered.

12725 of 18771 relevant lines covered (67.79%)

0.68 hits per line

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

26.79
/spynnaker/pyNN/extra_algorithms/synapse_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, cast
1✔
16
from spinn_utilities.config_holder import get_config_bool
1✔
17
from spinn_utilities.log import FormatAdapter
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
    AbstractSynapseExpandable, SYNAPSE_EXPANDER_APLX)
28

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

31

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

36
    .. note::
37
        Needs to be done after data has been loaded.
38
    """
39
    # Find the places where the synapse expander and delay receivers should run
NEW
40
    expander_cores, expanded_placements, timeout = _plan_expansion()
×
41

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

53
    # Once expander has run, fill in the connection data.
NEW
54
    if expanded_placements:
×
NEW
55
        with ProgressBar(len(expanded_placements),
×
56
                         "Reading generated connections") as progress:
NEW
57
            for placement in progress.over(expanded_placements):
×
NEW
58
                vertex = cast(AbstractSynapseExpandable, placement.vertex)
×
NEW
59
                vertex.read_generated_connection_holders(placement)
×
60

61

62
def _plan_expansion() -> Tuple[ExecutableTargets, List[Placement], float]:
1✔
63
    """
64
    Plan the expansion of synapses and set up the regions using USER1.
65

66
    :return: The places to load the synapse expander and delay expander
67
        executables, the target machine vertices to read synapses back from,
68
        and an estimated timeout for how long the expansion should be let run.
69
    :rtype: tuple(~.ExecutableTargets, list(~.Placement), float)
70
    """
71
    synapse_bin = SpynnakerDataView.get_executable_path(SYNAPSE_EXPANDER_APLX)
×
72
    expander_cores = ExecutableTargets()
×
NEW
73
    expanded_placements = list()
×
NEW
74
    txrx = SpynnakerDataView.get_transceiver()
×
75

76
    max_data = 0
×
77
    max_bit_field = 0
×
78
    progress = ProgressBar(
×
79
        SpynnakerDataView.get_n_placements(), "Preparing to Expand Synapses")
80
    for placement in progress.over(SpynnakerDataView.iterate_placemements()):
×
81
        # Add all machine vertices of the population vertex to ones
82
        # that need synapse expansion
83
        vertex = placement.vertex
×
84
        if isinstance(vertex, AbstractSynapseExpandable):
×
85
            if vertex.gen_on_machine():
×
86
                expander_cores.add_processor(
×
87
                    synapse_bin, placement.x, placement.y, placement.p,
88
                    executable_type=ExecutableType.SYSTEM)
NEW
89
                expanded_placements.append(placement)
×
90
                # Write the region to USER1, as that is the best we can do
NEW
91
                txrx.write_user(
×
92
                    placement.x, placement.y, placement.p, UserRegister.USER_1,
93
                    vertex.connection_generator_region)
94
                max_data = max(max_data, vertex.max_gen_data)
×
95
                max_bit_field = max(max_bit_field, vertex.bit_field_size)
×
96

97
    # Allow 1 seconds per ~1000 synapses, with minimum of 2 seconds
NEW
98
    timeout = max(2.0, max_data / 1000.0)
×
99
    # Also allow 1s per 1000 bytes of bitfields
NEW
100
    timeout += max(2.0, max_bit_field / 1000.0)
×
NEW
101
    return expander_cores, expanded_placements, timeout
×
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