Resource Manager

This module implements resource management in the MCCS subsystem.

class HealthfulReadyResourceManager(allocatees, healthful_resource_types, *args, **resources)

A resource manager that manages both allocatee readiness and resource health.

class ResourceManager(allocatees, **resources)

A generic resource manager / tracker.

This resource manager treats resources as abstract concepts that can be allocated to and deallocated from abstract allocatees.

__init__(allocatees, **resources)

Initialise a new instance.

Parameters:
  • allocatees (Iterable[Hashable]) – targets for allocation of resources.

  • resources (Iterable[Hashable]) –

    keyword args, with each keyword being the name of a resource type, and the value being the set of resources of that type managed by this resource manager. For example, to allocate toys, tools and treasure to boxes:

    resource_manager = _ResourceManager(
        boxes,
        toys={"teddybears", "lego"},
        tools={"hammers", "saws", "drills"}
        treasure={"diamonds", "rubies", "coins"},
    }
    

    The resource types will be maintained as separate namespaces, so you can re-use a resource marker across different types. For example, no problem using the number 2 twice in this example:

    resource_manager = _ResourceManager(
        subarrays,
        station_ids={1, 2},
        channel_blocks={2, 3}
    }
    

_validate_allocatee(allocatee)

Check that the allocatee provided is known to this resource manager.

Parameters:

allocatee (Hashable) – the allocatee to check

Raises:

ValueError – if the allocatee is not known to this resource manager

Return type:

None

_validate_allocation(allocatee, **resources)

Check that the specified resources can be allocated to the specified allocatee.

This method assumes that the resources and allocatee have been validated.

Parameters:
Raises:

ValueError – if the resources are not available to be allocated to the allocatee

Return type:

None

_validate_resources(**resources)

Check that the resources provided are managed by this resource manager.

Parameters:

resources (Iterable[Hashable]) – the resources to check

Raises:

ValueError – if any resources are not managed by this resource manager

Return type:

None

allocate(allocatee, **resources)

Allocate resources to an allocatee.

Parameters:
  • allocatee (Hashable) – the allocatee to which resources are to be allocated

  • resources (Iterable[Hashable]) –

    the resources to allocate. Each keyword specifies a resource type, with the value a list of the resources of that type to be allocated. For example:

    resource_manager.allocate(
        "box_1",
        toys={"lego"},
        tools={"hammers", "saws"}
    }
    

Return type:

None

deallocate(**resources)

Deallocate resources.

Parameters:

resources (Iterable[Hashable]) –

the resources to deallocate. Each keyword specifies a resource type, with the value a list of the resources of that type to be allocated. For example:

resource_manager.deallocate(
    toys={"lego"},
    tools={"hammers", "saws"}
}

Return type:

None

deallocate_from(allocatee)

Deallocate all resources from an allocatee.

Parameters:

allocatee (Hashable) – the allocatee to which resources are to be allocated

Return type:

None

get_allocated(allocatee)

Get all allocated resources in resource manager.

Parameters:

allocatee (Hashable) – The device to which the returned resources are allocated

Return type:

Mapping[str, Iterable[Hashable]]

Returns:

The resources allocated to the allocatee, with their type as the keys

get_unallocated()

Get all unallocated resources in resource manager.

Return type:

Mapping[str, Iterable[Hashable]]

Returns:

The unallocated resources, with their type as the keys

class ResourcePool(**resources)

A manager for a finite pool of resources.

The manager can be queried to get a free resource, which then marks the resource as allocated/locked and prevents it being returned again until it is freed.

__init__(**resources)

Initialise a pool of resources.

Parameters:

resources (Iterable[Hashable]) – the resources to be managed in this pool

Sets all resources as free (allocatable).

free_all_resources(resource_type=None)

Free all resources in this Resource Pool.

Parameters:

resource_type (Optional[str]) – the resource type of which all instances are to be freed.

Return type:

None

free_resources(resources)

Mark a resource as unallocated.

Parameters:

resources (Mapping[str, Iterable[Hashable]]) – the resources to free.

Raises:

ValueError – if resource does not exist in the pool.

Return type:

None

get_free_resource(resource_type)

Get a free (unallocated) resource from the pool.

Parameters:

resource_type (Hashable) – the type of resource

Raises:

ValueError – if there a no free resources.

Return type:

Hashable

Returns:

A free resource of the requested type