Skip to content

Commit

Permalink
clean-up and improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSt98 committed Jan 10, 2025
1 parent e702802 commit 534e575
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
15 changes: 3 additions & 12 deletions loki/batch/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class attribute is specified by every class implementing a specific item
trafo_data : any:`dict`
Container object for analysis passes to store analysis data. This can be used
in subsequent transformation passes.
plan_data : any:`dict`
Container object for plan dry-run passes to store information about
additional and removed dependencies.
Parameters
----------
Expand All @@ -165,18 +168,6 @@ def __init__(self, name, source, config=None):
self.plan_data = {}
super().__init__(config)

def clone(self, **kwargs):
"""
Replicate the object with the provided overrides.
"""
if 'name' not in kwargs:
kwargs['name'] = self.name
if 'source' not in kwargs:
kwargs['source'] = self.source.clone() # self.source.clone()
if self.config is not None and 'config' not in kwargs:
kwargs['config'] = self.config
return type(self)(**kwargs)

def __repr__(self):
return f'loki.batch.{self.__class__.__name__}<{self.name}>'

Expand Down
48 changes: 47 additions & 1 deletion loki/transformations/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,25 @@


class DuplicateKernel(Transformation):
"""
Duplicate subroutines which includes the creation of new :any:`Item`s
as well as the addition of the corresponding new dependencies.
Therefore, this transformation creates a new item and also implements
the relevant routines for dry-run pipeline planning runs.
Parameters
----------
duplicate_kernels : str|tuple|list, optional
Kernel name(s) to be duplicated.
duplicate_suffix : str, optional
Suffix to be used to append the original kernel name(s).
duplicate_module_suffix : str, optional
Suffix to be used to append the original module name(s),
if defined, otherwise `duplicate_suffix`
"""

creates_items = True

reverse_traversal = True

def __init__(self, duplicate_kernels=None, duplicate_suffix='duplicated',
Expand All @@ -25,6 +41,24 @@ def __init__(self, duplicate_kernels=None, duplicate_suffix='duplicated',
self.duplicate_kernels = tuple(kernel.lower() for kernel in as_tuple(duplicate_kernels))

def _create_duplicate_items(self, successors, item_factory, config):
"""
Create new/duplicated items.
Parameters
----------
successors : tuple
Tuple of :any:`Item`s representing the successor items for which
new/duplicated items are created..
item_factory : :any:`ItemFactory`
The :any:`ItemFactory` to use when creating the items.
config : :any:`SchedulerConfig`
The scheduler config to use when instantiating new items.
Returns
-------
tuple
Tuple of newly created items.
"""

new_items = ()
for item in successors:
if item.local_name in self.duplicate_kernels:
Expand Down Expand Up @@ -99,6 +133,18 @@ def plan_subroutine(self, routine, **kwargs):


class RemoveKernel(Transformation):
"""
Remove subroutines which includes the removal of the relevant :any:`Item`s
as well as the removal of the corresponding dependencies.
Therefore, this transformation creates a new item and also implements
the relevant routines for dry-run pipeline planning runs.
Parameters
----------
remove_kernels : str|tuple|list, optional
Kernel name(s) to be removed.
"""

creates_items = True

Expand Down

0 comments on commit 534e575

Please sign in to comment.