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

Use of mutable kwargs throughout psiflow #14

Open
Andrew-S-Rosen opened this issue Oct 21, 2023 · 4 comments
Open

Use of mutable kwargs throughout psiflow #14

Andrew-S-Rosen opened this issue Oct 21, 2023 · 4 comments

Comments

@Andrew-S-Rosen
Copy link
Contributor

Andrew-S-Rosen commented Oct 21, 2023

def evaluate_dataset(
device: str,
ncores: int,
load_calculator: Callable,
inputs: List[File] = [],
outputs: List[File] = [],
) -> None:

There are many instances in Psiflow where the default arguments are mutable objects. Is this intentional? I would imagine that this would be particularly undesirable and that one should do inputs: List[file] | None = None followed by something like inputs = {} if inputs is None else inputs in the function definition. Are these kwargs intentionally mutable, out of curiosity?

@Andrew-S-Rosen Andrew-S-Rosen changed the title Use of mutable kwargs through psiflow Use of mutable kwargs throughout psiflow Oct 21, 2023
@svandenhaute
Copy link
Member

Not really, this is inspired by the examples in the Parsl docs.
I see your point about this being undesirable. I seem to remember that Parsl demands these arguments to be of type list at all times. I guess we could change all defaults to None, but then take care that each time we're calling the python_app, we supply inputs and outputs as potentially-empty lists such that Parsl won't complain.
Alternatively, we use a default_factory as is done in some of the dataclasses in which mutable defaults are used as well, though I don't think this is standard Python practice for functions.

@Andrew-S-Rosen
Copy link
Contributor Author

Andrew-S-Rosen commented Oct 21, 2023

Ah, I see. So this related to a Parsl constraint with the inputs and outputs kwargs. I'm going to raise an issue in the Parsl repo about this one because the Parsl docs don't really promote best-practices if there are constraints like this. It could make sense for Parsl to accept None and then assume it's {}.

@Andrew-S-Rosen
Copy link
Contributor Author

@svandenhaute: here is a follow up Parsl/parsl#2925 (comment).

@svandenhaute
Copy link
Member

Yeah, I just disabled flake8 to complain about it for now until this is sorted in Parsl.

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

No branches or pull requests

2 participants