PySP conversion

Details

To use a PySP model in mpi-sppy, the critical step is to instantiate a PySPModel object. The API for the class is:

class mpisppy.utils.pysp_model.pysp_model.PySPModel(model, scenario_tree, data_dir=None)[source]

Bases: object

A class for instantiating PySP models for use in mpisppy.

Parameters:
  • model – The reference scenario model. Can be set to Pyomo model or the name of a file containing a Pyomo model. For historical reasons, this argument can also be set to a directory name where it is assumed a file named ReferenceModel.py exists.

  • scenario_tree – The scenario tree. Can be set to a Pyomo model, a file containing a Pyomo model, or a .dat file containing data for an abstract scenario tree model representation, which defines the structure of the scenario tree. It can also be a .py file that contains a networkx scenario tree or a networkx scenario tree object. For historical reasons, this argument can also be set to a directory name where it is assumed a file named ScenarioStructure.dat exists.

  • data_dir – Directory containing .dat files necessary for building the scenario instances associated with the scenario tree. This argument is required if no directory information can be extracted from the first two arguments and the reference model is an abstract Pyomo model. Otherwise, it is not required or the location will be inferred from the scenario tree location (first) or from the reference model location (second), where it is assumed the data files reside in the same directory.

Properties:
all_scenario_names (list):

A list of scenario names based on the pysp model for use in mpisppy

all_node_names (list):

A list of all node names based on the pysp model for use in mpisppy

scenario_creator (fct):

A scenario creator function based on the pysp model for use in mpisppy

scenario_denouement (fct):

A blank scenario_denouement function for use in mpisppy

property all_nodenames
property all_scenario_names
close()[source]
property scenario_creator
scenario_creator_callback(scenario_name, **kwargs)[source]
property scenario_denouement

Once a PySPModel object and an options dictionary have been created, an ExtensiveForm or PH object can be created using the PySPModel object attributes.

As reflected in the API for the PySPModel class there are many ways to specify the reference model and scenario tree information in PySP. A few examples are given in directory examples/farmer/from_pysp. Here are few notes about these examples:

  • They are written mainly to provide code examples.

  • How to form the EF is shown in, e.g. abstract.py

A more advanced example utilizing the hub-and-spoke system is available in the file examples/hydro/hydro_cylinders_pysp.py