Skip to content

Conversation

@vkarak
Copy link
Contributor

@vkarak vkarak commented Feb 9, 2024

Currently, multiple inheritance of test or mixin variables is prohibited leads to a test load error. This is restrictive, especially in case of mixins, which may be inherited multiple times in a complex setup. For example, the following would cause an error when reframe is processing the Z class:

    class Mixin(rfm.RegressionMixin):
        x = variable(typ.List[int], value=[])

    class X(Mixin):
        x = [3, 4]

    class Y(Mixin):
        x = [10, 1]

    class Z(X, Y):
        pass

This PR introduces a new variable argument, merge_func, that defines how the default values of the parent variables can be combined in case of multiple inheritance. Since merge_func=None by default, the default behaviour of variables does not change. It just that we now offer the extra flexibility to users to define the variable behaviour in case of multiple inheritance.

In the example above, if we define x as follows:

    class Mixin(rfm.RegressionMixin):
        x = variable(typ.List[int], value=[],
                     merge_func=lambda x, y: list(map(max, zip(x, y))))

    class X(Mixin):
        x = [3, 4]

    class Y(Mixin):
        x = [10, 1]

    class Z(X, Y):
        pass

its value in Z class will be [10, 4].

Todos

  • Update docs
  • Use a better than "combine" naming

@pep8speaks
Copy link

pep8speaks commented Feb 9, 2024

Hello @vkarak, Thank you for updating!

Cheers! There are no PEP8 issues in this Pull Request!Do see the ReFrame Coding Style Guide

Comment last updated at 2024-02-19 20:17:18 UTC

@codecov
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (791b57c) 86.64% compared to head (ed2526d) 86.66%.

❗ Current head ed2526d differs from pull request most recent head 479a013. Consider uploading reports for the commit 479a013 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3113      +/-   ##
===========================================
+ Coverage    86.64%   86.66%   +0.02%     
===========================================
  Files           61       61              
  Lines        12052    12066      +14     
===========================================
+ Hits         10442    10457      +15     
+ Misses        1610     1609       -1     

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

@vkarak vkarak marked this pull request as ready for review February 9, 2024 12:15
Co-authored-by: Theofilos Manitaras <manitaras@cscs.ch>
Copy link
Contributor

@victorusu victorusu left a comment

Choose a reason for hiding this comment

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

lgtm

@vkarak vkarak merged commit 98d8124 into reframe-hpc:develop Feb 19, 2024
@vkarak vkarak deleted the feat/combine-vars branch February 19, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants