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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/src/generic_cylinders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ needed even with the ``--help`` argument, e.g.,
.. Note::
This functionality is at the level of alpha-release.

Advanced manipulation of the hub and spokes dicts
-------------------------------------------------

Advanced users might want to directly manipulate the hub and spoke dicts
immediately before ``spin_the_wheel()`` is called. If the module (or class)
contains a function called ``hub_and_spoke_dict_callback()``, it will be called
immediately before the ``WheelSpinner`` object is created, and the ``hub_dict`` and
``list_of_spoke_dict`` will be passed to it. See ``generic_cylinders.py`` for details.


Pickled Scenarios
-----------------

Expand Down
8 changes: 2 additions & 6 deletions mpisppy/generic_cylinders.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ def _parse_args(m):
default=None)
# TBD - think about adding directory for json options files

cfg.add_to_config("hub_and_spoke_dict_callback",
description="[FOR EXPERTS ONLY] Module that contains the function hub_and_spoke_dict_callback that will be passed the hubdict and list of spokedicts prior to spin-the-wheel (last chance for intervention)",
domain=str,
default=None)

cfg.parse_command_line(f"mpi-sppy for {cfg.module_name}")

Expand Down Expand Up @@ -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.



wheel = WheelSpinner(hub_dict, list_of_spoke_dict)
wheel.spin()

Expand Down
Loading