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.json_utils module

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.

Note: 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 – The constraint to describe
Returns:A dict describing the constraint
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 – Either a JSON Object or a string pointing to a file
Returns:a JSON object
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.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:
Returns:

Nothing is returned

Return type:

None

Raises:

pacman.exceptions.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 (numpy.array(uint8)) – The array to extract the value from
  • bit_positions (numpy.array(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 (numpy.array(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:numpy.array(uint8)
pacman.utilities.utility_calls.ident(object)[source]

Get the ID of the given 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

pacman.utilities.utility_calls.is_single(iterable)[source]

Test if there is exactly one item in the iterable

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

Locates all constraints of a given type out of a list

Parameters:
  • constraints (iterable(pacman.model.constraints.AbstractConstraint)) – The constraints to filter
  • constraint_type (pacman.model.constraints.partitioner_constraints.AbstractPartitionConstraint) – The type of constraints to return
Returns:

The constraints of constraint_type that are found in the constraints given

Return type:

iterable(pacman.model.constraints.AbstractConstraint)

Raises:

None – no known exceptions

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:
  • constraints (iterable(pacman.model.constraints.AbstractConstraint)) – The constraints to select from
  • constraint_type (pacman.model.constraints.partitioner_constraints.AbstractPartitionConstraint) – The type of constraints to return
Returns:

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

Return type:

pacman.model.constraints.AbstractConstraint

Raises:

pacman.exceptions.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.

Return type:str

pacman.utilities.vertex_sorter module

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

Bases: object

A constraint order definition for sorting.

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

property method for the constraint class

relative_order

property method for the relative order

required_optional_properties

property method for the required optional properties

class pacman.utilities.vertex_sorter.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 – The vertices to sort
Returns:The sorted list of vertices

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 – The class of the constraint
  • relative_order – The order of the constraint relative to other constraints to be sorted
  • required_optional_properties – Properties of the constraint instances that must not be None for the constraint to match this ordering
constraint_class

property method for the constraint class

relative_order

property method for the relative order

required_optional_properties

property method for the required optional properties

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 – The vertices to sort
Returns:The sorted list of vertices