Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LFRic transformation signature? #2739

Open
Tracked by #2737
sergisiso opened this issue Oct 7, 2024 · 4 comments
Open
Tracked by #2737

Update LFRic transformation signature? #2739

sergisiso opened this issue Oct 7, 2024 · 4 comments

Comments

@sergisiso
Copy link
Collaborator

Since we are talking about 3.0, one aspect that I wanted to discuss is if we should also update the LFRic scripts signature in this major release to use the root psyir node as scprit input argument (like in the generic transformation scripts).

Instead of:

def trans(psy):
    '''
    :param psy: the PSy object that PSyclone has constructed.
    :type psy: :py:class:`psyclone.dynamo0p3.DynamoPSy`
    '''

    # Loop over all the Invokes in the PSy object
    for invoke in psy.invokes.invoke_list:
        print("Transforming invoke '"+invoke.name+"'...")
        schedule = invoke.schedule

it would be:

def trans(psyir):
    '''
    :param psyir: the PSyIR of the generated PSy-layer
    :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer`
    ''''

    # Loop over all the Invokes Subroutines
    for schedule in psyir.walk(InvokeSchedule):
        print("Transforming invoke " + schedule.name)

The main advantage is that it hides the PSy->Invokes->Invoke->InvokeSchedule structure:

  • Opens the door to modify it without breaking existing scripts
  • Less concepts to know about (and documentation needed) for users writing scritps

Other minor advantages are:

  • Allows to modify non invoke subroutines in a natural top-down approach (psyir.walk(Routines) instead of invoke.schedule.root.walk(Routines) that we do now)
  • Converges some code with the generic transformations, so we can simplify the generate.py
  • Simpler for people writing scripts for UM parts integrated into PSyclone, as they just need to know 1 script signature instead of 2.

What do @arporter @hiker @christophermaynard @TeranIvy think?

@arporter
Copy link
Member

arporter commented Oct 7, 2024

Thanks @sergisiso, I like this proposal a lot. Presumably, if we were dealing with a named invoke (i.e. a call invoke(name="big-science", kernel1(x,y))) then that name would still be available in the script as the name of the InvokeSchedule?

@sergisiso
Copy link
Collaborator Author

Yes, I didn't discuss it here but there are some scripts that use psy.invokes.get("invoke_0") which would then be a schedule.name == "invoke_0" check. Some print psy.name which will then be psyir.name. And since we would be touching all these loops we could also rename InvokeSchedule to InvokeRoutine (since it inherits from Routine) and it will be even clearer to do: for subroutine in psyir.walk(InvokeRoutine): (since Schedule is a very specifc PSyclone concept but Routine is a broader Fortran concept).

@sergisiso sergisiso mentioned this issue Oct 7, 2024
5 tasks
@hiker
Copy link
Collaborator

hiker commented Oct 9, 2024

Yes, please - change that, I always hated the exposure of the PSy structure.

For a while, maybe the FileContainer could provide a compatibility layer?

    for invoke_name in psy.invokes.names:
        invoke = psy.invokes.get(invoke_name)

That would avoid the effort of having to all scripts when the next release comes out? These function could print a deprecated functionality warning or so.

@sergisiso
Copy link
Collaborator Author

Ok, I will start implementing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants