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

[wip, fix] small changes and fixes #76

Closed
wants to merge 5 commits into from

Conversation

djarecka
Copy link
Collaborator

various small changes:

  • adding imports to init files;
  • adding exception for no input_spec (Assuming that changing input_spec to allow tasks without input #70 won't be accepted);
  • removing loop.close when Jupyter in os.environ (I'm just adding this variable in the tutorials, other suggestions to run pydra in jupyter welcome);
  • adding output_names to Task, so it doesn't have to be "out"
  • adding tests

tests that xfail (will be fixing later):

  • tasks wit splitter can't be run using call
  • if output_names is not specified we can't save as an output multiple variables

…r no input_spec; removing loop.close when Jupyter in os.environ (I add this variable in the tutorials); adding output_names to Task; adding tests (some xfail)
@djarecka djarecka mentioned this pull request Jul 16, 2019
@@ -149,7 +150,9 @@ def __exit__(self, type, value, traceback):
return futures

def close(self):
self.loop.close()
# jupyter is also using cf, so can't close the loop
if not "Jupyter" in os.environ:
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems something that Jupyter should handle, not us. i don't want pydra to be dependent on whether it's used in a specific environment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The short answer is - it also surprised me, but Jupyter doesn't handle... Note, that it's not only this, I still had to import nest_asyncio to the notebook!

I agree that we don't want to change pydra, the if statement seemed to me the only "acceptable" option, but I will search more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yesterday I was thinking about forgetting about jupyter, but I'm guessing it's not an option that will be approved ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have config?

Suggested change
if not "Jupyter" in os.environ:
if not config.getboolean("execution", "nested_asyncio"):

Then, Jupyter notebooks could use a modified config file, or users could add at import:

import pydra
pydra.config.set("execution", "nested_asyncio", True)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but the problem is that we also want pydra to change the behavior, i.e. do not close the loop. At least that was the solution we found yesterday

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we were thinking about it yesterday, but we were afraid that this might happen also in pydra Workflow itself, and has nothing to do with jupyter.

Just to be clear all tests pass without closing the loop at all, it's "just" a best practice, and I'm not sure when this might be a problem.

@mgxd can comment as well

Copy link
Contributor

Choose a reason for hiding this comment

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

a) a loop should be opened only when the program is not already in a loop
b) a loop should be closed only if the loop has been opened by the program

Copy link
Contributor

Choose a reason for hiding this comment

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

we can easily detect if the available loop is currently running, and avoid closing it, but we'll still need to import / activate nest_asyncio to allow running tasks through jupyter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@satra - looks like this is not issue create by jupyter, but newer version of tornado, and it looks like this is still not fixed. It works fine (at least for my simple example, will be testing more) if older version of tornado is used tornado==4.5.3

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

didn't read all posts, but you can find more here: jupyter/notebook#3397

@@ -60,6 +60,7 @@ def __init__(
self,
func: ty.Callable,
output_spec: ty.Optional[BaseSpec] = None,
output_names=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

no output_names - if needed to be specified they should use output_spec

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps an example we should work towards is how to annotate an existing function via the to_task decorator

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking that output_names could be the easier option

Copy link
Contributor

Choose a reason for hiding this comment

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

i agree it would be easier, but we want them to do it through proper annotation. since we will want people to provide type hints as well eventually.

so we should see if we can add __annotations__ to the function using the decorator and adding arguments to the decorator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, will work on it

@codecov
Copy link

codecov bot commented Jul 17, 2019

Codecov Report

Merging #76 into master will decrease coverage by <.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
- Coverage   85.01%   85.01%   -0.01%     
==========================================
  Files          12       13       +1     
  Lines        2109     2115       +6     
  Branches      539      541       +2     
==========================================
+ Hits         1793     1798       +5     
- Misses        231      232       +1     
  Partials       85       85
Flag Coverage Δ
#unittests 85.01% <88.88%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pydra/engine/core.py 85.95% <0%> (-0.32%) ⬇️
pydra/engine/submitter.py 92.63% <100%> (+0.07%) ⬆️
pydra/engine/__init__.py 100% <100%> (ø)
pydra/engine/task.py 81.56% <100%> (+0.4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86ac7ad...bb0af2d. Read the comment docs.

@djarecka djarecka changed the title [fix] small changes and fixes [wip, fix] small changes and fixes Jul 17, 2019
@@ -441,6 +437,8 @@ def __init__(
+ [("_graph", ty.Any)],
bases=(BaseSpec,),
)
else:
raise Exception("Workflow has to have input_spec")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can just do this with types:

 class Workflow(TaskBase):
     def __init__(
         self,
         name,
-        input_spec: ty.Union[ty.List[ty.Text], BaseSpec, None] = None,
+        *,
+        input_spec: ty.Union[ty.List[ty.Text], BaseSpec],
         output_spec: ty.Optional[BaseSpec] = None,
         audit_flags: AuditFlag = AuditFlag.NONE,

Keyword-only arguments don't have to have defaults.

@satra
Copy link
Contributor

satra commented Aug 6, 2019

should this be closed?

@djarecka djarecka closed this Aug 13, 2019
@djarecka djarecka deleted the tutorial branch December 30, 2022 20:46
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.

4 participants