Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/common_models/add_param_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function add_param_container!(
) where {
T <: EventParameter,
U <: IS.InfrastructureSystemsComponent,
V <: IS.InfrastructureSystemsComponent,
V <: IS.SupplementalAttribute,
}
param_key = ParameterKey(T, U, meta)
attributes = EventParametersAttributes(V, T)
Expand Down
16 changes: 9 additions & 7 deletions src/core/parameter_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,25 @@ get_sos_status(attr::CostFunctionAttributes) = attr.sos_status
get_variable_types(attr::CostFunctionAttributes) = attr.variable_types
get_uses_compact_power(attr::CostFunctionAttributes) = attr.uses_compact_power

"""
Attributes for event (contingency) parameters. `T` is the `IS.SupplementalAttribute`
subtype describing the contingency and `U` is the parameter type stored in the container.
"""
struct EventParametersAttributes{
T <: IS.InfrastructureSystemsComponent,
T <: IS.SupplementalAttribute,
U <: ParameterType,
} <: ParameterAttributes
affected_devices::Vector{T}

@luke-kiernan luke-kiernan Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're removing the affected_devices field. Looking in IOM, POM, and PSI, I don't see anywhere that field is used, but then that makes me wonder why it's here at all.

edit: oh, I see you noticed the same thing. I guess I'd like confirmation from Jose that we don't need that field before removing it.

end
} <: ParameterAttributes end

function EventParametersAttributes(
::Type{T},
::Type{U},
) where {T <: IS.InfrastructureSystemsComponent, U <: ParameterType}
return EventParametersAttributes{T, U}(T[])
) where {T <: IS.SupplementalAttribute, U <: ParameterType}
return EventParametersAttributes{T, U}()
end

function get_param_type(
::EventParametersAttributes{T, U},
) where {T <: IS.InfrastructureSystemsComponent, U <: ParameterType}
) where {T <: IS.SupplementalAttribute, U <: ParameterType}
return U
end

Expand Down
7 changes: 7 additions & 0 deletions test/mocks/mock_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ get_rate(b::MockBranch) = b.rating
# Subtypes IS.InfrastructureSystemsComponent so it works with VariableKey, ConstraintKey, etc.
struct MockComponentType <: IS.InfrastructureSystemsComponent end

# Mock supplemental attribute for testing event parameter containers.
# Subtypes IS.SupplementalAttribute (not IS.InfrastructureSystemsComponent), mirroring
# PSY.Contingency <: SupplementalAttribute.
struct MockContingency <: IS.SupplementalAttribute end

struct MockEventParameter <: InfrastructureOptimizationModels.EventParameter end

# Structures for the network problem
struct MockNetworkNode <: IS.InfrastructureSystemsComponent
name::String
Expand Down
30 changes: 30 additions & 0 deletions test/test_optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,34 @@ struct MockExpressionType <: ISOPT.ExpressionType end
@test expr1 == expr2
@test JuMP.coefficient(expr2, x) == 5.0
end

@testset "Event parameter container accepts supplemental-attribute contingency types" begin
mock_sys = MockSystem(100.0)
settings = IOM.Settings(
mock_sys;
horizon = Dates.Hour(24),
resolution = Dates.Hour(1),
time_series_cache_size = 0,
)
container = IOM.OptimizationContainer(
mock_sys,
settings,
nothing,
MockDeterministic,
)
IOM.set_time_steps!(container, 1:24)
time_steps = IOM.get_time_steps(container)

IOM.add_param_container!(
container,
MockEventParameter,
MockComponentType,
MockContingency,
["dev1", "dev2"],
time_steps,
)
key = IOM.ParameterKey(MockEventParameter, MockComponentType)
pc = IOM.get_parameter(container, key)
@test IOM.get_attributes(pc) isa IOM.EventParametersAttributes{MockContingency}
end
end
Loading