PowerSystems.jl
PowerSystems.jl copied to clipboard
Expression contains an invalid NaN constant. This could be produced by `Inf - Inf`.
If this is a question, something isn't working or an idea please start a Q&A discussion in the Discussion tab Open a bug report only if you can provide the details below
Describe the bug
If I rl = get_ramp_limits(g)
and set them back using set_ramp_limits!(g, rl)
, the build in PowerSimulations seems to fail.
That is, if I have the following code:
sys = create_sys()
for g in get_components(ThermalStandard, sys)
rl = get_ramp_limits(g)
set_ramp_limits!(g, rl)
end
op_problem = ...
build!(op_problem)
I end up with the following error when adding the linear ramp constraints
┌ Error: DecisionModel Build Failed
│ exception =
│ Expression contains an invalid NaN constant. This could be produced by `Inf - Inf`.
│ Stacktrace:
│ [1] error(s::String)
│ @ Base ./error.jl:35
│ [2] _assert_isfinite(a::AffExpr)
│ @ JuMP ~/.julia/packages/JuMP/0STkJ/src/aff_expr.jl:554
│ [3] MathOptInterface.ScalarAffineFunction(a::AffExpr)
│ @ JuMP ~/.julia/packages/JuMP/0STkJ/src/aff_expr.jl:587
│ [4] moi_function
│ @ ~/.julia/packages/JuMP/0STkJ/src/aff_expr.jl:630 [inlined]
│ [5] moi_function
│ @ ~/.julia/packages/JuMP/0STkJ/src/constraints.jl:483 [inlined]
│ [6] add_constraint(model::Model, con::ScalarConstraint{AffExpr, MathOptInterface.LessThan{Float64}}, name::String)
│ @ JuMP ~/.julia/packages/JuMP/0STkJ/src/constraints.jl:624
│ [7] add_linear_ramp_constraints!(container::PowerSimulations.OptimizationContainer, T::Type{RampConstraint}, U::Type{ActivePowerVariable}, devices::InfrastructureSystems.FlattenIteratorWrapper{ThermalStandard}, model::DeviceModel{ThermalStandard, ThermalStandardDispatch}, X::Type{CopperPlatePowerModel})
│ @ PowerSimulations ~/gitrepos/PowerSimulations.jl/src/devices_models/devices/common/rateofchange_constraints.jl:94
...
To Reproduce
Here's the code I'm using to reproduce this issue:
using PowerSystems
const PSY = PowerSystems
using PowerSimulations
const PSI = PowerSimulations
using InfrastructureSystems
using Dates
using DataFrames
using TimeSeries
using Xpress
using JuMP
using CSV
using DelimitedFiles
function create_rts_gmlc_system(
repo;
time_series_resolution = Dates.Hour(1),
try_deserialize = true,
kwargs...,
)
rts_data = joinpath(repo, "RTS_Data")
src_data = joinpath(rts_data, "SourceData")
siip_data = joinpath(rts_data, "FormattedData", "SIIP")
data = PowerSystemTableData(
src_data,
100.0,
joinpath(siip_data, "user_descriptors.yaml"),
generator_mapping_file = joinpath(siip_data, "generator_mapping.yaml"),
timeseries_metadata_file = joinpath(siip_data, "timeseries_pointers.json"),
)
sys = System(data; time_series_resolution = time_series_resolution, kwargs...)
set_units_base_system!(sys, "system_base")
return sys
end
function main()
repo = expanduser("~/gitrepos/RTS-GMLC")
sys = create_rts_gmlc_system(repo)
### ADD THESE LINES
for g in get_components(ThermalStandard, sys)
rl = get_ramp_limits(g)
set_ramp_limits!(g, rl)
end
### ADD THESE LINES
horizon = 24;
interval = Dates.Hour(24);
transform_single_time_series!(sys, horizon, interval)
template_uc = ProblemTemplate()
set_device_model!(template_uc, ThermalStandard, ThermalStandardDispatch)
solver = optimizer_with_attributes(Xpress.Optimizer, "MIPRELSTOP" => 0.0001, "OUTPUTLOG" => 1)
op_problem = DecisionModel(
template_uc,
sys,
horizon = 2,
optimizer = solver,
initial_time = Dates.DateTime("2020-01-01T00:00:00"), # "2020-07-30T00:00:00"
)
build!(op_problem, output_dir = mktempdir())
psi_container = PSI.get_optimization_container(op_problem)
open("test.txt","w") do f
print(f,psi_container.JuMPmodel)
end
op_problem
end
main()
Expected behavior
No error should occur when a get
and set
is used with the exact same data.
cc @Nongchao
I don't think that is guaranteed in PowerSystems that this will return the same thing
for g in get_components(ThermalStandard, sys)
rl = get_ramp_limits(g)
set_ramp_limits!(g, rl)
end
depends on the unit settings.
But we should definitely catch the Infs before the build
Issue is stale and hasn't been repeated.