Running a Single-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 Dates

Data

Note

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
PropertyValue
Name
Description
System Units BaseSYSTEM_BASE
Base Power100.0
Base Frequency60.0
Num Components504
Static Components
TypeCount
ACBus73
Arc109
Area3
FixedAdmittance3
HydroDispatch1
Line105
LoadZone21
PowerLoad51
RenewableDispatch29
RenewableNonDispatch31
SynchronousCondenser3
TapTransformer15
ThermalStandard54
TwoTerminalGenericHVDCLine1
VariableReserve{ReserveDown}1
VariableReserve{ReserveUp}4
StaticTimeSeries Summary
owner_typeowner_categorynametime_series_typeinitial_timestampresolutioncounttime_step_count
StringStringStringStringStringDates.CompoundPeriodInt64Int64
AreaComponentmax_active_powerSingleTimeSeries2020-01-01T00:00:001 hour38784
FixedAdmittanceComponentmax_active_powerSingleTimeSeries2020-01-01T00:00:001 hour38784
HydroDispatchComponentmax_active_powerSingleTimeSeries2020-01-01T00:00:001 hour18784
PowerLoadComponentmax_active_powerSingleTimeSeries2020-01-01T00:00:001 hour518784
RenewableDispatchComponentmax_active_powerSingleTimeSeries2020-01-01T00:00:001 hour298784
RenewableNonDispatchComponentmax_active_powerSingleTimeSeries2020-01-01T00:00:001 hour318784
VariableReserveComponentrequirementSingleTimeSeries2020-01-01T00:00:001 hour58784
Forecast Summary
owner_typeowner_categorynametime_series_typeinitial_timestampresolutioncounthorizonintervalwindow_count
StringStringStringStringStringDates.CompoundPeriodInt64Dates.CompoundPeriodDates.CompoundPeriodInt64
AreaComponentmax_active_powerDeterministicSingleTimeSeries2020-01-01T00:00:001 hour32 days1 day365
FixedAdmittanceComponentmax_active_powerDeterministicSingleTimeSeries2020-01-01T00:00:001 hour32 days1 day365
HydroDispatchComponentmax_active_powerDeterministicSingleTimeSeries2020-01-01T00:00:001 hour12 days1 day365
PowerLoadComponentmax_active_powerDeterministicSingleTimeSeries2020-01-01T00:00:001 hour512 days1 day365
RenewableDispatchComponentmax_active_powerDeterministicSingleTimeSeries2020-01-01T00:00:001 hour292 days1 day365
RenewableNonDispatchComponentmax_active_powerDeterministicSingleTimeSeries2020-01-01T00:00:001 hour312 days1 day365
VariableReserveComponentrequirementDeterministicSingleTimeSeries2020-01-01T00:00:001 hour52 days1 day365

Define a problem specification with a ProblemTemplate

You can create an empty template with:

template_uc = ProblemTemplate()
Network Model
Network ModelCopperPlatePowerModel
Slacksfalse
PTDFfalse
DualsNone
HVDC Network ModelNone
Device Models
Device TypeFormulationSlacks

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 = 0
Tip

The 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 = 0

Results 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
FuelConsumptionExpression__ThermalStandard
ProductionCostExpression__RenewableDispatch
CurtailmentCostExpression__RenewableDispatch
VOMCostExpression__RenewableDispatch
ProductionCostExpression__HydroDispatch
VOMCostExpression__ThermalStandard
ShutDownCostExpression__ThermalStandard
FuelCostExpression__ThermalStandard
ProductionCostExpression__ThermalStandard
FixedCostExpression__ThermalStandard
FixedCostExpression__RenewableDispatch
StartUpCostExpression__ThermalStandard
ActivePowerBalance__System
PowerSimulations Problem Parameters Results
RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Spin_Up_R1
ActivePowerTimeSeriesParameter__PowerLoad
RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Spin_Up_R2
RequirementTimeSeriesParameter__VariableReserve__ReserveDown__Reg_Down
RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Spin_Up_R3
ActivePowerTimeSeriesParameter__HydroDispatch
ActivePowerTimeSeriesParameter__RenewableNonDispatch
RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Reg_Up
ActivePowerTimeSeriesParameter__RenewableDispatch
PowerSimulations Problem Variables Results
StartVariable__ThermalStandard
StopVariable__ThermalStandard
ActivePowerReserveVariable__VariableReserve__ReserveDown__Reg_Down
ActivePowerVariable__ThermalStandard
ActivePowerReserveVariable__VariableReserve__ReserveUp__Spin_Up_R3
ActivePowerVariable__HydroDispatch
ActivePowerReserveVariable__VariableReserve__ReserveUp__Spin_Up_R2
ActivePowerReserveVariable__VariableReserve__ReserveUp__Spin_Up_R1
OnVariable__ThermalStandard
ActivePowerReserveVariable__VariableReserve__ReserveUp__Reg_Up
ActivePowerVariable__RenewableDispatch

Optimizer Stats

The optimizer summary is included

get_optimizer_stats(res)
detailed_statsobjective_valuetermination_statusprimal_statusdual_statussolver_solve_timeresult_counthas_valueshas_dualsobjective_boundrelative_gapdual_objective_valuesolve_timebarrier_iterationssimplex_iterationsnode_counttimed_solve_timetimed_calculate_aux_variablestimed_calculate_dual_variablessolve_bytes_allocsec_in_gc
BoolFloat64Int64Int64Int64Float64Int64BoolBoolMissingMissingMissingFloat64MissingMissingMissingFloat64Float64Float64Float64Float64
false2.356823683788018e6110NaN1falsefalsemissingmissingmissing0.6916055679321289missingmissingmissing0.8264367270.0015883880.0020462093.4638256e70.0

Objective Function Value

get_objective_value(res)
2.356823683788018e6

Variable, 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…
  "StopVariable__ThermalSt… => 1296×3 DataFrame…
  "ActivePowerReserveVaria… => 1224×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")
686 rows omitted
DateTimenamevalue
Dates.DateTimeStringFloat64
2020-01-01T00:00:00122_WIND_1713.1999999999999
2020-01-01T01:00:00122_WIND_1712.8
2020-01-01T02:00:00122_WIND_1708.4
2020-01-01T03:00:00122_WIND_1710.7
2020-01-01T04:00:00122_WIND_1701.4
2020-01-01T05:00:00122_WIND_1682.5
2020-01-01T06:00:00122_WIND_1614.7
2020-01-01T07:00:00122_WIND_1517.7
2020-01-01T08:00:00122_WIND_1426.6
2020-01-01T09:00:00122_WIND_1274.19999999999993

Plotting

Take a look at the plotting capabilities in PowerGraphics.jl