Running a Simple-Step Problem
To follow along, you can download this tutorial as a Julia script (.jl) or Jupyter notebook (.ipynb).
Introduction
PowerSimulations.jl supports the construction and solution of optimal power system scheduling problems (Operations Problems). Operations problems form the fundamental building blocks for sequential simulations. This example shows how to specify and customize the mathematics that will be applied to the data with a ProblemTemplate, build and execute a DecisionModel, and access the results.
using PowerSystems
using PowerSimulations
using HydroPowerSimulations
using PowerSystemCaseBuilder
using HiGHS # solver
using DatesData
PowerSystemCaseBuilder.jl is a helper library that makes it easier to reproduce examples in the documentation and tutorials. Normally you would pass your local files to create the system data instead of calling the function build_system. For more details visit PowerSystemCaseBuilder Documentation
sys = build_system(PSISystems, "modified_RTS_GMLC_DA_sys")| System | |
| Property | Value |
|---|---|
| Name | |
| Description | |
| System Units Base | SYSTEM_BASE |
| Base Power | 100.0 |
| Base Frequency | 60.0 |
| Num Components | 504 |
| Static Components | |
| Type | Count |
|---|---|
| ACBus | 73 |
| Arc | 109 |
| Area | 3 |
| FixedAdmittance | 3 |
| HydroDispatch | 1 |
| Line | 105 |
| LoadZone | 21 |
| PowerLoad | 51 |
| RenewableDispatch | 29 |
| RenewableNonDispatch | 31 |
| SynchronousCondenser | 3 |
| TapTransformer | 15 |
| ThermalStandard | 54 |
| TwoTerminalGenericHVDCLine | 1 |
| VariableReserve{ReserveDown} | 1 |
| VariableReserve{ReserveUp} | 4 |
| StaticTimeSeries Summary | |||||||
| owner_type | owner_category | name | time_series_type | initial_timestamp | resolution | count | time_step_count |
|---|---|---|---|---|---|---|---|
| String | String | String | String | String | Dates.CompoundPeriod | Int64 | Int64 |
| Area | Component | max_active_power | SingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 3 | 8784 |
| FixedAdmittance | Component | max_active_power | SingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 3 | 8784 |
| HydroDispatch | Component | max_active_power | SingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 1 | 8784 |
| PowerLoad | Component | max_active_power | SingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 51 | 8784 |
| RenewableDispatch | Component | max_active_power | SingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 29 | 8784 |
| RenewableNonDispatch | Component | max_active_power | SingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 31 | 8784 |
| VariableReserve | Component | requirement | SingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 5 | 8784 |
| Forecast Summary | |||||||||
| owner_type | owner_category | name | time_series_type | initial_timestamp | resolution | count | horizon | interval | window_count |
|---|---|---|---|---|---|---|---|---|---|
| String | String | String | String | String | Dates.CompoundPeriod | Int64 | Dates.CompoundPeriod | Dates.CompoundPeriod | Int64 |
| Area | Component | max_active_power | DeterministicSingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 3 | 2 days | 1 day | 365 |
| FixedAdmittance | Component | max_active_power | DeterministicSingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 3 | 2 days | 1 day | 365 |
| HydroDispatch | Component | max_active_power | DeterministicSingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 1 | 2 days | 1 day | 365 |
| PowerLoad | Component | max_active_power | DeterministicSingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 51 | 2 days | 1 day | 365 |
| RenewableDispatch | Component | max_active_power | DeterministicSingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 29 | 2 days | 1 day | 365 |
| RenewableNonDispatch | Component | max_active_power | DeterministicSingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 31 | 2 days | 1 day | 365 |
| VariableReserve | Component | requirement | DeterministicSingleTimeSeries | 2020-01-01T00:00:00 | 1 hour | 5 | 2 days | 1 day | 365 |
Define a problem specification with a ProblemTemplate
You can create an empty template with:
template_uc = ProblemTemplate()| Network Model | |
| Network Model | CopperPlatePowerModel |
| Slacks | false |
| PTDF | false |
| Duals | None |
| HVDC Network Model | None |
| Device Models | ||
| Device Type | Formulation | Slacks |
|---|---|---|
Now, you can add a DeviceModel for each device type to create an assignment between PowerSystems device types and the subtypes of AbstractDeviceFormulation. PowerSimulations has a variety of different AbstractDeviceFormulation subtypes that can be applied to different PowerSystems device types, each dispatching to different methods for populating optimization problem objectives, variables, and constraints. Documentation on the formulation options for various devices can be found in the formulation library docs
Branch Formulations
Here is an example of relatively standard branch formulations. Other formulations allow for selective enforcement of transmission limits and greater control on transformer settings.
set_device_model!(template_uc, Line, StaticBranch)
set_device_model!(template_uc, Transformer2W, StaticBranch)
set_device_model!(template_uc, TapTransformer, StaticBranch)Injection Device Formulations
Here we define template entries for all devices that inject or withdraw power on the network. For each device type, we can define a distinct AbstractDeviceFormulation. In this case, we're defining a basic unit commitment model for thermal generators, curtailable renewable generators, and fixed dispatch (net-load reduction) formulations for HydroDispatch and RenewableNonDispatch devices.
set_device_model!(template_uc, ThermalStandard, ThermalStandardUnitCommitment)
set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template_uc, PowerLoad, StaticPowerLoad)
set_device_model!(template_uc, HydroDispatch, HydroDispatchRunOfRiver)
set_device_model!(template_uc, RenewableNonDispatch, FixedOutput)Service Formulations
We have two VariableReserve types, parameterized by their direction. So, similar to creating DeviceModels, we can create ServiceModels. The primary difference being that DeviceModel objects define how constraints get created, while ServiceModel objects define how constraints get modified.
set_service_model!(template_uc, VariableReserve{ReserveUp}, RangeReserve)
set_service_model!(template_uc, VariableReserve{ReserveDown}, RangeReserve)Network Formulations
Finally, we can define the transmission network specification that we'd like to model. For simplicity, we'll choose a copper plate formulation. But there are dozens of specifications available through an integration with PowerModels.jl.
Note that many formulations will require appropriate data and may be computationally intractable
set_network_model!(template_uc, NetworkModel(CopperPlatePowerModel))DecisionModel
Now that we have a System and a ProblemTemplate, we can put the two together to create a DecisionModel that we solve.
Optimizer
It's most convenient to define an optimizer instance upfront and pass it into the DecisionModel constructor. For this example, we can use the free HiGHS solver with a relatively relaxed MIP gap (ratioGap) setting to improve speed.
solver = optimizer_with_attributes(HiGHS.Optimizer, "mip_rel_gap" => 0.5)MathOptInterface.OptimizerWithAttributes(HiGHS.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute, Any}[MathOptInterface.RawOptimizerAttribute("mip_rel_gap") => 0.5])Build a DecisionModel
The construction of a DecisionModel essentially applies a ProblemTemplate to System data to create a JuMP model.
problem = DecisionModel(template_uc, sys; optimizer = solver, horizon = Hour(24))
build!(problem; output_dir = mktempdir())InfrastructureSystems.Optimization.ModelBuildStatusModule.ModelBuildStatus.BUILT = 0The principal component of the DecisionModel is the JuMP model. But you can serialize to a file using the following command:
serialize_optimization_model(problem, save_path)Keep in mind that if the setting "store_variable_names" is set to False then the file won't show the model's names.
Solve a DecisionModel
solve!(problem)InfrastructureSystems.Simulation.RunStatusModule.RunStatus.SUCCESSFULLY_FINALIZED = 0Results Inspection
PowerSimulations collects the DecisionModel results into a OptimizationProblemResults struct:
res = OptimizationProblemResults(problem)Start: 2020-01-01T00:00:00
End: 2020-01-01T23:00:00
Resolution: 60 minutes
| PowerSimulations Problem Auxiliary variables Results |
| TimeDurationOn__ThermalStandard |
| TimeDurationOff__ThermalStandard |
| HydroEnergyOutput__HydroDispatch |
| PowerSimulations Problem Expressions Results |
| ProductionCostExpression__ThermalStandard |
| ProductionCostExpression__HydroDispatch |
| ActivePowerBalance__System |
| ProductionCostExpression__RenewableDispatch |
| FuelConsumptionExpression__ThermalStandard |
| PowerSimulations Problem Parameters Results |
| RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Spin_Up_R2 |
| RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Spin_Up_R1 |
| ActivePowerTimeSeriesParameter__RenewableNonDispatch |
| RequirementTimeSeriesParameter__VariableReserve__ReserveDown__Reg_Down |
| ActivePowerTimeSeriesParameter__HydroDispatch |
| ActivePowerTimeSeriesParameter__RenewableDispatch |
| RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Reg_Up |
| ActivePowerTimeSeriesParameter__PowerLoad |
| RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Spin_Up_R3 |
| PowerSimulations Problem Variables Results |
| ActivePowerReserveVariable__VariableReserve__ReserveUp__Spin_Up_R3 |
| ActivePowerVariable__ThermalStandard |
| ActivePowerReserveVariable__VariableReserve__ReserveUp__Reg_Up |
| StopVariable__ThermalStandard |
| ActivePowerVariable__HydroDispatch |
| StartVariable__ThermalStandard |
| ActivePowerReserveVariable__VariableReserve__ReserveDown__Reg_Down |
| ActivePowerVariable__RenewableDispatch |
| ActivePowerReserveVariable__VariableReserve__ReserveUp__Spin_Up_R1 |
| ActivePowerReserveVariable__VariableReserve__ReserveUp__Spin_Up_R2 |
| OnVariable__ThermalStandard |
Optimizer Stats
The optimizer summary is included
get_optimizer_stats(res)| detailed_stats | objective_value | termination_status | primal_status | dual_status | solver_solve_time | result_count | has_values | has_duals | objective_bound | relative_gap | dual_objective_value | solve_time | barrier_iterations | simplex_iterations | node_count | timed_solve_time | timed_calculate_aux_variables | timed_calculate_dual_variables | solve_bytes_alloc | sec_in_gc |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Bool | Float64 | Int64 | Int64 | Int64 | Float64 | Int64 | Bool | Bool | Missing | Missing | Missing | Float64 | Missing | Missing | Missing | Float64 | Float64 | Float64 | Float64 | Float64 |
| false | 2.356823683788018e6 | 1 | 1 | 0 | NaN | 1 | false | false | missing | missing | missing | 1.076258897781372 | missing | missing | missing | 1.26161452 | 0.002114362 | 0.002748654 | 3.4638256e7 | 0.0 |
Objective Function Value
get_objective_value(res)2.356823683788018e6Variable, Parameter, Auxiliary Variable, Dual, and Expression Values
The solution value data frames for variables, parameters, auxiliary variables, duals, and expressions can be accessed using the read_ methods:
read_variables(res)Dict{String, DataFrame} with 11 entries:
"ActivePowerReserveVaria… => 1224×3 DataFrame…
"ActivePowerReserveVaria… => 1224×3 DataFrame…
"StopVariable__ThermalSt… => 1296×3 DataFrame…
"OnVariable__ThermalStan… => 1296×3 DataFrame…
"ActivePowerVariable__Hy… => 24×3 DataFrame…
"ActivePowerReserveVaria… => 432×3 DataFrame…
"StartVariable__ThermalS… => 1296×3 DataFrame…
"ActivePowerVariable__Th… => 1296×3 DataFrame…
"ActivePowerVariable__Re… => 696×3 DataFrame…
"ActivePowerReserveVaria… => 408×3 DataFrame…
"ActivePowerReserveVaria… => 384×3 DataFrame…Or, you can read a single parameter value for parameters that exist in the results.
list_parameter_names(res)
read_parameter(res, "ActivePowerTimeSeriesParameter__RenewableDispatch")| DateTime | name | value |
|---|---|---|
| Dates.DateTime | String | Float64 |
| 2020-01-01T00:00:00 | 122_WIND_1 | 713.1999999999999 |
| 2020-01-01T01:00:00 | 122_WIND_1 | 712.8 |
| 2020-01-01T02:00:00 | 122_WIND_1 | 708.4 |
| 2020-01-01T03:00:00 | 122_WIND_1 | 710.7 |
| 2020-01-01T04:00:00 | 122_WIND_1 | 701.4 |
| 2020-01-01T05:00:00 | 122_WIND_1 | 682.5 |
| 2020-01-01T06:00:00 | 122_WIND_1 | 614.7 |
| 2020-01-01T07:00:00 | 122_WIND_1 | 517.7 |
| 2020-01-01T08:00:00 | 122_WIND_1 | 426.6 |
| 2020-01-01T09:00:00 | 122_WIND_1 | 274.19999999999993 |
| ⋮ | ⋮ | ⋮ |
Plotting
Take a look at the plotting capabilities in PowerGraphics.jl