Skip to content

Commit

Permalink
Merge pull request #449 from ecmwf-ifs/nabr-sgraph-rebuild-optimisation
Browse files Browse the repository at this point in the history
SGraph (re-)build optimisations
  • Loading branch information
reuterbal authored Dec 12, 2024
2 parents e9760e8 + aacccfc commit fe6bf33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 6 additions & 6 deletions loki/batch/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

from fnmatch import fnmatch
import fnmatch
from itertools import accumulate
from pathlib import Path
import re
Expand Down Expand Up @@ -183,10 +183,10 @@ def match_item_keys(item_name, keys, use_pattern_matching=False, match_item_pare
}

# Match against keys
keys = as_tuple(keys)
keys = tuple(key.lower() for key in as_tuple(keys))
if use_pattern_matching:
return tuple(key for key in keys or () if any(fnmatch(name, key.lower()) for name in item_names))
return tuple(key for key in keys or () if key.lower() in item_names)
return tuple(key for key in keys if fnmatch.filter(item_names, key))
return tuple(key for key in keys if key in item_names)

def create_item_config(self, name):
"""
Expand Down Expand Up @@ -233,7 +233,7 @@ def create_frontend_args(self, path, default_args):
frontend_args = default_args.copy()
for key, args in (self.frontend_args or {}).items():
pattern = key.lower() if key[0] == '/' else f'*{key}'.lower()
if fnmatch(path, pattern):
if fnmatch.fnmatch(path, pattern):
frontend_args.update(args)
return frontend_args
return frontend_args
Expand All @@ -242,7 +242,7 @@ def is_disabled(self, name):
"""
Check if the item with the given :data:`name` is marked as `disabled`
"""
return len(self.match_item_keys(name, self.disable, use_pattern_matching=True, match_item_parents=True)) > 0
return bool(self.match_item_keys(name, self.disable, use_pattern_matching=True, match_item_parents=True))


class TransformationConfig:
Expand Down
13 changes: 4 additions & 9 deletions loki/batch/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,7 @@ def definitions(self):
global variables.
"""
self.concretize_definitions()
definitions = tuple(
d for d in self.ir.definitions
if not isinstance(d, (MetaSymbol, TypedSymbol)) or isinstance(d, ProcedureSymbol)
)
definitions = self.ir.subroutines + as_tuple(FindNodes((TypeDef, Interface)).visit(self.ir.spec))
return definitions

@property
Expand Down Expand Up @@ -1118,8 +1115,6 @@ def get_or_create_item(self, item_cls, item_name, scope_name, config=None):
:any:`Item` or None
The item object or `None` if disabled or impossible to create
"""
if config and config.is_disabled(item_name):
return None
if item_name in self.item_cache:
return self.item_cache[item_name]

Expand Down Expand Up @@ -1489,7 +1484,7 @@ def _is_ignored(name, config, ignore):
``True`` if matched successfully via :data:`config` or :data:`ignore` list,
otherwise ``False``
"""
return (
(config and config.is_disabled(name)) or
(ignore and SchedulerConfig.match_item_keys(name, ignore, use_pattern_matching=True))
keys = as_tuple(config.disable if config else ()) + as_tuple(ignore)
return keys and SchedulerConfig.match_item_keys(
name, keys, use_pattern_matching=True, match_item_parents=True
)
4 changes: 2 additions & 2 deletions loki/batch/tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,15 @@ def test_module_item4(testdir):
# Make sure interfaces are correctly identified as definitions
item = get_item(ModuleItem, proj/'some_module.F90', 'some_module', RegexParserClass.ProgramUnitClass)
definitions = item.definitions
assert len(definitions) == 8
assert len(definitions) == 6
assert len(item.ir.interfaces) == 1
assert item.ir.interfaces[0] in definitions

item_factory = ItemFactory()
item_factory.item_cache[item.name] = item

items = item.create_definition_items(item_factory=item_factory)
assert len(items) == 10
assert len(items) == 8
assert len(set(items)) == 6
assert 'some_module#add_args' in item_factory.item_cache
assert isinstance(item_factory.item_cache['some_module#add_args'], InterfaceItem)
Expand Down

0 comments on commit fe6bf33

Please sign in to comment.