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

Provide wrapper for functions that modify inputs #625

Open
effigies opened this issue Mar 7, 2023 · 2 comments
Open

Provide wrapper for functions that modify inputs #625

effigies opened this issue Mar 7, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@effigies
Copy link
Contributor

effigies commented Mar 7, 2023

In #623, @tclose added a function that modifies its input as a reliable reproducer of a task whose input hash changes after execution, resulting in a deadlocked workflow as the task is complete but its results are no longer findable in the cache directory.

In a comment I proposed an addition to the pydra.mark module:


If someone has an unsafe function, they're going to need to either rewrite or wrap it themselves, or we can provide a standard tool with straightforward semantics:

def wrap_unsafe(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        return func(*deepcopy(args), **deepcopy(kwargs))
    return wrapper

So we could write:

safe_task = task(wrap_unsafe(unsafe_func))

And if somebody has control over the function but is lazy or (more charitably) finds an explicit copy cluttering, they could write:

@task
@wrap_unsafe
def f(x):
    x.a = 2
    return x
@tclose
Copy link
Contributor

tclose commented Mar 8, 2023

In #623 you mentioned a check at the end of the task to see whether the task has altered its input hash. I think this is a good idea. Should that be included in this issue or in a separate one?

@effigies
Copy link
Contributor Author

effigies commented Mar 8, 2023

I think it makes sense as part of this issue. Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants