Skip to content

(towards #2668) Add kwargs to all remaining transformations - #3612

Open
sergisiso wants to merge 9 commits into
masterfrom
2668_all_remaining_kwarg_trans
Open

sergisiso wants to merge 9 commits into
masterfrom
2668_all_remaining_kwarg_trans

Conversation

@sergisiso

Copy link
Copy Markdown
Collaborator

No description provided.

@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e93a73c) to head (ca6d36e).

Additional details and impacted files
@@            Coverage Diff             @@
##            master     #3612    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          403       403            
  Lines        56790     56892   +102     
==========================================
+ Hits         56790     56892   +102     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sergisiso

Copy link
Copy Markdown
Collaborator Author

@LonelyCat124 This is ready for review

@LonelyCat124 LonelyCat124 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look at the tests yet and had a fairly quick look through. It mostly looks ok (did it definitely find them all? Other than the Fuse ones iI'm currently working on), but its definitely missed a few of the things and in a couple of places it does some very non-obvious things.

It would be nice to cleanup the Nodes that take options as an input, but might be beyond the scope of this PR.

:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param bool options["create_driver"]: whether or not to create a \
:param options["create_driver"]: whether or not to create a \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm any options["..."] throughout the changed files.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them all now

:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param str options["prefix"]: a prefix to use for the PSyData module \
:param options["prefix"]: a prefix to use for the PSyData module \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is prefix inherited or it missed it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inherited from PSyDataTrans

"driver-MODULE-REGION.f90" where MODULE and REGION will be the \
corresponding values for this region. Defaults to False.
:param (str,str) options["region_name"]: an optional name to \
:param options["region_name"]: an optional name to \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is region name inherited or missed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inherited from PSyDataTrans

:py:class:`psyclone.domain.lfric.algorithm.LFRicAlgorithmInvokeCall`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param options["kernels"]: this option provides a list of \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again its kept options["..."]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them all now


# Check the algorithm arguments and kernel metadata match.
self.get_arguments(node, options=options, check_args=True)
self.get_arguments(node, kernels=kernels, check_args=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get arguments also take **kwargs (and keep options) in case of inheritance?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed options (it is an internal function we don't need it). I kept kwargs, just because it is a subclass calling a method implemented in subclasses with different parameters. I think this is not the best design but maybe updating this is out-of-scope for this PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also fully deleted the options from the alg_invoke_2_psy_call family of transformations as this are only for internal use and don't need backwards compatibility apis.

@@ -8,13 +8,17 @@
'''This module provides the LoopTiling2DTrans, which transforms a 2D Loop
construct into a tiled implementation of the construct.'''

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had previously ignored this transformation because its deprecated, happy to have it changed but maybe we can remove/delete this transformation on a similar timeline as options anyway?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for this PR I won't want to leave an exception without kwargs, maybe we keep the deprecation of the transformation separate of this?

:type nodes: :py:class:`psyclone.psyir.nodes.Node` or
list[:py:class:`psyclone.psyir.nodes.Node`]
:param bool options["force"]: whether to ignore potential control
:param force: whether to ignore potential control

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the param on validate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gone now

:param force: ignore potential control-flow jumps in the region.

'''
if force:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to avoid duplicating force in kwargs? That doesn't seem possible since force is explicitly defined on this apply method so can't we just do

super().apply(nodes, force=force, options=options, **kwargs)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (apparently is was due to a monkeypatched validate that didn't accept kwargs, but I fixed the test now)

(``PREFIX_PSYDATATYPE``) - a "_" will be added automatically. \
It defaults to "".
:param (str,str) options["region_name"]: an optional name to \
:param region_name: an optional name to \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only needed on apply

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

validate_kwargs["prefix"] = prefix
if region_name is not None:
validate_kwargs["region_name"] = region_name
self.validate(node_list, options, **validate_kwargs)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on here?

@LonelyCat124

Copy link
Copy Markdown
Collaborator

For reference, this was the script I wrote to find all remaining transformations previously:

import importlib
import pkgutil


def import_submodules(package, recursive=True):
    """ Import all submodules of a module, recursively, including subpackages

    :param package: package (name or actual module)
    :type package: str | module
    :rtype: dict[str, types.ModuleType]
    """
    if isinstance(package, str):
        package = importlib.import_module(package)
    results = {}
    for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
        full_name = package.__name__ + '.' + name
        try:
            results[full_name] = importlib.import_module(full_name)
        except ModuleNotFoundError:
            continue
        if recursive and is_pkg:
            results.update(import_submodules(full_name))
    return results

import psyclone
from psyclone.psyGen import Transformation
import_submodules(psyclone)
import sys
import inspect
all_trans = []
for module in list(sys.modules.keys())[:]:
    for name, obj in inspect.getmembers(sys.modules[module]):
        if inspect.isclass(obj) and issubclass(obj, Transformation):
            if obj not in all_trans:
                all_trans.append(obj)

no_applies = []
no_kwargs = []
has_kwargs = []
for trans in all_trans:
    if not (trans.__dict__.get("apply", None)):
        no_applies.append(trans.__name__)
        continue
    apply = trans.__dict__.get("apply")
    signature = inspect.signature(apply)
    for k, v in signature.parameters.items():
        if k == "kwargs":
            has_kwargs.append(trans.__name__)
            break
    else:
        no_kwargs.append(trans.__name__)

print(has_kwargs)
print("----------------------------")
print(no_applies)
print("----------")
print(no_kwargs)

This branch was successfully deployed

1 active (outdated) deployment
integration 69b8be15 Deployed Sep 21, 2026 by sergisiso via build #1825
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants