Skip to content

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

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

Merged
Merged
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
11 changes: 11 additions & 0 deletions doc/src/generic_cylinders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ 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. The ``hub_dict``,
``list_of_spoke_dict``, and ``cfg`` object will be passed to it.
See ``generic_cylinders.py`` for details.


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

Expand Down
10 changes: 3 additions & 7 deletions mpisppy/generic_cylinders.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,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 @@ -390,9 +386,9 @@ 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)
module.hub_and_spoke_dict_callback(hub_dict, list_of_spoke_dict)
if hasattr(module,'hub_and_spoke_dict_callback'):
module.hub_and_spoke_dict_callback(hub_dict, list_of_spoke_dict, cfg)


wheel = WheelSpinner(hub_dict, list_of_spoke_dict)
wheel.spin()
Expand Down
Loading