pacman.utilities package

Submodules

pacman.utilities.constants module

class pacman.utilities.constants.EDGES

Bases: enum.Enum

An enumeration.

EAST = 0
NORTH = 2
NORTH_EAST = 1
SOUTH = 5
SOUTH_WEST = 4
WEST = 3
pacman.utilities.constants.SARK_PER_MALLOC_SDRAM_USAGE = 8

The number of bytes used by SARK per memory allocation

pacman.utilities.json_utils module

Miscellaneous minor functions for converting between JSON and Python objects.

pacman.utilities.json_utils.constraint_from_json(json_dict, graph=None)[source]
pacman.utilities.json_utils.constraint_to_json(constraint)[source]

Converts a constraint to JSON.

Note

Vertexes are represented by just their label.

If an unexpected constraint is received, the str() and repr() values are saved

If an Exception occurs, that is caught and added to the JSON object.

Parameters:constraint (AbstractConstraint) – The constraint to describe
Returns:A dict describing the constraint
Return type:dict
pacman.utilities.json_utils.constraints_from_json(json_list, graph)[source]
pacman.utilities.json_utils.constraints_to_json(constraints)[source]
pacman.utilities.json_utils.edge_from_json(json_dict, graph=None)[source]
pacman.utilities.json_utils.edge_to_json(edge)[source]
pacman.utilities.json_utils.graph_from_json(json_dict)[source]
pacman.utilities.json_utils.graph_to_json(graph)[source]
pacman.utilities.json_utils.iptag_resource_from_json(json_dict)[source]
pacman.utilities.json_utils.iptag_resource_to_json(iptag)[source]
pacman.utilities.json_utils.iptag_resources_from_json(json_list)[source]
pacman.utilities.json_utils.iptag_resources_to_json(iptags)[source]
pacman.utilities.json_utils.json_to_object(json_object)[source]

Makes sure this is a JSON object reading in a file if required

Parameters:json_object (dict or list or str) – Either a JSON Object or a string pointing to a file
Returns:a JSON object
Return type:dict or list
pacman.utilities.json_utils.key_mask_from_json(json_dict)[source]
pacman.utilities.json_utils.key_mask_to_json(key_mask)[source]
pacman.utilities.json_utils.key_masks_from_json(json_list)[source]
pacman.utilities.json_utils.key_masks_to_json(key_masks)[source]
pacman.utilities.json_utils.partition_to_n_keys_map_to_json(partition_to_n_keys_map)[source]
pacman.utilities.json_utils.placement_from_json(json_dict, graph=None)[source]
pacman.utilities.json_utils.placement_to_json(placement)[source]
pacman.utilities.json_utils.placements_to_json(placements)[source]
pacman.utilities.json_utils.resource_container_from_json(json_dict)[source]
pacman.utilities.json_utils.resource_container_to_json(container)[source]
pacman.utilities.json_utils.vertex_add_contstraints_from_json(json_dict, graph)[source]
pacman.utilities.json_utils.vertex_from_json(json_dict, convert_constraints=True)[source]
pacman.utilities.json_utils.vertex_lookup(label, graph=None)[source]
pacman.utilities.json_utils.vertex_to_json(vertex)[source]

pacman.utilities.utility_calls module

pacman.utilities.utility_calls.check_algorithm_can_support_constraints(constrained_vertices, supported_constraints, abstract_constraint_type)[source]
Helper method to find out if an algorithm can support all the
constraints given the objects its expected to work on
Parameters:
Raises:

PacmanInvalidParameterException – When the algorithm cannot support the constraints demanded of it

pacman.utilities.utility_calls.check_constrained_value(value, current_value)[source]

Checks that the current value and a new value match

Parameters:
  • value – The value to check
  • current_value – The existing value
pacman.utilities.utility_calls.compress_bits_from_bit_array(bit_array, bit_positions)[source]

Compress specific positions from a bit array of 32 uint8 value, where is a 1 or 0, into a 32-bit value.

Parameters:
  • bit_array (ndarray(uint8)) – The array to extract the value from
  • bit_positions (ndarray(int)) – The positions of the bits to extract, each value being between 0 and 31
Return type:

int

pacman.utilities.utility_calls.compress_from_bit_array(bit_array)[source]
Compress a bit array of 32 uint8 values, where each is a 1 or 0,
into a 32-bit value
Parameters:bit_array (ndarray(uint8)) – The array to compress
Return type:int
pacman.utilities.utility_calls.expand_to_bit_array(value)[source]
Expand a 32-bit value in to an array of length 32 of uint8 values,
each of which is a 1 or 0
Parameters:value (int) – The value to expand
Return type:ndarray(uint8)
pacman.utilities.utility_calls.get_key_ranges(key, mask)[source]
Get a generator of base_key, n_keys pairs that represent ranges
allowed by the mask.
Parameters:
  • key (int) – The base key
  • mask (int) – The mask
Return type:

iterable(tuple(int,int))

pacman.utilities.utility_calls.ident(object)[source]

Get the ID of the given object.

Parameters:object (object) –
Return type:str
pacman.utilities.utility_calls.is_equal_or_None(a, b)[source]

If a and b are both not None, return True iff they are equal, otherwise return True

Return type:bool
pacman.utilities.utility_calls.is_single(iterable)[source]

Test if there is exactly one item in the iterable

Return type:bool
pacman.utilities.utility_calls.locate_constraints_of_type(constraints, constraint_type)[source]

Locates all constraints of a given type out of a list

Parameters:
Returns:

The constraints of constraint_type that are found in the constraints given

Return type:

iterable(AbstractConstraint)

pacman.utilities.utility_calls.locate_first_constraint_of_type(constraints, constraint_type)[source]

Locates the first constraint of a given type out of a list

Parameters:
Returns:

The first constraint of constraint_type that was found in the constraints given

Return type:

AbstractConstraint

Raises:

PacmanInvalidParameterException – If no such constraint is present

pacman.utilities.utility_calls.md5(string)[source]

Get the MD5 hash of the given string, which is UTF-8 encoded.

Parameters:string (str) –
Return type:str

Module contents

class pacman.utilities.ConstraintOrder(constraint_class, relative_order, required_optional_properties=None)[source]

Bases: object

A constraint order definition for sorting.

Parameters:
  • constraint_class (type) – The class of the constraint
  • relative_order (int) – The order of the constraint relative to other constraints to be sorted
  • required_optional_properties (list(str) or None) – Properties of the constraint instances that must not be None for the constraint to match this ordering
constraint_class

the constraint class

Return type:type
relative_order

the relative order

Return type:int
required_optional_properties

the required optional properties

Return type:list(str) or None
class pacman.utilities.VertexSorter(constraint_order)[source]

Bases: object

Sorts vertices based on constraints with given criteria.

Parameters:constraint_order (list(ConstraintOrder)) – The order in which the constraints are to be sorted
sort(vertices)[source]

Sort the given set of vertices by the constraint ordering

Parameters:vertices (list(AbstractVertex)) – The vertices to sort
Returns:The sorted list of vertices
Return type:list(AbstractVertex)