spinnman.spalloc package

Module contents

The new Spalloc client implementation. This has the notable distinction of including a proxying system that allows creating a transceiver with access to the boards of a job despite the client being not within the same firewall/NAT security domain as the spalloc-managed service.

The main class in here is SpallocClient.

class spinnman.spalloc.AbstractSpallocClient[source]

Bases: object

The API exported by the Spalloc Client.

create_job(num_boards: int = 1, machine_name: str = None, keepalive: int = 45) → spinnman.spalloc.spalloc_job.SpallocJob[source]

Create a job with a specified number of boards.

Parameters:
  • num_boards (int) – How many boards to ask for (defaults to 1)
  • machine_name (str) – Which machine to run on? If omitted, the service’s machine tagged with default will be used.
  • keepalive (int) – After how many seconds of no activity should a job become eligible for automatic pruning?
Returns:

A handle for monitoring and interacting with the job.

Return type:

SpallocJob

create_job_board(triad: Tuple[int, int, int] = None, physical: Tuple[int, int, int] = None, ip_address: str = None, machine_name: str = None, keepalive: int = 45) → spinnman.spalloc.spalloc_job.SpallocJob[source]

Create a job with a specific board. At least one of triad, physical and ip_address must be not None.

Parameters:
  • triad (tuple(int,int,int)) – The logical coordinate of the board to request
  • physical (tuple(int,int,int)) – The physical coordinate of the board to request
  • ip_address (str) – The IP address of the board to request
  • machine_name (str) – Which machine to run on? If omitted, the service’s machine tagged with default will be used.
  • keepalive (int) – After how many seconds of no activity should a job become eligible for automatic pruning?
Returns:

A handle for monitoring and interacting with the job.

Return type:

SpallocJob

create_job_rect(width: int, height: int, machine_name: str = None, keepalive: int = 45) → spinnman.spalloc.spalloc_job.SpallocJob[source]

Create a job with a rectangle of boards.

Parameters:
  • width (int) – The width of rectangle to request
  • height (int) – The height of rectangle to request
  • machine_name (str) – Which machine to run on? If omitted, the service’s machine tagged with default will be used.
  • keepalive (int) – After how many seconds of no activity should a job become eligible for automatic pruning?
Returns:

A handle for monitoring and interacting with the job.

Return type:

SpallocJob

list_jobs(deleted: bool = False) → Iterable[spinnman.spalloc.spalloc_job.SpallocJob][source]

Get the jobs known to the server.

Parameters:deleted (bool) – Whether to include deleted jobs.
Returns:The jobs known to the server.
Return type:Iterable(SpallocJob)
list_machines() → Dict[str, spinnman.spalloc.spalloc_machine.SpallocMachine][source]

Get the machines supported by the server.

Returns:Mapping from machine names to handles for working with a machine.
Return type:dict(str,SpallocMachine)
spinnman.spalloc.is_server_address(address: str, additional_schemes: Iterable[str] = ()) → bool[source]

Test if the given address is a likely spalloc server URL.

Parameters:
  • address (str) – The address to check
  • additional_schemes (Iterable(str)) – Any additional URL schemes that should be considered to be successes; typically {"spalloc"} when looser matching is required.
Return type:

bool

class spinnman.spalloc.SpallocClient(service_url, username=None, password=None, bearer_token=None)[source]

Bases: spinn_utilities.abstract_context_manager.AbstractContextManager, spinnman.spalloc.abstract_spalloc_client.AbstractSpallocClient

Basic client library for talking to new Spalloc.

Parameters:
  • service_url (str) – The reference to the service. May have username and password supplied as part of the network location; if so, the username and password arguments must be None. If username and password are not given, not even within the URL, the bearer_token must be not None.
  • username (str) – The user name to use
  • password (str) – The password to use
  • bearer_token (str) – The bearer token to use
close()[source]

How to actually close the underlying resources.

create_job(num_boards=1, machine_name=None, keepalive=45)[source]

Create a job with a specified number of boards.

Parameters:
  • num_boards (int) – How many boards to ask for (defaults to 1)
  • machine_name (str) – Which machine to run on? If omitted, the service’s machine tagged with default will be used.
  • keepalive (int) – After how many seconds of no activity should a job become eligible for automatic pruning?
Returns:

A handle for monitoring and interacting with the job.

Return type:

SpallocJob

create_job_board(triad=None, physical=None, ip_address=None, machine_name=None, keepalive=45)[source]

Create a job with a specific board. At least one of triad, physical and ip_address must be not None.

Parameters:
  • triad (tuple(int,int,int)) – The logical coordinate of the board to request
  • physical (tuple(int,int,int)) – The physical coordinate of the board to request
  • ip_address (str) – The IP address of the board to request
  • machine_name (str) – Which machine to run on? If omitted, the service’s machine tagged with default will be used.
  • keepalive (int) – After how many seconds of no activity should a job become eligible for automatic pruning?
Returns:

A handle for monitoring and interacting with the job.

Return type:

SpallocJob

create_job_rect(width, height, machine_name=None, keepalive=45)[source]

Create a job with a rectangle of boards.

Parameters:
  • width (int) – The width of rectangle to request
  • height (int) – The height of rectangle to request
  • machine_name (str) – Which machine to run on? If omitted, the service’s machine tagged with default will be used.
  • keepalive (int) – After how many seconds of no activity should a job become eligible for automatic pruning?
Returns:

A handle for monitoring and interacting with the job.

Return type:

SpallocJob

list_jobs(deleted=False)[source]

Get the jobs known to the server.

Parameters:deleted (bool) – Whether to include deleted jobs.
Returns:The jobs known to the server.
Return type:Iterable(SpallocJob)
list_machines()[source]

Get the machines supported by the server.

Returns:Mapping from machine names to handles for working with a machine.
Return type:dict(str,SpallocMachine)
static open_job_from_database(conn: sqlite3.Cursor) → spinnman.spalloc.spalloc_job.SpallocJob[source]

Create a job from the description in the attached database. This is intended to allow for access to the job’s allocated resources from visualisers and other third party code participating in the Spinnaker Tools Notification Protocol.

Note

The job is not verified to exist and be running. The session credentials may have expired; if so, the job will be unable to regenerate them.

Parameters:conn (Cursor) – The database cursor to retrieve the job details from. Assumes the presence of a proxy_configuration table with kind, name and value columns.
Returns:The job handle, or None if the records in the database are absent or incomplete.
Return type:SpallocJob
version
class spinnman.spalloc.SpallocJob[source]

Bases: object

Represents a job in spalloc.

Don’t make this yourself. Use SpallocClient instead.

connect_for_booting() → spinnman.spalloc.spalloc_boot_connection.SpallocBootConnection[source]

Open a connection to a job’s allocation so it can be booted.

Returns:a boot connection
Return type:SpallocBootConnection
connect_to_board(x: int, y: int, port: int = 17893) → spinnman.spalloc.spalloc_scp_connection.SpallocSCPConnection[source]

Open a connection to a particular board in the job.

Parameters:
  • x (int) – X coordinate of the board’s ethernet chip
  • y (int) – Y coordinate of the board’s ethernet chip
  • port (int) – UDP port to talk to; defaults to the SCP port
Returns:

A connection that talks to the board.

Return type:

SpallocProxiedConnection

create_transceiver() → spinnman.transceiver.Transceiver[source]

Create a transceiver that will talk to this job. The transceiver will only be configured to talk to the SCP ports of the boards of the job.

Return type:Transceiver
destroy(reason: str = 'finished')[source]

Destroy the job.

Parameters:reason (str) – Why the job is being destroyed.
get_connections() → Dict[Tuple[int, int], str][source]

Get the mapping from board coordinates to IP addresses.

Returns:(x,y)->IP mapping, or None if not allocated
Return type:dict(tuple(int,int), str) or None
get_root_host() → str[source]

Get the IP address for talking to the machine.

Returns:The IP address, or None if not allocated.
Return type:str or None
get_state() → spinnman.spalloc.spalloc_state.SpallocState[source]

Get the current state of the machine.

Return type:SpallocState
keepalive()[source]

Signal the job that we want it to stay alive for a while longer.

launch_keepalive_task(period: int = 30) → spinn_utilities.abstract_context_manager.AbstractContextManager[source]

Starts a periodic task to keep a job alive.

Parameters:
  • job (SpallocJob) – The job to keep alive
  • period (int) – How often to send a keepalive message (in seconds)
Returns:

Some kind of closeable task handle; closing it terminates the task. Destroying the job will also terminate the task.

open_eieio_connection(x: int, y: int) → spinnman.spalloc.spalloc_eieio_connection.SpallocEIEIOConnection[source]

Open an EIEIO connection to a specific board in a job.

Parameters:
  • x (int) – The X coordinate of the ethernet chip to connect to
  • y (int) – The Y coordinate of the ethernet chip to connect to
Returns:

an EIEIO connection with a board address bound

Return type:

SpallocEIEIOConnection

open_listener_connection() → spinnman.spalloc.spalloc_eieio_listener.SpallocEIEIOListener[source]

Open a listening EIEIO connection to the job’s boards. Messages cannot be sent on this connection unless you say which board to send to, but they can be received from all boards. You can also get the server side connection information so you can program that into a tag.

Returns:an EIEIO connection with no board address bound
Return type:SpallocEIEIOListener
wait_for_state_change(old_state: spinnman.spalloc.spalloc_state.SpallocState) → spinnman.spalloc.spalloc_state.SpallocState[source]

Wait until the allocation is not in the given old state.

Parameters:old_state (SpallocState) – The state that we are looking to change out of.
Returns:The state that the allocation is now in.

Note

If the machine gets destroyed, this will not wait for it.

Return type:SpallocState
wait_until_ready()[source]

Wait until the allocation is in the READY state.

Raises:Exception – If the allocation is destroyed
where_is_machine(x: int, y: int) → Tuple[int, int, int][source]

Get the physical coordinates of the board hosting the given chip.

Parameters:
  • x (int) – Chip X coordinate
  • y (int) – Chip Y coordinate
Returns:

physical board coordinates (cabinet, frame, board), or None if there are no boards currently allocated to the job or the chip lies outside the allocation.

Return type:

tuple(int,int,int) or None

class spinnman.spalloc.SpallocMachine[source]

Bases: object

Represents a spalloc-controlled machine.

Don’t make this yourself. Use SpallocClient instead.

area

Area of machine, in boards.

Returns:width, height
Return type:tuple(int,int)
dead_boards

The dead or out-of-service boards of the machine.

The dead or out-of-service links of the machine.

height

The height of the machine, in boards.

name

The name of the machine.

tags

The tags of the machine.

width

The width of the machine, in boards.

class spinnman.spalloc.SpallocProxiedConnection[source]

Bases: spinnman.connections.abstract_classes.listenable.Listenable

Base class for connections proxied via Spalloc.

receive(timeout=None) → bytes[source]

Receive a message on an open socket. Will block until a message is received.

Parameters:timeout – How long to wait for a message to be received before timing out. If None, will wait indefinitely (or until the connection is closed).
Returns:The received message.
Raises:SpinnmanTimeoutException – If a timeout happens
send(data: bytes)[source]

Send a message on an open socket.

Parameters:data – The message to send.
class spinnman.spalloc.SpallocEIEIOConnection(local_host=None, local_port=None, remote_host=None, remote_port=None)[source]

Bases: spinnman.connections.udp_packet_connections.eieio_connection.EIEIOConnection, spinnman.spalloc.spalloc_proxied_connection.SpallocProxiedConnection

The socket interface supported by proxied EIEIO connected sockets. This emulates an EIEOConnection opened with a remote address specified.

Parameters:
  • local_host (str) – The local host name or IP address to bind to. If not specified defaults to bind to all interfaces, unless remote_host is specified, in which case binding is done to the IP address that will be used to send packets
  • local_port (int) – The local port to bind to, between 1025 and 65535. If not specified, defaults to a random unused local port
  • remote_host (str) – The remote host name or IP address to send packets to. If not specified, the socket will be available for listening only, and will throw and exception if used for sending
  • remote_port (int) – The remote port to send packets to. If remote_host is None, this is ignored. If remote_host is specified specified, this must also be specified for the connection to allow sending
Raises:

SpinnmanIOException – If there is an error setting up the communication channel

get_receive_method()[source]

Get the method that receives for this connection.

receive_eieio_message(timeout=None)[source]

Receives an EIEIO message from this connection. Blocks until a message has been received, or a timeout occurs.

Parameters:

timeout (int) – The time in seconds to wait for the message to arrive; if not specified, will wait forever, or until the connection is closed

Returns:

an EIEIO message

Return type:

AbstractEIEIOMessage

Raises:
send_eieio_message(eieio_message)[source]

Sends an EIEIO message down this connection.

Parameters:eieio_message (AbstractEIEIOMessage) – The EIEIO message to be sent
Raises:SpinnmanIOException – If there is an error sending the message
send_eieio_message_to_core(eieio_message: spinnman.messages.eieio.eieio_message.AbstractEIEIOMessage, x: int, y: int, p: int)[source]
update_tag(tag: int, do_receive: bool = True)[source]

Update the given tag on the connected ethernet chip to send messages to this connection.

Parameters:
  • tag (int) – The tag ID to update
  • do_receive (bool) – Whether to do the reception of the response or not
Raises:
class spinnman.spalloc.SpallocEIEIOListener(local_host=None, local_port=None, remote_host=None, remote_port=None)[source]

Bases: spinnman.connections.udp_packet_connections.eieio_connection.EIEIOConnection, spinnman.spalloc.spalloc_proxied_connection.SpallocProxiedConnection

The socket interface supported by proxied EIEIO listener sockets. This emulates an EIEOConnection opened with no address specified.

Parameters:
  • local_host (str) – The local host name or IP address to bind to. If not specified defaults to bind to all interfaces, unless remote_host is specified, in which case binding is done to the IP address that will be used to send packets
  • local_port (int) – The local port to bind to, between 1025 and 65535. If not specified, defaults to a random unused local port
  • remote_host (str) – The remote host name or IP address to send packets to. If not specified, the socket will be available for listening only, and will throw and exception if used for sending
  • remote_port (int) – The remote port to send packets to. If remote_host is None, this is ignored. If remote_host is specified specified, this must also be specified for the connection to allow sending
Raises:

SpinnmanIOException – If there is an error setting up the communication channel

get_receive_method()[source]

Get the method that receives for this connection.

local_ip_address

The IP address on the server to which the connection is bound.

Returns:The IP address as a dotted string, e.g., 0.0.0.0
Return type:str
local_port

The port on the server to which the connection is bound.

Returns:The local port number
Return type:int
receive_eieio_message(timeout=None)[source]

Receives an EIEIO message from this connection. Blocks until a message has been received, or a timeout occurs.

Parameters:

timeout (int) – The time in seconds to wait for the message to arrive; if not specified, will wait forever, or until the connection is closed

Returns:

an EIEIO message

Return type:

AbstractEIEIOMessage

Raises:
send(data)[source]

Send a message on an open socket.

Parameters:data – The message to send.

Note

This class does not allow sending.

send_eieio_message_to_core(eieio_message: spinnman.messages.eieio.eieio_message.AbstractEIEIOMessage, x: int, y: int, p: int, ip_address: str)[source]

Send an EIEIO message (one way) to a given core.

Parameters:
  • eieio_message (AbstractEIEIOMessage) – The message to send.
  • x (int) – The X coordinate of the core to send to.
  • y (int) – The Y coordinate of the core to send to.
  • p (int) – The ID of the core to send to.
  • ip_address (str) – The IP address of the ethernet chip to route the message via.
send_to(data: bytes, address: Tuple[str, int])[source]

Send a message on an open socket.

Parameters:
  • message (bytes) – The message to send.
  • address (tuple(str,int)) – Where to send it to. Must be the address of an ethernet chip on a board allocated to the job. Does not mean that SpiNNaker is listening on that port (but the SCP port is being listened to if the board is booted).
send_to_chip(message: bytes, x: int, y: int, port: int = 17893)[source]

Send a message on an open socket to a particular board.

Parameters:
  • message (bytes) – The message to send.
  • x (int) – The X coordinate of the ethernet chip to send the message to.
  • y (int) – The Y coordinate of the ethernet chip to send the message to.
  • port (int) – The UDP port on the ethernet chip to send the message to. Defaults to the SCP port.
update_tag(x: int, y: int, tag: int, do_receive: bool = True)[source]

Update the given tag on the given ethernet chip to send messages to this connection.

Parameters:
  • x (int) – The ethernet chip’s X coordinate
  • y (int) – The ethernet chip’s Y coordinate
  • tag (int) – The tag ID to update
  • do_receive (bool) – Whether to receive the response or not
Raises:
update_tag_by_ip(ip_address: str, tag: int)[source]

Update a tag on a board at a given IP address to send messages to this connection.

Parameters:
  • ip_address (str) – The address of the ethernet chip
  • tag (int) – The ID of the tag
class spinnman.spalloc.SpallocState[source]

Bases: enum.IntEnum

The possible states of a Spalloc Job.

Jobs start as QUEUED, then move to POWER once they’ve been allocated. Once the job’s boards have been switched on and the hardware stabilised, the job moves to state READY. (It goes back to POWER if you tell it to switch off or on; this is not recommended.) Finally, it goes to DESTROYED once the job is completed in any way.

The UNKNOWN state is used when something odd is going on. It should normally be ignored.

DESTROYED = 4

The job has been destroyed.

POWER = 2

The job is queued waiting for boards to power on or off.

QUEUED = 1

The job is queued waiting for allocation.

READY = 3

The job is ready for user code to run on it.

UNKNOWN = 0

The job is in an unknown state.