# pacman.model.graphs package¶

## Module contents¶

class pacman.model.graphs.AbstractEdge[source]

Bases: object

A directed edge in a graph between two vertices.

label

The label of the edge

Return type: str
post_vertex

The vertex at the end of the edge

Return type: AbstractVertex
pre_vertex

The vertex at the start of the edge

Return type: AbstractVertex
class pacman.model.graphs.AbstractEdgePartition(identifier, allowed_edge_types, constraints, label, traffic_weight, class_name)[source]

Bases: pacman.model.graphs.common.constrained_object.ConstrainedObject

A collection of edges which start at a single vertex which have the same semantics and so can share a single key or block of SDRAM (depending on edge type).

Parameters: identifier (str) – The identifier of the partition allowed_edge_types (type or tuple(type, ..)) – The types of edges allowed constraints (iterable(AbstractConstraint)) – Any initial constraints label (str) – An optional label of the partition traffic_weight (int) – The weight of traffic going down this partition
add_edge(edge, graph_code)[source]

Add an edge to the edge partition.

Note

This method should only be called by the add_edge method of the graph that owns the partition. Calling it from anywhere else, even with the correct graph_code, will lead to unsupported inconsistency.

Parameters: edge (AbstractEdge) – the edge to add graph_code (int) – A code to check the correct graph is calling this method PacmanInvalidParameterException – If the edge does not belong in this edge partition
clone_without_edges()[source]

Make a copy of this edge partition without any of the edges in it

This follows the design pattern that only the graph adds edges to partitions already added to the graph

Returns: The copied edge partition but excluding edges
edges

The edges in this edge partition.

Note

The order in which the edges are added is preserved for when they are requested later. If not, please talk to the software team.

Return type: iterable(AbstractEdge)
identifier

The identifier of this edge partition.

Return type: str
label

The label of the edge partition.

Return type: str
n_edges

The number of edges in the edge partition.

Return type: int
pre_vertices

Provides the vertices associated with this partition

Note

Most edge partitions will be AbstractSingleSourcePartition and therefore provide the pre_vertex method.

Return type: iter(AbstractVertex)
register_graph_code(graph_code)[source]

Allows the graph to register its code when the partition is added

traffic_weight

The weight of the traffic in this edge partition compared to other partitions.

Return type: int
class pacman.model.graphs.AbstractFPGA[source]

Bases: pacman.model.graphs.abstract_virtual.AbstractVirtual

A vertex connected to an FPGA.

Note

Everything that is an instance of AbstractFPGA is also an instance of AbstractVertex.

fpga_id

The ID of the FPGA to which the vertex is connected.

Return type: int

The link of the FPGA to which the vertex is connected.

Return type: int
class pacman.model.graphs.AbstractMultiplePartition(pre_vertices, identifier, allowed_edge_types, constraints, label, traffic_weight, class_name)[source]

Bases: pacman.model.graphs.abstract_edge_partition.AbstractEdgePartition

An edge partition that has multiple source vertices.

add_edge(edge, graph_code)[source]

Add an edge to the edge partition.

Note

This method should only be called by the add_edge method of the graph that owns the partition. Calling it from anywhere else, even with the correct graph_code, will lead to unsupported inconsistency.

Parameters: edge (AbstractEdge) – the edge to add graph_code (int) – A code to check the correct graph is calling this method PacmanInvalidParameterException – If the edge does not belong in this edge partition
pre_vertices

Provides the vertices associated with this partition

Note

Most edge partitions will be AbstractSingleSourcePartition and therefore provide the pre_vertex method.

Return type: iter(AbstractVertex)
class pacman.model.graphs.AbstractSingleSourcePartition(pre_vertex, identifier, allowed_edge_types, constraints, label, traffic_weight, class_name)[source]

Bases: pacman.model.graphs.abstract_edge_partition.AbstractEdgePartition

An edge partition that has a single source vertex.

add_edge(edge, graph_code)[source]

Add an edge to the edge partition.

Note

This method should only be called by the add_edge method of the graph that owns the partition. Calling it from anywhere else, even with the correct graph_code, will lead to unsupported inconsistency.

Parameters: edge (AbstractEdge) – the edge to add graph_code (int) – A code to check the correct graph is calling this method PacmanInvalidParameterException – If the edge does not belong in this edge partition
pre_vertex

The vertex at which all edges in this outgoing edge partition start.

Return type: AbstractVertex
pre_vertices

Provides the vertices associated with this partition

Note

Most edge partitions will be AbstractSingleSourcePartition and therefore provide the pre_vertex method.

Return type: iter(AbstractVertex)

Bases: pacman.model.graphs.abstract_virtual.AbstractVirtual

An Object (most likely a vertex) connected to a SpiNNaker Link.

Note

It is expected that everything that is an instance of AbstractSpiNNakerLink is also an instance of AbstractVertex. This is not enforced to avoid diamond inheritance.

The SpiNNaker Link that the vertex is connected to.

Return type: int
class pacman.model.graphs.AbstractSupportsSDRAMEdges[source]

Bases: object

Marks a machine vertex that can have SDRAM edges attached to it.

sdram_requirement(sdram_machine_edge)[source]

Asks a machine vertex for the sdram requirement it needs.

Parameters: sdram_machine_edge – The SDRAM edge in question the size in bytes this vertex needs for the SDRAM edge int (most likely a multiple of 4)
class pacman.model.graphs.AbstractVertex(label=None, constraints=None)[source]

Bases: pacman.model.graphs.common.constrained_object.ConstrainedObject

A vertex in a graph.

Parameters: label (str) – The optional name of the vertex constraints (iterable(AbstractConstraint)) – The optional initial constraints of the vertex PacmanInvalidParameterException – If one of the constraints is not valid
addedToGraph()[source]

Records that the vertex has been added to a graph

Raises: PacmanConfigurationException – If there is an attempt to add the same vertex more than once
label

The current label to the vertex.

This label could change when the vertex is added to the graph.

Return type: str
set_label(label)[source]

Changes the label for a vertex not yet added to a graph.

Parameters: label (str) – new value for the label PacmanConfigurationException – If there is an attempt to change the label once the vertex has been added to a graph
class pacman.model.graphs.AbstractVirtual[source]

Bases: object

A vertex which exists outside of the machine, allowing a graph to formally participate in I/O.

Note

Everything that is an instance of AbstractVirtual is also an instance of AbstractVertex.

board_address

The IP address of the board to which the device is connected, or None for the boot board.

Return type: str
set_virtual_chip_coordinates(virtual_chip_x, virtual_chip_y)[source]

Set the details of the virtual chip that has been added to the machine for this vertex.

Parameters: virtual_chip_x (int) – The x-coordinate of the added chip virtual_chip_y (int) – The y-coordinate of the added chip
virtual_chip_x

The x-coordinate of the virtual chip where this vertex is to be placed.

Return type: int
virtual_chip_y

The y-coordinate of the virtual chip where this vertex is to be placed.

Return type: int
class pacman.model.graphs.Graph(allowed_vertex_types, allowed_edge_types, label)[source]

Bases: pacman.model.graphs.common.constrained_object.ConstrainedObject

A graph that specifies the allowed types of the vertices and edges.

Parameters: allowed_vertex_types (type or tuple(type, ..)) – A single or tuple of types of vertex to be allowed in the graph allowed_edge_types (type or tuple(type, ..)) – A single or tuple of types of edges to be allowed in the graph label (str or None) – The label on the graph, or None
add_edge(edge, outgoing_edge_partition_name)[source]

Add an edge to the graph and its partition

If required and possible will create a new partition in the graph

Returns the partition the edge was added to

Parameters: edge (AbstractEdge) – The edge to add outgoing_edge_partition_name (str) – The name of the edge partition to add the edge to; each edge partition is the partition of edges that start at the same vertex AbstractEdgePartition PacmanInvalidParameterException – If the edge is not of a valid type or if edges have already been added to this partition that start at a different vertex to this one
add_edges(edges, outgoing_edge_partition_name)[source]

Add a collection of edges to the graph.

Parameters: edges (iterable(AbstractEdge)) – The edges to add outgoing_edge_partition_name (str) – The name of the edge partition to add the edges to; each edge partition is the partition of edges that start at the same vertex PacmanInvalidParameterException – If any edge is not of a valid type or if edges have already been added to this partition that start at a different vertex to this one
add_outgoing_edge_partition(edge_partition)[source]

Add an edge partition to the graph.

Parameters: edge_partition (AbstractEdgePartition) – The edge partition to add PacmanAlreadyExistsException – If a partition already exists with the same pre_vertex and identifier
add_vertex(vertex)[source]

Add a vertex to the graph.

Parameters: vertex (AbstractVertex) – The vertex to add PacmanInvalidParameterException – If the vertex is not of a valid type PacmanConfigurationException – If there is an attempt to add the same vertex more than once
add_vertices(vertices)[source]

Add a collection of vertices to the graph.

Parameters: vertices (iterable(AbstractVertex)) – The vertices to add PacmanInvalidParameterException – If any vertex is not of a valid type PacmanConfigurationException – If there is an attempt to add the same vertex more than once
edges

The edges in the graph

Return type: iterable(AbstractEdge)
get_edges_ending_at_vertex(vertex)[source]

Get all the edges that end at the given vertex.

Parameters: vertex (AbstractVertex) – The vertex at which the edges to get end iterable(AbstractEdge)
get_edges_ending_at_vertex_with_partition_name(vertex, partition_name)[source]

Get all the edges that end at the given vertex, and reside in the correct partition ID.

Parameters: vertex (AbstractVertex) – The vertex at which the edges to get end partition_name (str) – the label for the partition iterable(AbstractEdge)
get_edges_starting_at_vertex(vertex)[source]

Get all the edges that start at the given vertex.

Parameters: vertex (AbstractVertex) – The vertex at which the edges to get start iterable(AbstractEdge)
get_outgoing_edge_partition_starting_at_vertex(vertex, outgoing_edge_partition_name)[source]
Get the given outgoing edge partition that starts at the
given vertex, or None if no such edge partition exists.
Parameters: vertex (AbstractVertex) – The vertex at the start of the edges in the partition outgoing_edge_partition_name (str) – The name of the edge partition the named edge partition, or None if no such partition exists
get_outgoing_edge_partitions_starting_at_vertex(vertex)[source]

Get all the edge partitions that start at the given vertex.

Parameters: vertex (AbstractVertex) – The vertex at which the edge partitions to find starts iterable(AbstractEdgePartition)
get_outgoing_partition_for_edge(edge)[source]

Gets the partition this edge is associated with.

Parameters: edge (AbstractEdge) – the edge to find associated partition AbstractEdgePartition
label

The label of the graph.

Return type: str
n_outgoing_edge_partitions

The number of outgoing edge partitions in the graph.

Return type: int
n_vertices

The number of vertices in the graph.

Return type: int
new_edge_partition(name, edge)[source]

How we create a new AbstractSingleSourcePartition in the first place. Uses the first/only element in the allowed partition types argument to the graph’s constructor.

Called from add_edge(). Can be overridden if different arguments should be passed.

Parameters: name (str) – The identifier of the partition edge (AbstractEdge) – An edge for the partition the new edge partition AbstractSingleSourcePartition
outgoing_edge_partitions

The edge partitions in the graph.

Return type: iterable(AbstractEdgePartition)
vertex_by_label(label)[source]
vertices

The vertices in the graph.

Return type: iterable(AbstractVertex)