Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/common_models/range_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ function get_startup_shutdown(
nothing
end

"""
get_min_max_limits(device, ::Type{<:ConstraintType}, ::Type{<:AbstractDeviceFormulation})

Return the (min, max) limits for a device given a constraint type and formulation.
This function must be implemented by downstream packages (e.g., PowerSimulations.jl)
for specific device types and formulations.

Returns a NamedTuple with fields `min` and `max`.
"""
function get_min_max_limits(
device,
T::Type{<:ConstraintType},
W::Type{<:AbstractDeviceFormulation},
)
error(
"get_min_max_limits not implemented for device $(typeof(device)), constraint type $T, formulation type $W",
)
end

@doc raw"""
Constructs min/max range constraint from device variable.

Expand Down
14 changes: 12 additions & 2 deletions src/common_models/variable_properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ function get_variable_lower_bound(
service::U,
d::V,
::F,
) where {T <: VariableType, U <: PSY.Service, V <: PSY.Component, F <: AbstractServiceFormulation}
) where {
T <: VariableType,
U <: PSY.Service,
V <: PSY.Component,
F <: AbstractServiceFormulation,
}
return nothing
end

Expand All @@ -65,7 +70,12 @@ function get_variable_upper_bound(
service::U,
d::V,
::F,
) where {T <: VariableType, U <: PSY.Service, V <: PSY.Component, F <: AbstractServiceFormulation}
) where {
T <: VariableType,
U <: PSY.Service,
V <: PSY.Component,
F <: AbstractServiceFormulation,
}
return nothing
end

Expand Down
10 changes: 8 additions & 2 deletions src/core/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ set_run_status!(::SimulationInfo, status) = nothing
#################################################################################
# Parameter Container Type
# Stores parameter arrays and their attributes for optimization problems
struct ParameterContainer{T, U <: Union{JuMP.Containers.DenseAxisArray, JuMP.Containers.SparseAxisArray}}
struct ParameterContainer{
T,
U <: Union{JuMP.Containers.DenseAxisArray, JuMP.Containers.SparseAxisArray},
}
attributes::T
parameter_array::U
multiplier_array::Union{JuMP.Containers.DenseAxisArray{Float64}, JuMP.Containers.SparseAxisArray{Float64}}
multiplier_array::Union{
JuMP.Containers.DenseAxisArray{Float64},
JuMP.Containers.SparseAxisArray{Float64},
}
end

# Accessor functions for ParameterContainer
Expand Down
4 changes: 3 additions & 1 deletion src/core/standard_variables_expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,7 @@ function add_to_expression!(
model::DeviceModel,
network_model::NetworkModel,
)
error("add_to_expression! not implemented for expression_type=$expression_type, variable_type=$variable_type, device_type=$(typeof(devices.values[1]))")
error(
"add_to_expression! not implemented for expression_type=$expression_type, variable_type=$variable_type, device_type=$(typeof(devices.values[1]))",
)
end
1 change: 0 additions & 1 deletion src/operation/decision_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ function solve!(
return get_run_status(model)
end


function handle_initial_conditions!(model::DecisionModel{<:DecisionProblem})
TimerOutputs.@timeit BUILD_PROBLEMS_TIMER "Model Initialization" begin
if isempty(get_template(model))
Expand Down
12 changes: 8 additions & 4 deletions src/operation/operation_model_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,29 @@ get_simulation_info(model::OperationModel) = model.simulation_info

function get_simulation_number(model::OperationModel)
sim_info = get_simulation_info(model)
isnothing(sim_info) && error("Model is not part of a simulation. Cannot get simulation number.")
isnothing(sim_info) &&
error("Model is not part of a simulation. Cannot get simulation number.")
return get_number(sim_info)
end

function set_simulation_number!(model::OperationModel, val)
sim_info = get_simulation_info(model)
isnothing(sim_info) && error("Model is not part of a simulation. Cannot set simulation number.")
isnothing(sim_info) &&
error("Model is not part of a simulation. Cannot set simulation number.")
return set_number!(sim_info, val)
end

function get_sequence_uuid(model::OperationModel)
sim_info = get_simulation_info(model)
isnothing(sim_info) && error("Model is not part of a simulation. Cannot get sequence UUID.")
isnothing(sim_info) &&
error("Model is not part of a simulation. Cannot get sequence UUID.")
return get_sequence_uuid(sim_info)
end

function set_sequence_uuid!(model::OperationModel, val)
sim_info = get_simulation_info(model)
isnothing(sim_info) && error("Model is not part of a simulation. Cannot set sequence UUID.")
isnothing(sim_info) &&
error("Model is not part of a simulation. Cannot set sequence UUID.")
return set_sequence_uuid!(sim_info, val)
end
get_status(model::OperationModel) = ISOPT.get_status(get_internal(model))
Expand Down
1 change: 0 additions & 1 deletion src/operation/problem_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ end
ProblemTemplate(::Type{T}) where {T <: PM.AbstractPowerModel} =
ProblemTemplate(NetworkModel(T))


get_device_models(template::ProblemTemplate) = template.devices
get_branch_models(template::ProblemTemplate) = template.branches
get_service_models(template::ProblemTemplate) = template.services
Expand Down
8 changes: 4 additions & 4 deletions test/PowerOptimizationModelsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ function run_tests()
# Results and I/O tests
@testset "Operation" begin
test_files = [
# Add as they are created:
# "unit/operation/test_problem_results.jl",
# "unit/operation/test_results_by_time.jl",
# "unit/operation/test_serialization.jl",
# Add as they are created:
# "unit/operation/test_problem_results.jl",
# "unit/operation/test_results_by_time.jl",
# "unit/operation/test_serialization.jl",
]
for test_file in test_files
if isfile(test_file)
Expand Down
22 changes: 11 additions & 11 deletions test/mocks/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ using Dates
Create a mock system with specified number of buses, generators, and loads.
"""
function make_mock_system(;
n_buses=3,
n_gens=2,
n_loads=1,
base_power=100.0
n_buses = 3,
n_gens = 2,
n_loads = 1,
base_power = 100.0,
)
sys = MockSystem(base_power)

Expand All @@ -27,7 +27,7 @@ function make_mock_system(;
"gen$i",
true,
buses[mod1(i, length(buses))],
(min=0.0, max=100.0)
(min = 0.0, max = 100.0),
)
add_component!(sys, gen)
end
Expand All @@ -38,7 +38,7 @@ function make_mock_system(;
"load$i",
true,
buses[mod1(i, length(buses))],
50.0
50.0,
)
add_component!(sys, load)
end
Expand All @@ -50,15 +50,15 @@ end
Create a mock time series with specified parameters.
"""
function make_mock_time_series(;
name="test_ts",
length=24,
resolution=Hour(1),
initial_timestamp=DateTime(2024, 1, 1)
name = "test_ts",
length = 24,
resolution = Hour(1),
initial_timestamp = DateTime(2024, 1, 1),
)
return MockDeterministic(
name,
rand(length),
resolution,
initial_timestamp
initial_timestamp,
)
end
8 changes: 4 additions & 4 deletions test/mocks/mock_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ mutable struct MockSystem
components::Dict{DataType, Vector{Any}}
time_series::Dict{Any, Any}

MockSystem(base_power=100.0) = new(base_power, Dict(), Dict())
MockSystem(base_power = 100.0) = new(base_power, Dict(), Dict())
end

# Required interface methods
get_base_power(sys::MockSystem) = sys.base_power

function get_components(::Type{T}, sys::MockSystem) where T
function get_components(::Type{T}, sys::MockSystem) where {T}
return get(sys.components, T, T[])
end

Expand All @@ -32,8 +32,8 @@ function get_time_series(
sys::MockSystem,
component,
args...;
kwargs...
) where T
kwargs...,
) where {T}
return get(sys.time_series, (T, component), nothing)
end

Expand Down
6 changes: 3 additions & 3 deletions test/verify_mocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ bus = MockBus("bus1", 1, :PV)
println("✓ MockBus works")

# Test MockThermalGen
gen = MockThermalGen("gen1", true, bus, (min=10.0, max=100.0))
gen = MockThermalGen("gen1", true, bus, (min = 10.0, max = 100.0))
@assert get_name(gen) == "gen1"
@assert get_available(gen) == true
@assert get_active_power_limits(gen).max == 100.0
println("✓ MockThermalGen works")

# Test factory function
sys2 = make_mock_system(n_buses=3, n_gens=2, n_loads=1)
sys2 = make_mock_system(; n_buses = 3, n_gens = 2, n_loads = 1)
@assert get_base_power(sys2) == 100.0
buses = get_components(MockBus, sys2)
@assert length(buses) == 3
Expand All @@ -42,7 +42,7 @@ gens = get_components(MockThermalGen, sys2)
println("✓ make_mock_system() works")

# Test time series
ts = make_mock_time_series(length=24)
ts = make_mock_time_series(; length = 24)
@assert length(ts.data) == 24
println("✓ make_mock_time_series() works")

Expand Down
Loading