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

Making hub and spoke dict callback a function of the model module instead of a separate module #499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tvalenciaz
Copy link
Contributor

@tvalenciaz tvalenciaz commented Mar 27, 2025

I think having the callback that does hub and spoke dict manipulation in generic_cylinders.py as a function within the model module is more convenient because that manipulation can be dependent on the value of the config options cfg. The same could be achieved by just also passing cfg to the callback the way it is written now but in the case where the user defines a class within their model module, having the callback be a method of the class makes cfg-dependent implementation straightforward.

@@ -367,10 +363,10 @@ def _do_decomp(module, cfg, scenario_creator, scenario_creator_kwargs, scenario_
list_of_spoke_dict.append(reduced_costs_spoke)

# if the user dares, let them mess with the hubdict prior to solve
if cfg.hub_and_spoke_dict_callback is not None:
module = sputils.module_name_to_module(cfg.hub_and_spoke_dict_callback)
if hasattr(module,'hub_and_spoke_dict_callback'):
module.hub_and_spoke_dict_callback(hub_dict, list_of_spoke_dict)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Related to this PR: should this callback also have cfg explicitly passed into it? E.g.,

Suggested change
module.hub_and_spoke_dict_callback(hub_dict, list_of_spoke_dict)
module.hub_and_spoke_dict_callback(hub_dict, list_of_spoke_dict, cfg)

I guess with your comment there's a different way to get the config object from this function?

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 think passing it keeps it more general and perhaps easy to use, so I'm in favor of adding it :)
I use a class inside my model module, so when the class gets initialized I save what I need from cfg to self.some_attribute. Since my function is a method of that class, I am accessing what I need from cfg through that attribute. But having it explicitly passed is more flexible for non-class-oriented modules, so adding it makes sense to me.

Copy link
Collaborator

@bknueven bknueven left a comment

Choose a reason for hiding this comment

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

Happy to merge if we agree on passing the config object into the callback.

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