hydroflows.workflow.Rule#

class hydroflows.workflow.Rule(method: Method, workflow: Workflow, rule_id: str | None = None)[source]#

Bases: object

Rule class.

A rule is a wrapper around a method to be run in the context of a workflow. The rule is responsible for detecting wildcards and evaluating them based on the workflow wildcards. It creates method instances based on the wildcards and evaluates all input and output paths of the rule. The rule can be run and dryrun.

There is one common rule class to rule all methods.

Methods

dryrun

Dryrun the rule.

run

Run the rule.

to_dict

Return the rule as a dictionary.

Attributes

input

Return the input paths of the rule per field.

method_instances

Return a list of all method instances.

n_runs

Return the number of required method runs.

output

Return the output paths of the rule per field.

wildcard_fields

Return a wildcard - fieldname dictionary.

wildcards

Return the wildcards of the rule per wildcard type.

workflow

Return the workflow.

property workflow: Workflow#

Return the workflow.

property n_runs: int#

Return the number of required method runs.

property wildcards: Dict[str, List]#

Return the wildcards of the rule per wildcard type.

Wildcards are saved for three types, based on whether these “expand” (1:n), “reduce” (n:1) and “repeat” (n:n) the method.

property wildcard_fields: Dict[str, List]#

Return a wildcard - fieldname dictionary.

Per wildcard it contains all input, output and params field names which have the wildcard.

property method_instances: List[Method]#

Return a list of all method instances.

property input: Dict[str, list[Path]]#

Return the input paths of the rule per field.

property output: Dict[str, list[Path]]#

Return the output paths of the rule per field.

to_dict() Dict[source]#

Return the rule as a dictionary.

run(max_workers=1) None[source]#

Run the rule.

Parameters:

max_workers (int, optional) – The maximum number of workers to use, by default 1

dryrun(input_files: List[Path] | None = None, missing_file_error: bool = False) List[Path][source]#

Dryrun the rule.

Parameters:
  • input_files (List[Path], optional) – The input files to use for the dryrun, by default None

  • missing_file_error (bool, optional) – Whether to raise an error if a file is missing, by default False

Returns:

The output files of the dryrun.

Return type:

List[Path]