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

SingleColumn: Fix vectorisation of nested else-if bodies #392

Merged
merged 4 commits into from
Oct 10, 2024

Conversation

mlange05
Copy link
Collaborator

@mlange05 mlange05 commented Oct 9, 2024

The recent special-casing for else-if branches in the SCC vectorisation only works for single-level nesting, but skips any further nested else-ifs and the final else-branch. TO fix this, i've introduced a else_bodies property on Conditional nodes that returns the nested bodies for multi-conditionals. Using this, this we can then apply vector-section extraction for every else body in a deeply nested multi-conditional.

Copy link

github-actions bot commented Oct 9, 2024

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

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.53%. Comparing base (3834903) to head (53b2080).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #392   +/-   ##
=======================================
  Coverage   95.53%   95.53%           
=======================================
  Files         186      186           
  Lines       38974    39005   +31     
=======================================
+ Hits        37233    37263   +30     
- Misses       1741     1742    +1     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 95.51% <100.00%> (+<0.01%) ⬆️

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.

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.

Only a comment for now, but changes look very good. I think your solution actually allows to simplify the vector sections extraction again, removing the need to check for has_elseif.

I will let the nightly CI run against this branch to confirm whether it fixes the problem.

of the conditional chain.
"""
if self.has_elseif:
return (self.else_body[0].body,) + self.else_body[0].else_bodies
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now I have understood - very neat indeed 😄

@@ -141,7 +141,11 @@ def extract_vector_sections(cls, section, horizontal):
# as 'Conditional's rely on the fact that the first element of the 'else_body'
# (if 'has_elseif') is a Conditional itself
if separator.has_elseif and separator.else_body:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since separator.else_bodies should, even in the has_elseif==False case, return the else_body correctly, we should be able to remove this check here and always use the new implementation, no?

@mlange05 mlange05 force-pushed the naml_fix_multicond_scc_vector branch from ddc67d1 to e4a4526 Compare October 10, 2024 04:08
@mlange05 mlange05 force-pushed the naml_fix_multicond_scc_vector branch from e4a4526 to 96cfb7d Compare October 10, 2024 05:29
@mlange05 mlange05 marked this pull request as ready for review October 10, 2024 05:29
@mlange05
Copy link
Collaborator Author

Thanks for the early review; you were right, the logic could be drastically simplified. Unfortunately, last nights version was still buggy, but I've just rebase-pushed a clean version that should bring the tco399 ecphys regression back (confirmed locally). Please have another look, but should be ready now.

Copy link
Collaborator

@MichaelSt98 MichaelSt98 left a comment

Choose a reason for hiding this comment

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

Very nice indeed!

loki/transformations/single_column/vector.py Outdated Show resolved Hide resolved
Co-authored-by: Michael Staneker <[email protected]>
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.

The fixed fix seems to have resolved the problems in ifs-bundle. Many thanks for this!

I have accepted the comment suggestion from @MichaelSt98 as well.

@reuterbal reuterbal added the ready for merge This PR has been approved and is ready to be merged label Oct 10, 2024
@reuterbal reuterbal merged commit 0189d24 into main Oct 10, 2024
13 checks passed
@reuterbal reuterbal deleted the naml_fix_multicond_scc_vector branch October 10, 2024 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge This PR has been approved and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants