Skip to content

Commit

Permalink
Merge pull request #1114 from NREL-Sienna/rh/psy4_renaming
Browse files Browse the repository at this point in the history
PSY4 Renaming
  • Loading branch information
jd-lara authored Jun 17, 2024
2 parents f8a63c4 + 0c927e5 commit a530304
Show file tree
Hide file tree
Showing 28 changed files with 174 additions and 129 deletions.
6 changes: 3 additions & 3 deletions docs/src/formulation_library/Branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If Slack variables are enabled:

**Static Parameters**

- ``R^\text{max}`` = `PowerSystems.get_rate(branch)`
- ``R^\text{max}`` = `PowerSystems.get_rating(branch)`

**Objective:**

Expand Down Expand Up @@ -80,7 +80,7 @@ StaticBranchBounds

**Static Parameters**

- ``R^\text{max}`` = `PowerSystems.get_rate(branch)`
- ``R^\text{max}`` = `PowerSystems.get_rating(branch)`

**Objective:**

Expand Down Expand Up @@ -308,7 +308,7 @@ PhaseAngleControl

**Static Parameters**

- ``R^\text{max}`` = `PowerSystems.get_rate(branch)`
- ``R^\text{max}`` = `PowerSystems.get_rating(branch)`
- ``\Theta^\text{min}`` = `PowerSystems.get_phase_angle_limits(branch).min`
- ``\Theta^\text{max}`` = `PowerSystems.get_phase_angle_limits(branch).max`
- ``X`` = `PowerSystems.get_x(branch)` (series reactance)
Expand Down
8 changes: 4 additions & 4 deletions docs/src/formulation_library/Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Depending on the `PowerSystems.jl` type associated to the `RangeReserve` formula

- ``\text{PF}`` = `PowerSystems.get_max_participation_factor(service)`

For a `StaticReserve` `PowerSystems` type:
For a `ConstantReserve` `PowerSystems` type:
- ``\text{Req}`` = `PowerSystems.get_requirement(service)`

**Time Series Parameters**
Expand Down Expand Up @@ -94,14 +94,14 @@ similarly if ``s_3`` is a `ReserveDown` service (e.g. Reg-Down):
A RangeReserve implements two fundamental constraints. The first is that the sum of all reserves of contributing devices must be larger than the `RangeReserve` requirement. Thus, for a service ``s``:

```math
\sum_{d\in\mathcal{D}_s} r_{d,t} + r_t^\text{sl} \ge \text{Req},\quad \forall t\in \{1,\dots, T\} \quad \text{(for a StaticReserve)} \\
\sum_{d\in\mathcal{D}_s} r_{d,t} + r_t^\text{sl} \ge \text{Req},\quad \forall t\in \{1,\dots, T\} \quad \text{(for a ConstantReserve)} \\
\sum_{d\in\mathcal{D}_s} r_{d,t} + r_t^\text{sl} \ge \text{RequirementTimeSeriesParameter}_{t},\quad \forall t\in \{1,\dots, T\} \quad \text{(for a VariableReserve)}
```

In addition, there is a restriction on how much each contributing device ``d`` can contribute to the requirement, based on the max participation factor allowed.

```math
r_{d,t} \le \text{Req} \cdot \text{PF} ,\quad \forall d\in \mathcal{D}_s, \forall t\in \{1,\dots, T\} \quad \text{(for a StaticReserve)} \\
r_{d,t} \le \text{Req} \cdot \text{PF} ,\quad \forall d\in \mathcal{D}_s, \forall t\in \{1,\dots, T\} \quad \text{(for a ConstantReserve)} \\
r_{d,t} \le \text{RequirementTimeSeriesParameter}_{t} \cdot \text{PF}\quad \forall d\in \mathcal{D}_s, \forall t\in \{1,\dots, T\}, \quad \text{(for a VariableReserve)}
```

Expand Down Expand Up @@ -176,7 +176,7 @@ A `StepwiseCostReserve` implements a single constraint, such that the sum of all

## `GroupReserve`

Service must be used with `StaticReserveGroup` `PowerSystems.jl` type. This service model is used to model an aggregation of services.
Service must be used with `ConstantReserveGroup` `PowerSystems.jl` type. This service model is used to model an aggregation of services.

```@docs
GroupReserve
Expand Down
6 changes: 3 additions & 3 deletions docs/src/modeler_guide/read_results.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Once a `DecisionModel` is solved via `solve!(model)` or a Simulation is executed

## Read results of a Decision Problem

Once a `DecisionModel` is solved, results are accessed using `ProblemResults(model)` as follows:
Once a `DecisionModel` is solved, results are accessed using `OptimizationProblemResults(model)` as follows:

```julia
# The DecisionModel is already constructed
build!(model, output_dir = mktempdir())
solve!(model)

results = ProblemResults(model)
results = OptimizationProblemResults(model)
```

The output will showcase the available expressions, parameters and variables to read. For example it will look like:
Expand Down Expand Up @@ -40,7 +40,7 @@ PowerSimulations Problem Duals Results
PowerSimulations Problem Parameters Results
┌────────────────────────────────────────────────────────────────────────┐
ActivePowerTimeSeriesParameter__RenewableFix
ActivePowerTimeSeriesParameter__RenewableNonDispatch
│ RenewablePowerTimeSeries__HybridSystem │
│ RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Spin_Up_R3 │
│ RequirementTimeSeriesParameter__VariableReserve__ReserveUp__Reg_Up │
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/decision_problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ Here we define template entries for all devices that inject or withdraw power on
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 `RenewableFix` devices.
for `HydroDispatch` and `RenewableNonDispatch` devices.

```@example op_problem
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, RenewableFix, FixedOutput)
set_device_model!(template_uc, RenewableNonDispatch, FixedOutput)
```

### Service Formulations
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/pcm_simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ problem definition), we can use:
```@example pcm
read_parameter(
ed_results,
"ActivePowerTimeSeriesParameter__RenewableFix",
"ActivePowerTimeSeriesParameter__RenewableNonDispatch",
initial_time = DateTime("2020-01-01T06:00:00"),
count = 5,
)
Expand Down
7 changes: 3 additions & 4 deletions src/PowerSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export run_parallel_simulation
## Template Exports
export template_economic_dispatch
export template_unit_commitment
export template_agc_reserve_deployment
export EconomicDispatchProblem
export UnitCommitmentProblem
export AGCReserveDeployment
Expand Down Expand Up @@ -557,10 +556,10 @@ include("devices_models/devices/AC_branches.jl")
include("devices_models/devices/area_interchange.jl")
include("devices_models/devices/TwoTerminalDC_branches.jl")
include("devices_models/devices/HVDCsystems.jl")
include("devices_models/devices/regulation_device.jl")
#include("devices_models/devices/regulation_device.jl")

# Services Models
include("services_models/agc.jl")
#include("services_models/agc.jl")
include("services_models/reserves.jl")
include("services_models/reserve_group.jl")
include("services_models/transmission_interface.jl")
Expand All @@ -584,7 +583,7 @@ include("devices_models/device_constructors/hvdcsystems_constructor.jl")
include("devices_models/device_constructors/branch_constructor.jl")
include("devices_models/device_constructors/renewablegeneration_constructor.jl")
include("devices_models/device_constructors/load_constructor.jl")
include("devices_models/device_constructors/regulationdevice_constructor.jl")
#include("devices_models/device_constructors/regulationdevice_constructor.jl")

# Network constructors
include("network_models/network_constructor.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/core/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ For more information check [Service Formulations](@ref service_formulations).
The constraint is as follows:
```math
r_{d,t} \\le \\text{Req} \\cdot \\text{PF} ,\\quad \\forall d\\in \\mathcal{D}_s, \\forall t\\in \\{1,\\dots, T\\} \\quad \\text{(for a StaticReserve)} \\\\
r_{d,t} \\le \\text{Req} \\cdot \\text{PF} ,\\quad \\forall d\\in \\mathcal{D}_s, \\forall t\\in \\{1,\\dots, T\\} \\quad \\text{(for a ConstantReserve)} \\\\
r_{d,t} \\le \\text{RequirementTimeSeriesParameter}_{t} \\cdot \\text{PF}\\quad \\forall d\\in \\mathcal{D}_s, \\forall t\\in \\{1,\\dots, T\\}, \\quad \\text{(for a VariableReserve)}
```
"""
Expand Down Expand Up @@ -288,7 +288,7 @@ For more information check [Service Formulations](@ref service_formulations).
The constraint is as follows:
```math
\\sum_{d\\in\\mathcal{D}_s} r_{d,t} + r_t^\\text{sl} \\ge \\text{Req},\\quad \\forall t\\in \\{1,\\dots, T\\} \\quad \\text{(for a StaticReserve)} \\\\
\\sum_{d\\in\\mathcal{D}_s} r_{d,t} + r_t^\\text{sl} \\ge \\text{Req},\\quad \\forall t\\in \\{1,\\dots, T\\} \\quad \\text{(for a ConstantReserve)} \\\\
\\sum_{d\\in\\mathcal{D}_s} r_{d,t} + r_t^\\text{sl} \\ge \\text{RequirementTimeSeriesParameter}_{t},\\quad \\forall t\\in \\{1,\\dots, T\\} \\quad \\text{(for a VariableReserve)}
```
"""
Expand Down
20 changes: 10 additions & 10 deletions src/devices_models/devices/AC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ function branch_rate_bounds!(
continue
end
for t in get_time_steps(container)
JuMP.set_upper_bound(var[name, t], PSY.get_rate(d))
JuMP.set_lower_bound(var[name, t], -1.0 * PSY.get_rate(d))
JuMP.set_upper_bound(var[name, t], PSY.get_rating(d))
JuMP.set_lower_bound(var[name, t], -1.0 * PSY.get_rating(d))
end
end
return
Expand All @@ -162,8 +162,8 @@ function branch_rate_bounds!(
continue
end
for t in time_steps, var in vars
JuMP.set_upper_bound(var[name, t], PSY.get_rate(d))
JuMP.set_lower_bound(var[name, t], -1.0 * PSY.get_rate(d))
JuMP.set_upper_bound(var[name, t], PSY.get_rating(d))
JuMP.set_lower_bound(var[name, t], -1.0 * PSY.get_rating(d))
end
end
return
Expand All @@ -179,7 +179,7 @@ function get_min_max_limits(
::Type{<:ConstraintType},
::Type{<:AbstractBranchFormulation},
) # -> Union{Nothing, NamedTuple{(:min, :max), Tuple{Float64, Float64}}}
return (min = -1 * PSY.get_rate(device), max = PSY.get_rate(device))
return (min = -1 * PSY.get_rating(device), max = PSY.get_rating(device))
end

"""
Expand Down Expand Up @@ -348,7 +348,7 @@ function add_constraints!(
device_model::DeviceModel{B, <:AbstractBranchFormulation},
network_model::NetworkModel{T},
) where {B <: PSY.ACBranch, T <: PM.AbstractPowerModel}
rating_data = [(PSY.get_name(h), PSY.get_rate(h)) for h in devices]
rating_data = [(PSY.get_name(h), PSY.get_rating(h)) for h in devices]

time_steps = get_time_steps(container)
var1 = get_variable(container, FlowActivePowerFromToVariable(), B)
Expand Down Expand Up @@ -403,7 +403,7 @@ function add_constraints!(
::DeviceModel{B, <:AbstractBranchFormulation},
network_model::NetworkModel{T},
) where {B <: PSY.ACBranch, T <: PM.AbstractPowerModel}
rating_data = [(PSY.get_name(h), PSY.get_rate(h)) for h in devices]
rating_data = [(PSY.get_name(h), PSY.get_rating(h)) for h in devices]

time_steps = get_time_steps(container)
var1 = get_variable(container, FlowActivePowerToFromVariable(), B)
Expand Down Expand Up @@ -516,7 +516,7 @@ function _make_flow_expressions!(
=#

t2_ = time()
@error "time to build PTDF expressions $branch_Type $(t2_ - t1_)"
#@error "time to build PTDF expressions $branch_Type $(t2_ - t1_)"
return branch_flow_expr
end
"""
Expand Down Expand Up @@ -564,7 +564,7 @@ function add_constraints!(
end
end
t2 = time()
@error "time to build PTDF constraints $B $(t2 - t1)"
#@error "time to build PTDF constraints $B $(t2 - t1)"
return
end

Expand Down Expand Up @@ -622,7 +622,7 @@ function get_min_max_limits(
)
end
limit = min(
PSY.get_rate(device),
PSY.get_rating(device),
PSY.get_flow_limits(device).to_from,
PSY.get_flow_limits(device).from_to,
)
Expand Down
2 changes: 1 addition & 1 deletion src/devices_models/devices/common/add_to_expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ function add_to_expression!(
W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch},
}
variable = get_variable(container, U(), V)
sys_expr = get_expression(container, T(), _system_expression_type(X))
sys_expr = get_expression(container, T(), _system_expression_type(PTDFPowerModel))
nodal_expr = get_expression(container, T(), PSY.ACBus)
radial_network_reduction = get_radial_network_reduction(network_model)
for d in devices
Expand Down
30 changes: 15 additions & 15 deletions src/network_models/pm_translator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ function get_branch_to_pm(
)
PM_branch = Dict{String, Any}(
"br_r" => PSY.get_r(branch),
"rate_a" => PSY.get_rate(branch),
"rate_a" => PSY.get_rating(branch),
"shift" => PSY.get_α(branch),
"rate_b" => PSY.get_rate(branch),
"rate_b" => PSY.get_rating(branch),
"br_x" => PSY.get_x(branch),
"rate_c" => PSY.get_rate(branch),
"rate_c" => PSY.get_rating(branch),
"g_to" => 0.0,
"g_fr" => 0.0,
"b_fr" => PSY.get_primary_shunt(branch) / 2,
Expand All @@ -52,11 +52,11 @@ function get_branch_to_pm(
) where {D <: AbstractBranchFormulation}
PM_branch = Dict{String, Any}(
"br_r" => PSY.get_r(branch),
"rate_a" => PSY.get_rate(branch),
"rate_a" => PSY.get_rating(branch),
"shift" => PSY.get_α(branch),
"rate_b" => PSY.get_rate(branch),
"rate_b" => PSY.get_rating(branch),
"br_x" => PSY.get_x(branch),
"rate_c" => PSY.get_rate(branch),
"rate_c" => PSY.get_rating(branch),
"g_to" => 0.0,
"g_fr" => 0.0,
"b_fr" => PSY.get_primary_shunt(branch) / 2,
Expand Down Expand Up @@ -107,11 +107,11 @@ function get_branch_to_pm(
)
PM_branch = Dict{String, Any}(
"br_r" => PSY.get_r(branch),
"rate_a" => PSY.get_rate(branch),
"rate_a" => PSY.get_rating(branch),
"shift" => 0.0,
"rate_b" => PSY.get_rate(branch),
"rate_b" => PSY.get_rating(branch),
"br_x" => PSY.get_x(branch),
"rate_c" => PSY.get_rate(branch),
"rate_c" => PSY.get_rating(branch),
"g_to" => 0.0,
"g_fr" => 0.0,
"b_fr" => PSY.get_primary_shunt(branch) / 2,
Expand Down Expand Up @@ -162,11 +162,11 @@ function get_branch_to_pm(
)
PM_branch = Dict{String, Any}(
"br_r" => PSY.get_r(branch),
"rate_a" => PSY.get_rate(branch),
"rate_a" => PSY.get_rating(branch),
"shift" => 0.0,
"rate_b" => PSY.get_rate(branch),
"rate_b" => PSY.get_rating(branch),
"br_x" => PSY.get_x(branch),
"rate_c" => PSY.get_rate(branch),
"rate_c" => PSY.get_rating(branch),
"g_to" => 0.0,
"g_fr" => 0.0,
"b_fr" => PSY.get_primary_shunt(branch) / 2,
Expand Down Expand Up @@ -217,11 +217,11 @@ function get_branch_to_pm(
)
PM_branch = Dict{String, Any}(
"br_r" => PSY.get_r(branch),
"rate_a" => PSY.get_rate(branch),
"rate_a" => PSY.get_rating(branch),
"shift" => 0.0,
"rate_b" => PSY.get_rate(branch),
"rate_b" => PSY.get_rating(branch),
"br_x" => PSY.get_x(branch),
"rate_c" => PSY.get_rate(branch),
"rate_c" => PSY.get_rating(branch),
"g_to" => 0.0,
"g_fr" => 0.0,
"b_fr" => PSY.get_b(branch).from,
Expand Down
36 changes: 36 additions & 0 deletions src/operation/decision_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,42 @@ function init_model_store_params!(model::DecisionModel)
return
end

function validate_time_series!(model::DecisionModel{<:DefaultDecisionProblem})
sys = get_system(model)
settings = get_settings(model)
available_resolutions = PSY.get_time_series_resolutions(sys)

if get_resolution(settings) == UNSET_RESOLUTION && length(available_resolutions) != 1
throw(
IS.ConflictingInputsError(
"Data contains multiple resolutions, the resolution keyword argument must be added to the Model. Time Series Resolutions: $(available_resolutions)",
),
)
elseif get_resolution(settings) != UNSET_RESOLUTION && length(available_resolutions) > 1
if get_resolution(settings) available_resolutions
throw(
IS.ConflictingInputsError(
"Resolution $(get_resolution(settings)) is not available in the system data. Time Series Resolutions: $(available_resolutions)",
),
)
end
else
set_resolution!(settings, first(available_resolutions))
end

if get_horizon(settings) == UNSET_HORIZON
set_horizon!(settings, PSY.get_forecast_horizon(sys))
end

counts = PSY.get_time_series_counts(sys)
if counts.forecast_count < 1
error(
"The system does not contain forecast data. A DecisionModel can't be built.",
)
end
return
end

function build_pre_step!(model::DecisionModel{<:DecisionProblem})
TimerOutputs.@timeit BUILD_PROBLEMS_TIMER "Build pre-step" begin
validate_template(model)
Expand Down
Loading

0 comments on commit a530304

Please sign in to comment.