|
| 1 | + |
| 2 | +.. _stochastics: |
| 3 | + |
| 4 | +Stochastic Programming |
| 5 | +====================== |
| 6 | + |
| 7 | +The Stochastics extension in Temoa v4 provides support for stochastic programming using the `mpi-sppy <https://github.com/Pyomo/mpi-sppy>`_ library. This allows for decision-making under uncertainty by considering multiple scenarios simultaneously and finding an optimal "first-stage" decision that minimizes the expected cost over all scenarios. |
| 8 | + |
| 9 | +Stochastic programming is particularly useful for modeling uncertainties in future costs, demands, or resource availability. |
| 10 | + |
| 11 | +Dependencies |
| 12 | +------------ |
| 13 | + |
| 14 | +The stochastics extension requires the ``mpi-sppy`` package. You can install it using ``uv``: |
| 15 | + |
| 16 | +.. code-block:: bash |
| 17 | +
|
| 18 | + uv add mpi-sppy |
| 19 | +
|
| 20 | +Or using ``pip``: |
| 21 | + |
| 22 | +.. code-block:: bash |
| 23 | +
|
| 24 | + pip install mpi-sppy |
| 25 | +
|
| 26 | +Configuration |
| 27 | +------------- |
| 28 | + |
| 29 | +To run Temoa in stochastic mode, you need to modify your main configuration TOML file and provide an additional stochastic configuration file. |
| 30 | + |
| 31 | +Main Configuration TOML |
| 32 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 33 | + |
| 34 | +Set the ``scenario_mode`` to ``"stochastic"`` and add a ``[stochastic]`` section: |
| 35 | + |
| 36 | +.. code-block:: toml |
| 37 | +
|
| 38 | + scenario_mode = "stochastic" |
| 39 | +
|
| 40 | + # ... other standard options ... |
| 41 | +
|
| 42 | + [stochastic] |
| 43 | + # Path to the stochastic configuration file, relative to this file |
| 44 | + stochastic_config = "stochastic_config.toml" |
| 45 | +
|
| 46 | +Stochastic Configuration TOML |
| 47 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 48 | + |
| 49 | +The stochastic configuration file defines the scenarios, their probabilities, and the data perturbations associated with each scenario. |
| 50 | + |
| 51 | +.. code-block:: toml |
| 52 | +
|
| 53 | + # Define the scenarios |
| 54 | + [scenarios] |
| 55 | + # Each key is a scenario name, and the value is its probability |
| 56 | + # Probabilities must sum to 1.0 |
| 57 | + low_cost = 0.5 |
| 58 | + high_cost = 0.5 |
| 59 | +
|
| 60 | + # Define perturbations for a specific scenario |
| 61 | + [[perturbations]] |
| 62 | + scenario = "low_cost" |
| 63 | + table = "cost_variable" |
| 64 | + # Filter specifies which rows in the table to perturb |
| 65 | + filter = { tech = "IMPHCO1" } |
| 66 | + # Action can be "multiply", "add", or "set" (defaults to "set") |
| 67 | + action = "multiply" |
| 68 | + value = 0.5 |
| 69 | +
|
| 70 | + [[perturbations]] |
| 71 | + scenario = "high_cost" |
| 72 | + table = "cost_variable" |
| 73 | + filter = { tech = "IMPHCO1" } |
| 74 | + action = "multiply" |
| 75 | + value = 1.5 |
| 76 | +
|
| 77 | +Perturbation Options |
| 78 | +^^^^^^^^^^^^^^^^^^^^ |
| 79 | + |
| 80 | +Currently, the following fields are required for each perturbation: |
| 81 | + |
| 82 | +* **scenario**: The name of the scenario to which this perturbation applies. |
| 83 | +* **table**: The Temoa parameter (database table) to perturb (e.g., ``cost_variable``, ``demand``, ``capacity_factor_process``). |
| 84 | +* **filter**: A dictionary of column-value pairs used to identify specific rows. Since the extension uses the dynamic manifest from ``HybridLoader``, any column belonging to the table's index can be used for filtering. |
| 85 | +* **action**: The operation to perform. Supported values: |
| 86 | + * ``multiply``: Multiply the base value by ``value``. |
| 87 | + * ``add``: Add ``value`` to the base value. |
| 88 | + * ``set``: Replace the base value with ``value``. |
| 89 | +* **value**: The numeric value used in the perturbation action. |
| 90 | + |
| 91 | +How it Works |
| 92 | +------------ |
| 93 | + |
| 94 | +When running in stochastic mode, Temoa: |
| 95 | + |
| 96 | +1. Loads the base data from the input database. |
| 97 | +2. Identifies the "first-stage" variables. In the current implementation, all decisions in the first time period are considered first-stage. |
| 98 | +3. Orchestrates multiple scenario runs using the ``mpi-sppy`` Extensive Form (EF) solver. |
| 99 | +4. For each scenario, the ``scenario_creator`` applies the specified perturbations to the base data and builds a Pyomo model instance. |
| 100 | +5. The EF solver binds the first-stage variables across all scenarios (non-anticipativity constraints) and optimizes the total expected cost. |
| 101 | +6. The terminal output reports the Stochastic Expected Value. |
| 102 | + |
| 103 | +Limitations |
| 104 | +----------- |
| 105 | + |
| 106 | +* **Two-Stage Only**: While ``mpi-sppy`` supports multi-stage stochastic programming, the current Temoa integration is tailored for two-stage problems where the first time period constitutes the first stage. |
| 107 | +* **Result Persistence**: Currently, only the expected objective value and summary logs are produced. Detailed per-scenario result persistence to the database is under development. |
0 commit comments