pacman.utilities package

Subpackages

Submodules

pacman.utilities.constants module

class pacman.utilities.constants.EDGES(value)[source]

Bases: Enum

The 6 directions links can go.

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.iptag_resource_from_json(json_dict: Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]]) IPtagResource[source]

Creates an iptag from json

Parameters:

json_dict

Returns:

The iptag described by the json.

pacman.utilities.json_utils.iptag_resource_to_json(iptag: IPtagResource) Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][source]

Converts an iptag to json

Parameters:

iptag

Returns:

iptag in json forMAT

pacman.utilities.json_utils.iptag_resources_from_json(json_list: List[Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]]]) List[IPtagResource][source]

Creates a list of iptags from json.

Parameters:

json_list

Returns:

iptags described by the json

pacman.utilities.json_utils.iptag_resources_to_json(iptags: Iterable[IPtagResource]) List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][source]

Converts a list of iptags to json.

Parameters:

iptags

Returns:

json description of the iptags

pacman.utilities.json_utils.json_to_object(json_object: str | Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]]) Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][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_to_json(key_mask: BaseKeyAndMask) Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][source]

Converts a BaseKeyAndMask into json

Parameters:

key_mask

Returns:

key and mask in json format

pacman.utilities.json_utils.placement_from_json(json_dict: Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]]) Placement[source]
Parameters:

json_dict

Returns:

a Placement based on the json.

pacman.utilities.json_utils.placement_to_json(placement: Placement) Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][source]

Converts a Placement to json

Parameters:

placement

Returns:

json object describing the placement

pacman.utilities.json_utils.placements_to_json() List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][source]
Returns:

A json description of the placements (held in DataView)

pacman.utilities.json_utils.reverse_iptag_from_json(json_dict: Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]]) ReverseIPtagResource[source]

Creates a ReverseIPtagResource based on json

Parameters:

json_dict

Returns:

reverse iptags described by the json

pacman.utilities.json_utils.reverse_iptag_to_json(iptag: ReverseIPtagResource) Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][source]

Converts a reverse iptag to json

Parameters:

iptag

Returns:

json description of the reverse iptags

pacman.utilities.json_utils.reverse_iptags_from_json(json_list: List[Dict[str, int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]]]) List[ReverseIPtagResource][source]

Creates a list of ReverseIPtagResource from json

Parameters:

json_list

Returns:

reverse iptags described by the json

pacman.utilities.json_utils.reverse_iptags_to_json(iptags: Iterable[ReverseIPtagResource]) List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | List[int | float | str | None | JsonObject | JsonArray]] | List[int | float | str | None | Dict[str, int | float | str | None | JsonObject | JsonArray] | JsonArray]][source]

Converts a list of reverse iptags to json

Parameters:

iptags

Returns:

Json representation of the reverse iptags

pacman.utilities.utility_calls module

pacman.utilities.utility_calls.allocator_bits_needed(size: int) int[source]

Get the bits needed for the routing info allocator.

Parameters:

size – The size to calculate the number of bits for

Returns:

the number of bits required for that size

pacman.utilities.utility_calls.compress_bits_from_bit_array(bit_array: ndarray, bit_positions: ndarray) int[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 – The array to extract the value from

  • bit_positions – The positions of the bits to extract, each value being between 0 and 31

Returns:

integer value of the specified part bit array

pacman.utilities.utility_calls.compress_from_bit_array(bit_array: ndarray) int[source]

Compress a bit array of 32 uint8 values, where each is a 1 or 0, into a 32-bit value.

Parameters:

bit_array – The array to compress

Returns:

integer value of the whole bit array

pacman.utilities.utility_calls.expand_to_bit_array(value: int) ndarray[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 – The value to expand

Returns:

Bit array representing the value

pacman.utilities.utility_calls.get_key_ranges(key: int, mask: int) Iterable[Tuple[int, int]][source]

Get a generator of base_key, n_keys pairs that represent ranges allowed by the mask.

Parameters:
  • key – The base key

  • mask – The mask

Returns:

tuples of base_key, n_keys pairs

pacman.utilities.utility_calls.get_keys(base_key: int, vertex_slice: Slice, n_extra_bits: int = 0) ndarray[source]
Parameters:
  • base_key – The base key for the vertex slice

  • vertex_slice – The slice of the vertex to get keys for

  • n_extra_bits – Additional right shift to apply to atoms

Returns:

the keys for a given vertex slice.

pacman.utilities.utility_calls.get_n_bits(n_values: int) int[source]

Determine how many bits are required for the given number of values.

Parameters:

n_values – the number of values (starting at 0)

Returns:

the number of bits required to express that many values

pacman.utilities.utility_calls.is_equal_or_none(a: Any, b: Any) bool[source]

If a and b are both not None, return True if and only if they are equal, otherwise return True.

Returns:

True if either value is None or they are equal

pacman.utilities.utility_calls.is_power_of_2(v: int) bool[source]
Parameters:

v – The value to test

Returns:

True if the value is a power of 2.

pacman.utilities.utility_calls.is_single(iterable: Iterable[Any]) bool[source]
Returns:

True if there is exactly one item in the iterable.

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

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

Parameters:

string

Returns:

the hash key

Module contents