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

Allow function as default values for WorkChain input. #1604

Closed
mottetm opened this issue May 29, 2018 · 3 comments · Fixed by #3465
Closed

Allow function as default values for WorkChain input. #1604

mottetm opened this issue May 29, 2018 · 3 comments · Fixed by #3465

Comments

@mottetm
Copy link

mottetm commented May 29, 2018

Would it be possible to allow the runtime generation of the default node of a Worchain input.

This would allow to have, for example, random seeds stored in inputs node allowing better reproduciblity:

cls.input('seed', valid_type=Int, default=lambda: Int(np.random.randint(2**32 - 1)))
@ltalirz
Copy link
Member

ltalirz commented Jun 21, 2018

Isn't this more an issue of convenience rather than of better reproducibility?
At the moment, I guess you simply generate the random number outside the workchain and pass it in when you run it, right? I don't see how this affects reproducibility.

Also, what about

cls.input('seed', valid_type=Int, default=Int(np.random.randint(2**32 - 1)))

Anyhow, mentioning the experts @muhrin and @sphuber .

@mottetm
Copy link
Author

mottetm commented Jun 21, 2018

Yes the current best way is to generate the seed outside. I just don't find it very convenient.

Concerning:

cls.input('seed', valid_type=Int, default=Int(np.random.randint(2**32 - 1)))

If you run the process several time without reloading the module, the seed will be the same.

return ToContext(p1=self.submit(ProcessWithSeed, options=opt1), 
                 p2=self.submit(ProcessWithSeed, options=opt2))

But you probably want two seeds and them to be stored in an input node for your calculation.

@mottetm
Copy link
Author

mottetm commented Jun 21, 2018

And the solution seems quite simple.

if callable(default):
    default = default()

If it is added before the checks, it shouldn't cause any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants