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

Explain how to use functions from libraries #2798

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

WardLT
Copy link
Contributor

@WardLT WardLT commented Jul 4, 2023

Description

The documentation does not explain that you can create Apps outside of the decorator-based mechanism.
It's a convenient route when you just want to make a "Parsl version" of a function already in a module,
and create Parsl functions programatically.

Type of change

  • Documentation update

Context

Was reviewing code from a user and saw functions similar to:

@python_app
def f(x): 
   from m import f
   return f(x)

I suggested they replace with

from m import f
f = python_app(f)

to make the code more succinct.

It wasn't apparent in the docs that you could do this. I know you can because I'm familiar with function serialization.

@@ -112,7 +141,7 @@ Limitations
There are some limitations on the Python functions that can be converted to apps:

1. Functions should act only on defined input arguments. That is, they should not use script-level or global variables.
2. Functions must explicitly import any required modules.
2. Functions must explicitly import any required modules if they are defined in script which starts Parsl.
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm fairly certain there's more subtlety here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How so?

I'm fairly sure it works this way for functions defined in other files. The main Parsl process will serialize a reference to the location of the function, and the worker will import those libraries as it loads in the function.

That said, my knowledge of Parsl's function serialization is empirical. I don't understand the underlying codebase, just how it has worked for me in practice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

pickle does that, but dill does more complex stuff (including changing behaviour depending on where on the filesystem your Other Files are located...) that is hard to keep in my head

``function_app`` will act as Parsl App function of ``function``.

It is also possible to create wrapped versions of functions, such as ones with pinned arguments.
Parsl just requires first calling :meth:`~functools.update_wrapped` with the wrapped function
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happens if you don't do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should test to be sure. I think we get errors when a function lacks a name, but might be confused with those errors originating from a code which uses Parsl and not Parsl itself.

@benclifford benclifford merged commit 5240e25 into Parsl:master Jul 4, 2023
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