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

Create a decorator function to extract options from Strategy #180

Merged
merged 18 commits into from
Oct 12, 2024
Merged

Conversation

tjgalvin
Copy link
Owner

At the moment in order to get round specific options from the Strategy yaml file an explicit call has to be made into get_options_from_strategy with a set of keywords that specify the mode, self cal round and operation to uniquely identify the target set of user provided options. If these do not exist an empty dictionary is returned.

This has worked fine in the past, but requires an explicit function call to get options, which are passed through into the target function.

This pull request explores whether a decorator function is of any use. The idea being that we can add the strategy extraction parameters to a target function, such that the target function itself extracts the appropriate options. Functionally, there is still a call into the Strategy yaml file, but it is hidden.

At best, it keeps all keyword arguments that act as inputs to a particular processing stage together and removes some clutter in the larger prefect workflow.

At worst, it can be seen as confusing and hides logic that may not be immediately obvious to someone who does not know the task has been wrapped.

This pull request does not remove the old approach of separating the call into the strategy options getter - that is still a completely supported mode.

Thoughts are welcome. After doing this I have two issues:

  • the decorator itself returns a new function, which has a different __name__ and __doc__ to the wrapped function. There might be other gotchas that come from this. I already found that functools.wraps causes errors with the prefect.task argument validation
  • It feels a little smelly. To date I have preferred explicit is better than implicit, and this is feeling like it is getting a little too close to the implicit.

@tjgalvin tjgalvin requested a review from AlecThomson October 11, 2024 03:25
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.28%. Comparing base (f65ddb4) to head (240eeb7).

Files with missing lines Patch % Lines
flint/configuration.py 97.05% 1 Missing ⚠️
flint/prefect/flows/continuum_pipeline.py 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #180      +/-   ##
==========================================
- Coverage   60.32%   60.28%   -0.04%     
==========================================
  Files          33       33              
  Lines        5727     5749      +22     
==========================================
+ Hits         3455     3466      +11     
- Misses       2272     2283      +11     

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

@tjgalvin tjgalvin merged commit 0f41108 into main Oct 12, 2024
2 checks passed
@tjgalvin tjgalvin deleted the stratdec branch October 12, 2024 14:04
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.

2 participants