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

SpiNNakerManchester / PACMAN / 8143395689

04 Mar 2024 04:13PM UTC coverage: 86.121%. Remained the same
8143395689

push

github

web-flow
Merge pull request #541 from SpiNNakerManchester/pylint_default

Pylint default

2688 of 3185 branches covered (84.4%)

Branch coverage included in aggregate %.

39 of 42 new or added lines in 32 files covered. (92.86%)

1 existing line in 1 file now uncovered.

5168 of 5937 relevant lines covered (87.05%)

0.87 hits per line

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

41.89
/pacman/utilities/algorithm_utilities/partition_algorithm_utilities.py
1
# Copyright (c) 2015 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
"""
1✔
15
A collection of methods which support partitioning algorithms.
16
"""
17

18
import math
1✔
19
from typing import List
1✔
20
from pacman.exceptions import PacmanConfigurationException
1✔
21
from pacman.model.graphs.common import MDSlice, Slice
1✔
22
from pacman.model.graphs.application import ApplicationVertex
1✔
23

24

25
def get_multidimensional_slices(
1✔
26
        app_vertex: ApplicationVertex) -> List[Slice]:
27
    """
28
    Get the multi-dimensional slices of an application vertex
29
    such that each is sized to the maximum atoms per dimension per core
30
    except the last, which might be smaller in one or more dimensions.
31

32
    :param ApplicationVertex app_vertex: The vertex to get the slices of
33
    :return: The slices
34
    :rtype: list(~pacman.model.graphs.common.Slice)
35
    """
36
    atoms_per_core = app_vertex.get_max_atoms_per_dimension_per_core()
1✔
37
    n_atoms = app_vertex.atoms_shape
1✔
38
    if len(atoms_per_core) != len(n_atoms):
1!
39
        raise PacmanConfigurationException(
×
40
            "The length of atoms_per_core doesn't match the number of"
41
            " dimensions")
42

43
    if len(app_vertex.atoms_shape) == 1:
1!
44
        return get_single_dimension_slices(app_vertex)
1✔
45

46
    # If there is only one slice, get that
47
    if app_vertex.n_atoms <= app_vertex.get_max_atoms_per_core():
×
48
        return [MDSlice(0, app_vertex.n_atoms - 1, app_vertex.atoms_shape,
×
49
                        tuple(0 for _ in app_vertex.atoms_shape),
50
                        app_vertex.atoms_shape)]
51

52
    # Find out how many vertices we will create, keeping track of the
53
    # total atoms per core, and the numerator to divide by when working
54
    # out positions
55
    n_vertices = 1
×
56
    total_atoms_per_core = 1
×
57
    dim_numerator = [0] * len(n_atoms)
×
58
    total_n_atoms = 1
×
NEW
59
    for d, n_atom in enumerate(n_atoms):
×
60
        dim_numerator[d] = n_vertices
×
NEW
61
        n_this_dim = int(math.ceil(n_atom / atoms_per_core[d]))
×
62
        n_vertices *= n_this_dim
×
63
        total_atoms_per_core *= atoms_per_core[d]
×
NEW
64
        total_n_atoms *= n_atom
×
65

66
    # Run over all the vertices and create slices for them
67
    slices: List[Slice] = list()
×
68
    hi_atom = -1
×
69
    for v in range(n_vertices):
×
70
        # Work out where in each of the dimensions this vertex starts by
71
        # dividing the remainder from the previous dimension by the
72
        # numerator of each dimension
73
        start = [0] * len(n_atoms)
×
74
        n_on_core = [0] * len(n_atoms)
×
75
        remainder = v
×
76
        total_on_core = 1
×
77
        for d in reversed(range(len(n_atoms))):
×
78
            start[d] = (remainder // dim_numerator[d]) * atoms_per_core[d]
×
79
            remainder = remainder % dim_numerator[d]
×
80
            hi_d = min(start[d] + atoms_per_core[d], n_atoms[d])
×
81
            n_on_core[d] = hi_d - start[d]
×
82
            total_on_core *= n_on_core[d]
×
83

84
        # Make a slice and a vertex
85
        lo_atom = hi_atom + 1
×
86
        hi_atom = (lo_atom + total_on_core) - 1
×
87
        vertex_slice = MDSlice(
×
88
            lo_atom, hi_atom, tuple(n_on_core), tuple(start),
89
            app_vertex.atoms_shape)
90
        slices.append(vertex_slice)
×
91

92
    return slices
×
93

94

95
def get_single_dimension_slices(app_vertex: ApplicationVertex) -> List[Slice]:
1✔
96
    """ Get the single dimension slices of an application vertex
97
        such that each is sized to the maximum atoms per dimension per core
98
        except the last which might be smaller in one or more dimensions
99

100
    :param ApplicationVertex app_vertex: The vertex to get the slices of
101
    """
102
    # If there is only one slice, get that
103
    if app_vertex.n_atoms < app_vertex.get_max_atoms_per_core():
1✔
104
        return [Slice(0, app_vertex.n_atoms - 1)]
1✔
105

106
    total_on_core = app_vertex.get_max_atoms_per_dimension_per_core()[0]
1✔
107

108
    n_vertices = math.ceil(app_vertex.n_atoms / total_on_core)
1✔
109

110
    # Run over all the vertices and create slices for them
111
    slices = list()
1✔
112
    hi_atom = -1
1✔
113
    for _ in range(n_vertices):
1✔
114
        # Make a slice
115
        lo_atom = hi_atom + 1
1✔
116
        hi_atom = min(app_vertex.n_atoms - 1, (lo_atom + total_on_core) - 1)
1✔
117
        vertex_slice = Slice(lo_atom, hi_atom)
1✔
118
        slices.append(vertex_slice)
1✔
119

120
    return slices
1✔
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

© 2026 Coveralls, Inc