• No results found

14.6 Generating SMPS Input Files From PySP Models

14.6.3 Generating SMPS Input Files

As discussed at the start of this section, the pysp2smps command is used to execute the conversion to SMPS format. A detailed description of the command-line options available with this command can be obtained by executing the command pysp2smps --helpin your shell. Here we discuss some of the basic inputs to this command.

14.6.3.1 Explicit Conversion

Consider the baa99 example inside the pysp/baa99 subdirectory that is distributed with the Pyomo examples (pyomo_examples.zip). Both the reference model and the scenario tree structure are defined in the file baa99.py using PySP callback functions. Ad- ditionally, this model has been annotated to enable explicit conversion to the SMPS format. Assuming one is in this example’s directory, SMPS files can be generated for the model by executing the following shell command:

$\$$ pysp2smps -m baa99.py --basename baa99 \ --output-directory sdinput/baa99 --explicit

Assuming successful execution, this would result in the following files being created: • sdinput/baa99/baa99.lp • sdinput/baa99/baa99.tim • sdinput/baa99/baa99.sto • sdinput/baa99/baa99.lp.det • sdinput/baa99/baa99.lp.row • sdinput/baa99/baa99.lp.col • sdinput/baa99/baa99.sto.struct

The first three files are the main SMPS input, and the remaining four files are left for debugging purposes. These latter files are used to verify the problem structure is the same across the individual scenarios. This script works by constructing each of the scenarios on the scenario tree, and then merging their output into a single .sto file. The .lp.det file includes the deterministic rows of the main LP file. If this does not match for every scenario, then there are places in the model that still need to be declared on one or more of the stochastic data annotations. The .row and the .col files are compared across each scenario to ensure that the number of constraints and variables and their ordering in the LP representation is the same. The .sto.struct file is compared to ensure that the sparsity pattern of the stochastic entries provided by the model annotations is also the same for each scenario. If any of these checks fail, the command will report this as an error.

Warning

The checks implemented by thepysp2smpscommand are not perfect. For example, an error case that will not be caught is the following: a constraint (or the objective) is annotated as having stochastic variable coefficients and the user forgets to include one or more variables from the expression (that also have stochastic coefficients) in the annotation. In this case, the coefficients used in the reference scenario will apply to all of those variables that are missing from the declaration.

The pysp2smps command also supports parallel execution. This can significantly reduce the overall time required to produce the SMPS files when there are many scenarios. Parallel execution using PySP’s Pyro-based tools can be performed using the steps below. Note that each of these commands can be launched in the background inside the same shell or in their own separate shells.

1. Start the Pyro name server: $\$$ pyomo_ns -n localhost

1. Start the Pyro dispatch server: $\$$ dispatch_srvr -n localhost

1. Start 8 ScenarioTree Servers (for the 625 baa99 scenarios)

$\$$ mpirun -np 8 scenariotreeserver --pyro-host=localhost

1. Run pysp2smps using the Pyro ScenarioTree Manager $\$$ pysp2smps -m baa99.py --basename baa99 \

--output-directory sdinput/baa99 --explicit \ --pyro-required-scenariotreeservers=8 \

--pyro-host=localhost --scenario-tree-manager=pyro

An annotated version of the farmer example is also provided. The model file can be found in the pysp/farmer/smps_model examples subdirectory. Note that the scenario tree for this model is defined in a separate file. When launching the pysp2smps command, a scenario tree structure file can be provided via the --scenario-tree-location (-s) command-line option. For example, assuming one is in the pysp/farmer subdirectory, the farmer model can be converted to SMPS files using the command:

$\$$ pysp2smps -m smps_model/ReferenceModel.py \

-s scenariodata/ScenarioStructure.dat --basename farmer \ --output-directory sdinput/farmer --explicit

Note that the files created by the pysp2smps command by default use shortened symbols that do not match the names of the variables and constraints declared on the Pyomo model. This is for efficiency reasons as using fully qualified component names can result in significantly larger files. However, it can be useful in debugging situations to generate the SMPS files using the original component names. To do this, simply add the command-line option --symbolic-solver-labels to the command string.

14.6.3.2 Implicit Conversion (Beta) Under Construction. . .

Chapter 15

Suffixes

Suffixes provide a mechanism for declaring extraneous model data, which can be used in a number of contexts. Most commonly, suffixes are used by solver plugins to store extra information about the solution of a model. This and other suffix functionality is made available to the modeler through the use of the Suffix component class. Uses of Suffix include:

• Importing extra information from a solver about the solution of a mathematical program (e.g., constraint duals, variable reduced costs, basis information).

• Exporting information to a solver or algorithm to aid in solving a mathematical program (e.g., warm-starting information, variable branching priorities).

• Tagging modeling components with local data for later use in advanced scripting algorithms.

15.1

Suffix Notation and the Pyomo NL File Interface

The Suffix component used in Pyomo has been adapted from the suffix notation used in the modeling language AMPL[AMPL]. Therefore, it follows naturally that AMPL style suffix functionality is fully available using Pyomo’s NL file interface. For information on AMPL style suffixes the reader is referred to the AMPL website:

http://www.ampl.com

A number of scripting examples that highlight the use AMPL style suffix functionality are available in the examples/pyomo/ suffixesdirectory distributed with Pyomo.