ComponentGrouping#
Module: iqm.cpc.core.config
- class iqm.cpc.core.config.ComponentGrouping(components, validate=True)#
Bases:
listUtility class for handling the
runargumentcomponents.ComponentGrouping is a list of one of the following types:
str(QPU component names)tuple[str, ...](component groups)list[tuple[str, ...]](group of parallelizable units, each such group can be executed in parallel).
All the normal list operations and comprehensions work with ComponentGrouping. In addition, the class provides utility methods such as flattening the structure and checking whether components or groups are found within it. The attribute
grouping_modecan be accessed to find out what kind of contents (one of the three above) the list contains.Methods
Checks if a component, a component group or a colour group is contained.
Copies the contents into a new instance.
Flattens the contents into a list of unique strings.
Limits the component groups by a list of component names or component groups while preserving the order.
Returns the contents as a JSON serializable format, using lists instead of tuples.
Returns the contents as a normal list.
- Parameters:
components (Components | None)
validate (bool)
- to_list()#
Returns the contents as a normal list.
- to_json_serializable()#
Returns the contents as a JSON serializable format, using lists instead of tuples.
- copy()#
Copies the contents into a new instance.
- flatten()#
Flattens the contents into a list of unique strings.
Any duplicate entries are removed such that only the first occurrence is kept. Otherwise the order is preserved.
- contains(elem)#
Checks if a component, a component group or a colour group is contained.
The behaviour depends on the self.grouping_mode and on the type of the searched element.
1. If self.grouping_mode == ComponentGroupingMode.LIST: - Search for a string returns True if the string is contained within. - Search for a group returns True if all the elements of the group are contained within. - Search for a colour group returns True if all the groups in it are contained within (similarly as above).
2. If self.grouping_mode == ComponentGroupingMode.GROUP: - Search for a string returns True if the string is contained within any of the groups. - Search for a group returns True if the group is contained within. - Search for a colour group returns True if all the groups in it are contained within.
3. If self.grouping_mode == ComponentGroupingMode.COLOUR_GROUP: - Search for a string returns True if the string is contained within any of the groups in the colour groups. - Search for a group returns True if the group is contained within any of the colour groups. - Search for a colour group returns True if the colour group is contained within.
- limit_by_components(component_list)#
Limits the component groups by a list of component names or component groups while preserving the order.
If self.grouping_mode == ComponentGroupingMode.LIST, and limiting by flat lists, will return a new ComponentGrouping such that all components not belonging to the given component_list are removed. Lists cannot be limited by groups, an error is thrown instead.
If self.grouping_mode == ComponentGroupingMode.GROUP or self.grouping_mode == ComponentGroupingMode.COLOUR_GROUP, and limiting with flat lists, will return a new ComponentGrouping such that all groups that are not subsets of the component_list are removed. If limiting by groups, will return only the groups that belong to the limiting groups. Completely emptied colour groups will be removed.
- Returns:
The limited component grouping.
- Raises:
ValueError – When trying to limit flat lists with groups.
- Parameters:
- Return type:
Inheritance
