A return type of a dict of jobs from a Job is interpreted as a replace#856
A return type of a dict of jobs from a Job is interpreted as a replace#856vineetbansal wants to merge 6 commits intomaterialsproject:mainfrom
Conversation
|
I just saw that @gpetretto submitted a small fix to the previous PR. That particular issue does not exist in this PR since everything is inside the |
gpetretto
left a comment
There was a problem hiding this comment.
Hi @vineetbansal,
thanks for the addition. I have left a few small comments. In particular it would be good to address here the problem reported in #855.
|
Thanks @gpetretto. I think I've addressed the concerns here. Some tests had to be tweaked slightly because with this change: From: to: The last However, in doing this, I noticed something that may or may not indicate something problematic. This snippet in one of the tests: becomes: The fact that the last |
|
Thanks @vineetbansal for the updates. I think they are fine, but apparently I cannot mark the comments as resolved. Concerning the change in the config manager, you are absolutely right, I think it is a bug. The problem is that the I think that the correct solution would be to make this change: --- a/src/jobflow/core/job.py
+++ b/src/jobflow/core/job.py
@@ -184,6 +184,7 @@ def job(
--------
Job, .Flow, .Response
"""
+ from copy import deepcopy
def decorator(func):
from functools import wraps
@@ -214,7 +215,7 @@ def job(
args = args[1:]
return Job(
- function=f, function_args=args, function_kwargs=kwargs, **job_kwargs
+ function=f, function_args=args, function_kwargs=kwargs, **deepcopy(job_kwargs)
)I briefly tested and with this the tests can go back to their original form. It makes sense to make sure that the same instances of the jobs_kwargs elements are not shared among the different instances of the jobs created from a single decorated function. @utf do you see any problem with this? or do you have any better solution? |
|
Thanks @gpetretto - that makes sense. I've removed the last I'll open up another issue on the deepcopy stuff in case it has deeper implications that we may want to investigate. |
|
@utf - perhaps you can take a look? We're not introducing any deep changes here other than interpreting dict return of |
Summary
In a previously accepted PR, we put in some logic to check if a
Job(or a tuple/list ofJobs) is returned by a@job. In those cases it is automatically interpreted as aReplace.The motivation for that PR was that the
@jobspecifies the dependencies, but the actual mechanics of replacement (Response/replace) are handled internally injobflow. This has worked well for our suite of recipes, but we've stumbled on a use-case that might need one small enhancement to this behavior.We found that since a
@jobthat spawns otherJobs needs to return all of them instead of the ones that may be of direct interest to the caller (otherwise the non-returned jobs are never added to the DAG), we're finding that it is useful in certain jobs to namespace the dependentJobs for easier use by the caller by returning a dict. Something like:This PR adds this functionality while preserving the output structure. I've included a test to demonstrate this.
This change allows
jobflowto work with all our recipes.Let me know if there are any questions or concerns with this. Thanks!
Checklist
Work-in-progress pull requests are encouraged, but please put [WIP] in the pull request
title.
Before a pull request can be merged, the following items must be checked:
The easiest way to handle this is to run the following in the correct sequence on
your local machine. Start with running black on your new code. This will
automatically reformat your code to PEP8 conventions and removes most issues. Then run
pycodestyle, followed by flake8.
Run pydocstyle on your code.
type check your code.
Note that the CI system will run all the above checks. But it will be much more
efficient if you already fix most errors prior to submitting the PR. It is highly
recommended that you use the pre-commit hook provided in the repository. Simply
pip install pre-commitand thenpre-commit installand a check will be runprior to allowing commits.