Source code for spinnman.spinnman_script
# Copyright (c) 2025 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
from spinn_machine import Machine
from spinnman.transceiver import Transceiver
from spinnman.spinnman_simulation import SpiNNManSimulation
__simulator: Optional[SpiNNManSimulation] = None
[docs]
def setup(n_boards_required: Optional[int] = None,
n_chips_required: Optional[int] = None) -> None:
"""
The main method similar to PyNN setup.
Needs to be called before any other function
:param n_chips_required:
Deprecated! Use n_boards_required instead.
Must be `None` if n_boards_required specified.
:param n_boards_required:
if you need to be allocated a machine (for spalloc) before building
your graph, then fill this in with a general idea of the number of
boards you need so that the spalloc system can allocate you a machine
big enough for your needs.
"""
# pylint: disable=global-statement
global __simulator
if __simulator is not None:
raise RuntimeError("Setup can only be called once")
__simulator = SpiNNManSimulation(n_boards_required, n_chips_required)
[docs]
def get_machine() -> Machine:
"""
Gets the Machine creating it if needed
Will call get_transceiver(ensure_board_is_ready = True)
:returns: Machine object
"""
assert __simulator is not None
return __simulator.get_machine()
[docs]
def get_transceiver(ensure_board_is_ready: bool = True) -> Transceiver:
"""
Gets the Transceiver creating it if needed
:param ensure_board_is_ready:
:return:
"""
assert __simulator is not None
# pylint: disable=protected-access
return __simulator._get_transceiver(
ensure_board_is_ready=ensure_board_is_ready)
[docs]
def end() -> None:
"""
Cleans up the machine, transceiver and spalloc objects
"""
# pylint: disable=global-statement,protected-access
global __simulator
if __simulator is not None:
__simulator._shutdown()
__simulator = None