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

having a module setup a configuration key #161

Open
vittoriodx7 opened this issue Dec 11, 2024 · 2 comments
Open

having a module setup a configuration key #161

vittoriodx7 opened this issue Dec 11, 2024 · 2 comments

Comments

@vittoriodx7
Copy link

Hello,
I was wondering how I could go about if I wanted to have a module setup some configuration parameters that are later used by another module as setup: e.g. imagine

[pipeline]
modules =  module1 module2

can module1 use something like
configuration.put_double('section', 'name', value)
to setup parameter 'name' in 'section' and then module2 read such configuration?

This is routine in the execute() function of modules, but I cannot make it work for the setup(), in fact trying as I wrote above gives a BlockNameNotFound error, and if I use a place holder and then use replace_double method I get the placeholder value and not the replaced one. I can save it and pass it during execute(), but that would be less ideal for my purposes.

I hope my question is clear.

Thank you,
Vittorio

@joezuntz
Copy link
Owner

Hi Vittorio,

Yes, this behaviour isn't currently supported directly. But there are a few ways to do something like it:

  1. Specify this value yourself in the parameter file, rather than computing it in the module itself. If you put it in a special section called [DEFAULT] then it will be available to any module.

  2. Defer computing this value until the execute function is called, when it can be passed through the data block to subsequent modules like any other value. Then if you returned e.g. a dictionary from the setup function then the value can be stored in that dictionary and it will still be there the next time execute is called, for the next parameter set. So the next time you can just get it out of the dictionary in both modules.

I hope this is useful - let me know if one of these could work for you.

Best wishes,
Joe

@vittoriodx7
Copy link
Author

Dear Joe,
Thanks a lot for your prompt reply.
Both works although they are not elegant for my case.

  1. As the value module1 computes depends itself on configuration of module1 I could make a lookup table in configuration and assert the value I calculate is the tabulated one.
  2. This fan also work, however I make visualization plots in the setup to visualize the data (which depend on the calculated value) so the plots I made would not be corrected by the values I calculate.

Thanks,
Vittorio

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