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

Repo reorganisation: Moving transformations #296

Merged
merged 13 commits into from
May 3, 2024
Merged

Conversation

mlange05
Copy link
Collaborator

@mlange05 mlange05 commented Apr 23, 2024

The next step in our spring clean (issue #253) is to move all the internally support transformations into the core package, alongside the associated tests. This then also merges the loki.transform general utilities into the more custom loki.transformations packages.

I've tried to restrain myself to only move files and fix-up import headers, with a few small exceptions listed in the details below:

  • Transformation and Pipeline class have been moved into loki.batch as they are the interface to the scheduler
  • transformations has been moved into loki.transformations
    • the associated test have been moved in the same fashion
    • the additional conftest.py has been resolved and the runner utilities for CLOUDSC and ecWAM added to loki.tools
  • The subpackages loki.transformations.single_column, loki.transformations.transpile and loki.transformations.build_system have been separated
    • DependencyTransformation and ModuleWrapTransformation have been mode to separate files inside trnasformations.build_system
    • CI And packaging has been changes as needed (please double-check this)
    • loki.transform has been moved into loki.transformations, often removing the transform_xxx prefix

And finally, apologies to @MichaelSt98 , as this one might conflict quite a bit with his current stuff... 😬

Copy link

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/296/index.html

@mlange05 mlange05 force-pushed the naml-repo-reorg-trafo branch 7 times, most recently from 3bcad1b to 7f70cc3 Compare April 25, 2024 07:15
Copy link

codecov bot commented Apr 25, 2024

Codecov Report

Attention: Patch coverage is 95.71046% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 95.09%. Comparing base (102dafd) to head (fb56455).

Files Patch % Lines
loki/tools/files.py 15.78% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #296      +/-   ##
==========================================
+ Coverage   94.97%   95.09%   +0.12%     
==========================================
  Files         151      165      +14     
  Lines       32407    35282    +2875     
==========================================
+ Hits        30779    33552    +2773     
- Misses       1628     1730     +102     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 95.07% <95.71%> (-0.07%) ⬇️
transformations ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@mlange05 mlange05 marked this pull request as ready for review April 25, 2024 08:34
@MichaelSt98
Copy link
Collaborator

Thanks, really nice! I'm happy with it and haven't discovered anything problematic.
Nevertheless some comments:

I think in order to be consistent:

  • transformations/build_system/tests/test_transform_dependency.py --> transformations/build_system/test_dependency.py
  • transformations/tests/test_transform_derived_types.py --> transformations/tests/test_derived_types.py

Why not?

  • transformations/transform_loop.py --> transformations/loop.py
  • transformations/transform_region.py --> transfrormations/region.py

Me thinking out loud:

  • introduce subdirectories within transformations ?
    • transformations/temporaries/ (or something like that) for hoist-variables, pool_allocator, ...
    • transformations/control_flow/ (or something like that) for loop, inline, region, ...
    • transformations/utilities/ for utilities, remove_code, drhook, ...
  • it makes sense for transformation and pipeline to be within batch as they are interfacing the scheduler, however, I somehow would have expected them to be in transformations/

I guess that further repo reorganisation like "separate operations (inlinecall, subscript, sum, ...) from the symbols/literals" will be done in a future/separate PR?!

@mlange05
Copy link
Collaborator Author

@MichaelSt98 Many thanks for the review - to answer your questions:
1.

transformations/build_system/tests/test_transform_dependency.py --> transformations/build_system/test_dependency.py
transformations/tests/test_transform_derived_types.py --> transformations/tests/test_derived_types.py

Yes, absolutely, that was an oversight! Will fix in the needed rebase!

transformations/transform_loop.py --> transformations/loop.py
transformations/transform_region.py --> transfrormations/region.py

Mostly because I actually thought "transform" to be a good high-level description for "fusion/fission/interchange" and "hoist/extract". Open for suggestions though, as the grouping by target "node type" seemed not scalable to me.

Agree in general on the proposed further sub-division or the transformations package; this will potentially also require some re-jigging of the stuff insied some of those transformation (eg. lots in SCCBase could go into utility) and I simply wanted to keep this PR manageable.

With regards to Transformation/Pipeline moving, this simply creates a clean import chain, as everything in loki.transformations should be "do something to code", and thus depend on the ir/expression and batch sub-packages. Hope this makes sense. 😉

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to review this and many thanks, this looks fantastic.

I agree with all what's been said so far. Regarding the renaming to just loop & co I share your assessment that this might not scale well and the transform adds information despite being somewhat redundant at first look - since it is the commonly used terminology for the kind of changes applied by the utilities in there.

I've added some comments where I spotted missing docstrings or possible clean-up opportunities, but overall this looks very good.

The documentation scripts need to be updated, too, but since we have already dangling pointers in there and Sphinx steps over this gracefully, we may as well do a sweep in a separate PR to rectify this.

install Outdated
@@ -508,5 +507,5 @@ echo "Activate the Loki environment with"
echo
echo " source loki-activate"
echo
echo "You can test the Loki installation by running 'py.test transformations lint_rules .'"
echo "You can test the Loki installation by running 'py.test lint_rules .'"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be running 'py.test lint_rules loki', I think.

"""
Update imports of wrapped subroutines.
"""
from loki.batch import SchedulerConfig # pylint: disable=import-outside-toplevel,cyclic-import
Copy link
Collaborator

Choose a reason for hiding this comment

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

This import could now also take place at the toplevel, no?



@pytest.fixture(scope='module', name='here')
@pytest.fixture(scope='function', name='here')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that it matters too much, but curious why the scope has changed for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch! I had previously used this in the build, but now it works without this, so can go back to "module" scoping.

Comment on lines 745 to 747
builder.clean()
(here/f'{driver.name}.f90').unlink()
(here/f'{kernel_module.name}.f90').unlink()
(tempdir/f'{driver.name}.f90').unlink()
(tempdir/f'{kernel_module.name}.f90').unlink()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be redundant with the tempdir clean-up in the fixture?

Comment on lines 249 to 250
def write_env_launch_script(here, binary, args):
# Write a script to source env.sh and launch the binary
Copy link
Collaborator

Choose a reason for hiding this comment

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

It took me a while to figure out why we have these because they didn't show up with test coverage. So, I would suggest adding short docstrings:

Suggested change
def write_env_launch_script(here, binary, args):
# Write a script to source env.sh and launch the binary
def write_env_launch_script(here, binary, args):
"""
Utility method that is used for regression tests that require
activating an environment file before running :data:`binary`.
This writes a simple script of the form
.. code-block::
source env.sh
bin/<binary> <args>
exit $?
Parameters
----------
here : pathlib.Path or str
The directory in which the script is created
binary : str
The name of the binary
args : list of str
List of arguments to pass to the binary
Returns
-------
pathlib.Path
The path to the created script file
"""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for these! Added as suggested.

loki/tools/files.py Show resolved Hide resolved
return str(lokidir.resolve()), target, backup


def local_loki_cleanup(target, backup):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def local_loki_cleanup(target, backup):
def local_loki_cleanup(target, backup):
Companion utility to :any:`local_loki_setup` to revert the changes
This removes a symlink at :data:`target`, if it exists, and moves the
:data:`backup` path in its original location.
Parameters
---------
target : pathlib.Path
The target injection path as returned by :any:`local_loki_setup`
backup : pathlib.Path
The backup path as created by :any:`local_loki_setup`

@mlange05 mlange05 force-pushed the naml-repo-reorg-trafo branch 3 times, most recently from 0dbb754 to da4814c Compare May 3, 2024 11:29
@mlange05
Copy link
Collaborator Author

mlange05 commented May 3, 2024

Ok, apologies, this took a bit longer than anticipated. @reuterbal I think I've addressed all comments - many thanks for the suggestions!

I've also tried to address the naming inconsistencies pointed out by @MichaelSt98, but those generated some name clashes in the test base (test_derived_type existed twice). So instead I've opted to rename loki.transformations.derived_type to loki.transformations.transform_derived_types to match the test. I hope this works now, and I think we'll get to tidy this up a little further in a follow-on PR.

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

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

Thanks for this. I found another oopsie and my docstring suggestion was faulty (sorry!), but otherwise good to go!

install Outdated
@@ -512,7 +511,7 @@ print_step "Installation finished"
echo
echo "Activate the Loki environment with"
echo
echo " source loki-activate"
echo " source loki-activate"xf
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something's gone wrong here

Suggested change
echo " source loki-activate"xf
echo " source loki-activate"

"""
Utility method that is used to determine paths for injecting the
currently running source code of Loki into an
[ecbundle](https://github.com/ecmwf/ecbundle)-based worktree This
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, got caught out by the annoying RST vs. MD syntax differences for link formatting...

Also, empty line after the first sentence improves formatting in the HTML output.

Suggested change
[ecbundle](https://github.com/ecmwf/ecbundle)-based worktree This
`ecbundle <https://github.com/ecmwf/ecbundle>`_-based worktree.
This

@mlange05 mlange05 merged commit dd01f94 into main May 3, 2024
12 checks passed
@mlange05 mlange05 deleted the naml-repo-reorg-trafo branch May 3, 2024 15:29
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

Successfully merging this pull request may close these issues.

3 participants