init
core ¶
summary.
__all__ = ['CoSyLuigiRepo', 'CoSyLuigiTask', 'CoSyLuigiTaskParameter'] module-attribute ¶
CoSyLuigiRepo ¶
Serves as the repository that Combinatory Logic Synthesis requires for type inhabitation. Unlike the previous version of CoSy-Luigi, known as CLS-Luigi, having an explicit repository prevents side-effects that may occur by collecting all CoSyLuigiTasks via reflection. Another important task of the CoSyLuigiRepo is to translate the observed class hierarchy into a taxonomy that the CoSy framework understands during synthesis.
Attributes:
| Name | Type | Description |
|---|---|---|
luigi_repo | set[type[CoSyLuigiTask]] | The set of CoSyLuigiTask types that constitute the repositories' combinators. |
taxonomy | Mapping[str, set[str]] | The taxonomy that describes the class hierarchy of the luigi_repo. |
cls_repo | list[tuple[str, Callable, Specification]] | The final repository that can be passed to the CoSy framework. |
Source code in src/cosy_luigi/core/combinatorics.py
cls_repo: list[tuple[str, Callable, Specification]] = [] instance-attribute ¶
luigi_repo: set[type[CoSyLuigiTask]] = set(flatten(*tasks)) instance-attribute ¶
taxonomy: Mapping[str, set[str]] = defaultdict(set) instance-attribute ¶
__init__(*tasks: type[CoSyLuigiTask] | Sequence[type[CoSyLuigiTask]]) ¶
Initializes the CoSyLuigiRepo. The passed arbitrarily nested Sequence is flattened and converted into a set. Please see the documentation of flatten, as it adds some features to the flattening. The taxonomy is then computed by examining the method resolution order of each CoSyLuigiTask type, up to the most abstract possible CoSyLuigiTask itself.
Also performs rudimentary inspection of the repositories' contents, currently only checks if any set unique_in_prior_tasks flags make logical sense.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*tasks | type[CoSyLuigiTask] | Sequence[type[CoSyLuigiTask]] | An arbitrarily nested Sequence where leaves are CoSyLuigiTasks' types. | () |
Source code in src/cosy_luigi/core/combinatorics.py
check_unique_in_prior_tasks_sanity() ¶
Checks if the unique_in_prior_tasks flags set on CoSyLuigiTaskParameters make logical sense. If a required task is set to be unique throughout pipelines, but there are no subclasses of it present, i.e. no variance is possible, remind the user that this is nonsensical.
Source code in src/cosy_luigi/core/combinatorics.py
CoSyLuigiTask ¶
flowchart TD
cosy_luigi.core.CoSyLuigiTask[CoSyLuigiTask]
click cosy_luigi.core.CoSyLuigiTask href "" "cosy_luigi.core.CoSyLuigiTask"
Serves as a CoSy-specific version of luigi.Task. Types derived from CoSyLuigiTask can be added to a CoSyLuigiRepo and will automatically produce typed combinators for synthesis. The main purpose of CoSyLuigiTask is to enforce some conventions and utilize reflections to model variance through Python object inheritance. A task that requires another task of a given type T will also find all subclasses of T as valid inputs.
- Code Reference cosy_luigi
- init cosy_luigi CoSyLuigiTask
- utils
- core
- Code Reference cosy_luigi
- init cosy_luigi
- utils
- core
- constraints
Source code in src/cosy_luigi/core/combinatorics.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
__hash = hash(self.task_id) instance-attribute ¶
__constraints() -> Sequence[Callable[..., bool]] classmethod ¶
This method computes the auto-generated constraints that results from features that are part of the framework itself. For instance, the unique_across_prior_tasks flag is implemented by adding a constraint, this method creates the corresponding Callables.
Returns:
| Type | Description |
|---|---|
Sequence[Callable[..., bool]] | Sequence[Callable[..., bool]]: The auto-generated constraints. |
Source code in src/cosy_luigi/core/combinatorics.py
__init__(*args, **kwargs) ¶
Initializes the CoSyLuigiTask. This only happens during and after synthesis, when the combinators are interpreted. Most functionality is instead implemented on class-level to benefit from caching, since constraints/predicates during synthesis can cause large numbers of instances to be created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args | _type_ | Passed to super().init(). | () |
**kwargs | _type_ | Passed to super().init(). | {} |
Raises:
| Type | Description |
|---|---|
TypeError | The output method of a CoSyLuigiTask must return a Mapping. This is done to prevent addressing output files by index, which leads to unreadable code. |
Source code in src/cosy_luigi/core/combinatorics.py
combinator() -> tuple[str, Callable[..., CoSyLuigiTask], Specification] classmethod ¶
Produces the typed combinator representing this class. Classes with no requirements are instantiated as is, while classes with requirements have the resulting values for their task-parameters passed as varargs. Note that it is not necessary to use kwargs here, as the generation of the type guarantees that the order of passed args and CoSyLuigiTaskParameters aligns.
Returns:
| Type | Description |
|---|---|
tuple[str, Callable[..., CoSyLuigiTask], Specification] | tuple[str, Callable[..., CoSyLuigiTask], Specification]: The resulting combinator. |
Source code in src/cosy_luigi/core/combinatorics.py
combinator_type() -> Specification classmethod ¶
Computes the resulting type of the combinator represented by this class, as described in the methods referenced by this method.
Returns:
| Name | Type | Description |
|---|---|---|
Specification | Specification | The type of the combinator. |
Source code in src/cosy_luigi/core/combinatorics.py
constraints() -> Sequence[Callable[..., bool]] classmethod ¶
The Callables returned by this class are translated into constraints applied to the resulting combinator's types. This method is intended to be overridden in subclasses to make use of this feature. The returned Callables are directly passed to a SpecificationBuilder as a .constraint() call.
Returns:
| Type | Description |
|---|---|
Sequence[Callable[..., bool]] | Sequence[Callable[..., bool]]: A sequence of constraints. |
Source code in src/cosy_luigi/core/combinatorics.py
get_all_class_attributes() -> dict[str, Any] cached classmethod ¶
Collects all class attributes that will be present at runtime. Python does not store class attributes from parent classes in the dict of the subclasses. This method traverses the mro, the ordered list of superclasses to consider for looking for methods, up to the first class that no longer relates to CoSy and copies all their attributes down to the current class.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | dict[str, Any]: A dict containing all attributes that will be present at runtime. |
Source code in src/cosy_luigi/core/combinatorics.py
get_all_instance_attributes() -> dict[str, Any] ¶
Collects all attributes present on an instance at runtime. This method specifically accounts for the fact that Luigi switches out LuigiTaskParameters for the true passed objects at instantiation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | dict[str, Any]: A dict containing all attributes that are present at runtime. |
Source code in src/cosy_luigi/core/combinatorics.py
get_all_variants() -> set[type[CoSyLuigiTask] | Any] cached classmethod ¶
Recursively finds all subclasses of current class.
Returns:
| Type | Description |
|---|---|
set[type[CoSyLuigiTask] | Any] | set[type[CoSyLuigiTask] | Any]: The set of all subclasses. |
Source code in src/cosy_luigi/core/combinatorics.py
get_params() -> list[tuple[str, CoSyLuigiTaskParameter]] cached classmethod ¶
Converts the output of _requirements into a list of tuples instead of a dict.
Returns:
| Type | Description |
|---|---|
list[tuple[str, CoSyLuigiTaskParameter]] | list[tuple[str, CoSyLuigiTaskParameter]]: A list of tuples representing the output of _requirements. |
Source code in src/cosy_luigi/core/combinatorics.py
requirements_unique_in_prior_tasks() -> Mapping[str, CoSyLuigiTaskParameter] cached classmethod ¶
Filters the output of _requirements, returning only those dict entries where the CoSyLuigiTaskParameter has the optional unique_across_prior_tasks flag set.
Returns:
| Type | Description |
|---|---|
Mapping[str, CoSyLuigiTaskParameter] | Mapping[str, CoSyLuigiTaskParameter]: The filtered output of _requirements. |
Source code in src/cosy_luigi/core/combinatorics.py
requires() -> dict[str, CoSyLuigiTask] ¶
Returns a dict of other tasks required to run this task. This is done by retrieving all user-created attributes that are subclasses of CosyLuigiTaskParameter. Note that at Runtime Luigi unpacks CosyLuigiTaskParameters, so the actual check has to be for CoSyLuigiTasks. This overrides the requires method of luigi.Task, and thus ensures that the Luigi scheduler when executing a task "sees" the requirements allocated during synthesis.
Returns:
| Type | Description |
|---|---|
dict[str, CoSyLuigiTask] | dict[str, CoSyLuigiTask]: A dict of other tasks required to run this task, keyed by attribute name. |
Source code in src/cosy_luigi/core/combinatorics.py
target() -> Constructor cached classmethod ¶
The target constructed by this class. This is the right-most entry of the resulting arrow-type constructed for a given CoSyLuigiTask.
Returns:
| Name | Type | Description |
|---|---|---|
Constructor | Constructor | A Constructor, uniquely identified by the class name. |
Source code in src/cosy_luigi/core/combinatorics.py
unique_required_tasks_in_prior() -> Sequence[type[CoSyLuigiTask]] cached classmethod ¶
Transforms the output of requirements_unique_in_prior_tasks into a list of classes that the collected CoSyLuigiTaskParameter's indicate should be unique across prior tasks.
Returns:
| Type | Description |
|---|---|
Sequence[type[CoSyLuigiTask]] | Sequence[type[CoSyLuigiTask]]: The transformed output of requirements_unique_in_prior_tasks. |
Source code in src/cosy_luigi/core/combinatorics.py
CoSyLuigiTaskParameter ¶
flowchart TD
cosy_luigi.core.CoSyLuigiTaskParameter[CoSyLuigiTaskParameter]
click cosy_luigi.core.CoSyLuigiTaskParameter href "" "cosy_luigi.core.CoSyLuigiTaskParameter"
Serves as CoSy-specific version of luigi.TaskParameter. It has two primary uses: Providing a unique classname for the reflection-based operations of the CoSyLuigiTask to examine, and wrapping the classes that a CoSyLuigiTask requires to be inhabited. For instance, for a class B, which declares a CoSyLuigiTaskParameter that wraps the Class A, the resulting CoSy combinator type would be A -> B.
Attributes:
| Name | Type | Description |
|---|---|---|
required_task | type[CoSyLuigiTask] | The type of CoSyLuigiTask this parameter wraps. |
unique_across_prior_tasks | bool | Whether or not to enforce that all concrete occurrences of the potentially abstract wrapped type need to be the same. |
Source code in src/cosy_luigi/core/combinatorics.py
required_task = required_task instance-attribute ¶
unique_across_prior_tasks = unique_across_prior_tasks instance-attribute ¶
__init__(required_task: type[CoSyLuigiTask], *, unique_across_prior_tasks: bool = False) ¶
Initializes the CoSyLuigiTaskParameter. Setting unique_across_prior_tasks to True only makes sense if the required_task is abstract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
required_task | type[CoSyLuigiTask] | The type of CoSyLuigiTask this parameter wraps. | required |
unique_across_prior_tasks | bool | Whether or not to enforce that all concrete occurrences of the potentially abstract wrapped type need to be the same. | False |