• 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

18.6
/spinnman/get_cores_in_run_state.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

15
"""
1✔
16
This is a script used to check the state of a SpiNNaker machine.
17
"""
18

19
import sys
1✔
20
import argparse
1✔
21
from spinn_utilities.config_holder import set_config
1✔
22
from spinnman.transceiver import create_transceiver_from_hostname
1✔
23
from spinn_machine import CoreSubsets, CoreSubset
1✔
24
from spinnman.board_test_configuration import BoardTestConfiguration
1✔
25
from spinnman.config_setup import unittest_setup
1✔
26
from spinnman.model.enums import CPUState
1✔
27
SCAMP_ID = 0
1✔
28
IGNORED_IDS = {SCAMP_ID, 16}  # WHY 16?
1✔
29

30

31
def get_cores_in_run_state(txrx, app_id, print_all_chips):
1✔
32
    """
33
    :param Transceiver txrx:
34
    :param int app_id:
35
    :param bool print_all_chips:
36
    """
37
    count_finished = txrx.get_core_state_count(app_id, CPUState.FINISHED)
×
38
    count_run = txrx.get_core_state_count(app_id, CPUState.RUNNING)
×
39
    print(f'running: {count_run} finished: {count_finished}')
×
40

41
    machine = txrx.get_machine_details()
×
42
    print(f'machine width: {machine.width} height: {machine.height}')
×
43
    if print_all_chips:
×
44
        print(f'machine chips: {list(machine.chips)}')
×
45

46
    all_cores = []
×
47
    for chip in machine.chips:
×
48
        all_cores.append(CoreSubset(chip.x, chip.y, range(1, 17)))
×
49

50
    all_cores = CoreSubsets(core_subsets=all_cores)
×
51

52
    cpu_infos = txrx.get_cpu_infos(
×
53
        all_cores,
54
        [CPUState.FINISHED, CPUState.RUNNING, CPUState.WATCHDOG], True)
55
    cores_finished = cpu_infos.infos_for_state(CPUState.FINISHED)
×
56
    cores_running = cpu_infos.infos_for_state(CPUState.RUNNING)
×
57
    cores_watchdog = cpu_infos.infos_for_state(CPUState.WATCHDOG)
×
58

59
    for (x, y, p), _ in cores_running:
×
60
        if p not in IGNORED_IDS:
×
61
            print(f'run core: {x} {y} {p}')
×
62

63
    for (x, y, p), _ in cores_finished:
×
64
        print(f'finished core: {x} {y} {p}')
×
65

66
    for (x, y, p), _ in cores_watchdog:
×
67
        print(f'watchdog core: {x} {y} {p}')
×
68

69

70
def _make_transceiver(host, version, bmp_names):
1✔
71
    """
72
    :param host:
73
        Host to use or `None` to use test configuration for all parameters
74
    :type host: str or None
75
    :param version: Board version to use (`None` defaults to 5 unless host is
76
        192.168.240.253 (spin 3)
77
    :type version: int or None
78
    :param bmp: bmp connection or `None` to auto detect (if applicable)
79
    :type bmp: str or None
80
    :rtype: Transceiver
81
    """
82
    if host is None:
×
83
        config = BoardTestConfiguration()
×
84
        config.set_up_remote_board()
×
85
        host = config.remotehost
×
86
        bmp_names = None
×
87
        auto_detect_bmp = config.auto_detect_bmp
×
88
    else:
89
        if version is None:
×
90
            if host == "192.168.240.253":
×
91
                version = 3
×
92
            else:
93
                version = 5
×
94
        auto_detect_bmp = False
×
95
        set_config("Machine", "version", version)
×
96

97
    print(f"talking to SpiNNaker system at {host}")
×
98
    return create_transceiver_from_hostname(
×
99
        host, bmp_connection_data=bmp_names,
100
        auto_detect_bmp=auto_detect_bmp)
101

102

103
def main(args):
1✔
104
    """
105
    Runs the script.
106
    """
107
    unittest_setup()
×
108
    ap = argparse.ArgumentParser(
×
109
        description="Check the state of a SpiNNaker machine.")
110
    ap.add_argument(
×
111
        "-a", "--appid", help="the application ID to check", type=int,
112
        default=17)
113
    ap.add_argument(
×
114
        "-v", "--version", help="the version of your boards", type=int,
115
        default=None)
116
    ap.add_argument(
×
117
        "-b", "--bmp_names",
118
        help="the hostname or IP address of the BMP of the SpiNNaker machine "
119
             "to inspects",
120
        type=str, default=None)
121
    ap.add_argument(
×
122
        "-n", "--noprintchips", action="store_true", default=False,
123
        help=("don't print all the chips out; avoids a great deal of "
124
              "output for large machines"))
125
    ap.add_argument(
×
126
        "host", default=None, nargs='?',
127
        help="the hostname or IP address of the SpiNNaker machine to inspect")
128
    args = ap.parse_args(args)
×
129
    # These ought to be parsed from command line arguments
130
    app_id = args.appid
×
131
    print_chips = not args.noprintchips
×
132

133
    transceiver = _make_transceiver(args.host, args.version, args.bmp_names)
×
134
    try:
×
135
        get_cores_in_run_state(transceiver, app_id, print_chips)
×
136
    finally:
137
        transceiver.close()
×
138

139

140
if __name__ == "__main__":  # pragma: no cover
1!
141
    main(sys.argv[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

© 2025 Coveralls, Inc