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

SpiNNakerManchester / SpiNNMan / 6574804013

19 Oct 2023 12:47PM UTC coverage: 51.937% (+1.2%) from 50.777%
6574804013

Pull #327

github

Christian-B
typing changes
Pull Request #327: Type Annotations and Checking

105 of 1288 branches covered (0.0%)

Branch coverage included in aggregate %.

2375 of 2375 new or added lines in 180 files covered. (100.0%)

4775 of 8108 relevant lines covered (58.89%)

0.59 hits per line

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

28.79
/spinnman/transceiver/transceiver_factory.py
1
# Copyright (c) 2023 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

15
import logging
1✔
16
from typing import (List, Optional)
1✔
17
from spinn_utilities.log import FormatAdapter
1✔
18
from spinn_machine.version.version_3 import Version3
1✔
19
from spinn_machine.version.version_5 import Version5
1✔
20
from spinnman.connections.abstract_classes import Connection
1✔
21
from spinnman.data import SpiNNManDataView
1✔
22
from spinnman.extended.version3transceiver import ExtendedVersion3Transceiver
1✔
23
from spinnman.extended.version5transceiver import ExtendedVersion5Transceiver
1✔
24
from spinnman.model.bmp_connection_data import BMPConnectionData
1✔
25
from spinnman.utilities.utility_functions import (
1✔
26
    work_out_bmp_from_machine_details)
27
from spinnman.connections.udp_packet_connections import (
1✔
28
    BMPConnection, BootConnection, SCAMPConnection)
29
from spinnman.transceiver.version3transceiver import Version3Transceiver
1✔
30
from spinnman.transceiver.version5transceiver import Version5Transceiver
1✔
31
from spinnman.transceiver.virtual5Transceiver import Virtual5Transceiver
1✔
32
from spinnman.constants import LOCAL_HOST
1✔
33

34
logger = FormatAdapter(logging.getLogger(__name__))
1✔
35

36

37
def create_transceiver_from_hostname(
1✔
38
        hostname: Optional[str], *,
39
        bmp_connection_data: Optional[BMPConnectionData] = None,
40
        auto_detect_bmp: bool = False, power_cycle: bool = False,
41
        extended: bool = False):
42
    """
43
    Create a Transceiver by creating a :py:class:`~.UDPConnection` to the
44
    given hostname on port 17893 (the default SCAMP port), and a
45
    :py:class:`~.BootConnection` on port 54321 (the default boot port),
46
    optionally discovering any additional links using the UDPConnection,
47
    and then returning the transceiver created with the conjunction of
48
    the created UDPConnection and the discovered connections.
49

50
    :param hostname: The hostname or IP address of the board or `None` if
51
        only the BMP connections are of interest
52
    :type hostname: str or None
53
    :type number_of_boards: int or None
54
    :param BMPConnectionData bmp_connection_data:
55
        the details of the BMP connections used to boot multi-board systems
56
    :param bool auto_detect_bmp:
57
        ``True`` if the BMP of version 4 or 5 boards should be
58
        automatically determined from the board IP address
59
    :param bool power_cycle: If True will power cycle the machine
60
    :param scamp_connections:
61
        the list of connections used for SCAMP communications
62
    :param bool extended:
63
        If True will return an Extended version of the Transceiver
64
    :return: The created transceiver
65
    :rtype: spinnman.transceiver.Transceiver
66
    :raise SpinnmanIOException:
67
        If there is an error communicating with the board
68
    :raise SpinnmanInvalidPacketException:
69
        If a packet is received that is not in the valid format
70
    :raise SpinnmanInvalidParameterException:
71
        If a packet is received that has invalid parameters
72
    :raise SpinnmanUnexpectedResponseCodeException:
73
        If a response indicates an error during the exchange
74
    """
75
    if hostname is not None:
×
76
        logger.info("Creating transceiver for {}", hostname)
×
77
    connections: List[Connection] = list()
×
78

79
    # if no BMP has been supplied, but the board is a spinn4 or a spinn5
80
    # machine, then an assumption can be made that the BMP is at -1 on the
81
    # final value of the IP address
82
    version = SpiNNManDataView.get_machine_version()
×
83
    if (isinstance(version, Version5) and auto_detect_bmp is True and
×
84
            (bmp_connection_data is None)):
85
        if hostname is None:
×
86
            raise ValueError("hostname is required if deriving BMP details")
×
87
        bmp_connection_data = \
×
88
            work_out_bmp_from_machine_details(hostname)
89

90
    # handle BMP connections
91
    if bmp_connection_data is not None:
×
92
        bmp_connection = BMPConnection(bmp_connection_data)
×
93
        connections.append(bmp_connection)
×
94
        logger.info("Transceiver using BMP: {}",
×
95
                    bmp_connection.remote_ip_address)
96

97
    connections.append(SCAMPConnection(remote_host=hostname))
×
98

99
    # handle the boot connection
100
    connections.append(BootConnection(remote_host=hostname))
×
101

102
    if hostname == LOCAL_HOST:
×
103
        return create_transceiver_from_connections(
×
104
            connections=connections, virtual=True, extended=extended)
105
    else:
106
        return create_transceiver_from_connections(
×
107
            connections=connections, virtual=False, power_cycle=power_cycle,
108
            extended=extended)
109

110

111
def create_transceiver_from_connections(
1✔
112
        connections: List[Connection], virtual: bool = False,
113
        power_cycle: bool = False, extended: bool = False):
114
    """
115
    Create a Transceiver with these connections
116

117
    :param list(Connection) connections:
118
        An iterable of connections to the board.  If not specified, no
119
        communication will be possible until connections are found.
120
    :param bool virtual: If True will return a virtual Transceiver
121
    :param bool power_cycle: If True will power cycle the machine
122
    :param bool extended:
123
    :return: The created transceiver
124
    :rtype: spinnman.transceiver.Transceiver
125
    :raise SpinnmanIOException:
126
        If there is an error communicating with the board
127
    :raise SpinnmanInvalidPacketException:
128
        If a packet is received that is not in the valid format
129
    :raise SpinnmanInvalidParameterException:
130
        If a packet is received that has invalid parameters
131
    :raise SpinnmanUnexpectedResponseCodeException:
132
        If a response indicates an error during the exchange
133
    """
134
    version = SpiNNManDataView.get_machine_version()
×
135
    if isinstance(version, Version3):
×
136
        if virtual:
×
137
            raise NotImplementedError(f"No Virtual Transceiver for {version=}")
138
        if extended:
×
139
            return ExtendedVersion3Transceiver(
×
140
                connections=connections, power_cycle=power_cycle)
141
        return Version3Transceiver(
×
142
            connections=connections, power_cycle=power_cycle)
143
    if isinstance(version, Version5):
×
144
        if virtual:
×
145
            return Virtual5Transceiver(
×
146
                connections=connections, power_cycle=power_cycle)
147
        if extended:
×
148
            return ExtendedVersion5Transceiver(
×
149
                connections=connections, power_cycle=power_cycle)
150
        return Version5Transceiver(
×
151
            connections=connections, power_cycle=power_cycle)
152
    raise NotImplementedError(f"No Transceiver for {version=}")
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