cpalgnodes.algnode module
- class cpalgnodes.algnode.AlgNode(type: str, name: str, priority: int = 0, inputs: Dict[str, str] | None = None, outputs: Dict[str, str] | None = None, **properties)
-
Node that has one (main) algorithm
Dictionary access is used to gain access to the algorithm’s properties
- add_input(property: str, nickname: str)
Add a new input container to the algorithm
- Parameters:
property (str) – The name of the property to which the input should be provided
nickname (str) – The (nick)name of the container which should be provided
- add_output(property: str, nickname: str)
Add a new output container to the algorithm
- Parameters:
property (str) – The name of the property to which the output should be provided
nickname (str) – The (nick)name of the container which should be provided
- add_selection(property: str, selection: str | Expression, input_property: str | None = None, is_preselection: bool = False)
Add a new selection to this algorithm
- Parameters:
property (str) – The name of the property to which the selection should be provided
selection (Union[str, boolean.Expression]) – The selection
input_property (str, optional) – The name of the property on which the input container is set, by default None. Can be omitted if the algorithm has only one input
is_preselection (bool) – If the property is a preselection. In this case the set value will be or’ed with the value provided by the scheduler
- create(container_info: Mapping[str, ContainerInfo]) Algorithm
Create the algorithm(s) represented by this node
- Parameters:
container_info (Mapping[str, ContainerInfo]) – The ContainerInfo for each input/output container
- Returns:
The configured algorithm(s)
- Return type:
Union[Algorithm, List[Algorithm], ConfigFragment]
- classmethod create_unique_name(pattern: str) str
Create a unique name for an algorithm
An example pattern string would be MyAlgNode_{index}
- Parameters:
pattern (str) – The format string to use. Should accept an ‘index’ key
- input_nickname(property: str | None = None) str
Get the container nickname for the specified input to this algorithm
- Parameters:
property (str, optional) – The property under which the input will be stored. If there is only one input to this algorithm it may be omitted.
- Raises:
KeyError – The specified property is not an input or no property is specified where the number of inputs does not equal 1.
- Returns:
The nickname of the container to be supplied to that input property
- Return type:
str
- property name
The name of this node
- output_nickname(property: str | None = None) str
Get the container nickname for the specified output to this algorithm
- Parameters:
property (str, optional) – The property under which the output will be stored. If there is only one output to this algorithm it may be omitted.
- Raises:
KeyError – The specified property is not an output or no property is specified where the number of inputs does not equal 1.
- Returns:
The nickname of the container to be supplied to that output property
- Return type:
str
- property priority
The priority of this node - higher priority nodes will be placed first
- property produces_containers: Dict[str, str | None]
Any containers created by this node
Containers are returned as a dictionary mapping from the created container nickname to its parent container (or None otherwise). A container has a parent if it is a deep copy, shallow copy or view. Where a node updates a container it should have itself as the parent.
- property requires_aux: Dict[str, Set[str]]
The auxdata required by this node, split by container
- Return type:
A dictionary mapping container nicknames to the set of auxnames the node requires
- requires_objects(required_output: Dict[Tuple[str, str | None], Expression]) Dict[Tuple[str, str | None], Expression]
The input objects that this algorithm needs
Part of the preselection mechanism. This method allows each node to tell the scheduler which objects upstream nodes need to have run for this node to produce the data required by downstream node.
For example, in the most simple case (which this default implementation satisfies) the node calculates object-by-object so the node only needs to see the objects on which its output is required.
- Parameters:
required_output (Dict[Dependency, boolean.Expression]) – The selections required downstream of this node on its outputs
- Return type:
The selections this node requires on its inputs
- class cpalgnodes.algnode.SimpleAlgNode(type: str, name: str, container_property: str, container: str, container_out_property: str | None = None, container_out: str | None = None, preselection_property: str | None = 'preselection', preselection: str | Expression = FALSE, priority: int = 0, requires_aux: Set[str | Callable[[SimpleAlgNode], str | Iterable[str]]] | None = None, produces_aux: Set[str | Callable[[SimpleAlgNode], str | Iterable[str]]] | None = None, **properties)
Bases:
AlgNodeSimple algorithm class to handle most cases
This class handles the case where there is one obvious ‘main’ input container and (optionally) one main output container. This fulfils the vast majority of use cases for the CP algorithms.
- property input_container
The nickname of the input container
- property output_container
The nickname of the output container
Returns None if this node has no output container
- property preselection: Expression
The preselection (if any) to this algorithm
- property produces_aux: Dict[str, Set[str]]
The auxdata produced by this node, split by container
- Return type:
A dictionary mapping container nicknames to the set of auxnames the node produces
- property produces_containers: Dict[str, str | None]
Any containers created by this node
Containers are returned as a dictionary mapping from the created container nickname to its parent container (or None otherwise). A container has a parent if it is a deep copy, shallow copy or view. Where a node updates a container it should have itself as the parent.
- property requires_aux: Dict[str, Set[str]]
The auxdata required by this node, split by container
- Return type:
A dictionary mapping container nicknames to the set of auxnames the node requires