diff --git a/src/PowerModels.jl b/src/PowerModels.jl index 5dc13458..348a5f90 100644 --- a/src/PowerModels.jl +++ b/src/PowerModels.jl @@ -38,6 +38,7 @@ const pm_it_sym = Symbol(pm_it_name) include("io/matpower.jl") +include("io/opfdata.jl") include("io/common.jl") include("io/pti.jl") include("io/psse.jl") diff --git a/src/io/json.jl b/src/io/json.jl index 06590d2f..bcd019d7 100644 --- a/src/io/json.jl +++ b/src/io/json.jl @@ -16,6 +16,10 @@ function parse_json(io::Union{IO,String}; kwargs...)::Dict{String,Any} Memento.warn(_LOGGER, "The JSON data contains the conductor parameter, but only single conductors are supported. Consider using PowerModelsDistribution.") end + if haskey(pm_data, "grid") && haskey(pm_data, "solution") && haskey(pm_data, "metadata") + pm_data = PowerModels.parse_opfdata(pm_data, get(kwargs, :validate, true)) + end + if get(kwargs, :validate, true) PowerModels.correct_network_data!(pm_data) end diff --git a/src/io/opfdata.jl b/src/io/opfdata.jl new file mode 100644 index 00000000..f5451137 --- /dev/null +++ b/src/io/opfdata.jl @@ -0,0 +1,327 @@ +########################################################################### +# # +# This file provides functions for interfacing with OPFData dataset files # +# # +########################################################################### + +"Parses the OPFData data from a json dictionary" +function parse_opfdata(opfdata_dict::Dict{String,Any}, validate=true)::Dict + pm_data = _opfdata_to_powermodels!(opfdata_dict) + if validate + correct_network_data!(pm_data) + end + return pm_data +end + +"Parses OPFData data from either a filename or an IO object" +function parse_opfdata(io::IO; kwargs...)::Dict + opf_data = parse_json(io; kwargs...) + return opf_data +end + +function parse_opfdata(file::String; kwargs...)::Dict + opf_data = open(file) do io + parse_json(io; kwargs...) + end + return opf_data +end + +### Data and functions specific to OPFData format ### + +const _opf_bus_columns = [ + ("base_kv", Float64), + ("bus_type", Int), + ("vmin", Float64), + ("vmax", Float64) +] + +const _opf_gen_columns = [ + ("mbase", Float64), + ("pg", Float64), + ("pmin", Float64), ("pmax", Float64), + ("qg", Float64), + ("qmin", Float64), ("qmax", Float64), + ("vg", Float64), + ("cost_squared", Float64), + ("cost_linear", Float64), + ("cost_offset", Float64) +] + +const _opf_load_columns = [ + ("pd", Float64), ("qd", Float64) +] + +const _opf_shunt_columns = [ + ("bs", Float64), ("gs", Float64) +] + +const _opf_ac_line_feature_columns = [ + ("angmin", Float64), ("angmax", Float64), + ("b_fr", Float64), ("b_to", Float64), + ("br_r", Float64), ("br_x", Float64), + ("rate_a", Float64), + ("rate_b", Float64), + ("rate_c", Float64) +] + +const _opf_transformer_line_feature_columns = [ + ("angmin", Float64), ("angmax", Float64), + ("br_r", Float64), ("br_x", Float64), + ("rate_a", Float64), + ("rate_b", Float64), + ("rate_c", Float64), + ("tap", Float64), ("shift", Float64), + ("b_fr", Float64), ("b_to", Float64) +] + + +### Data and functions specific to PowerModels format ### + +""" +Converts a OPFData dict into a PowerModels dict +""" +function _opfdata_to_powermodels!(opfdata_dict::Dict{String,<:Any}) + + grid = opfdata_dict["grid"] + case = Dict{String,Any}() + + case["per_unit"] = true + + if haskey(grid["nodes"], "bus") + buses = [] + for (i, bus_row) in enumerate(grid["nodes"]["bus"]) + bus_data = _IM.row_to_typed_dict(bus_row, _opf_bus_columns) + bus_data["index"] = i + bus_data["source_id"] = ["bus", i] + bus_data["va"] = 0.0 + bus_data["vm"] = 0.0 + push!(buses, bus_data) + end + case["bus"] = buses + else + Memento.error(string("no bus table found in OPFData file. The file seems to be missing \"bus\": [...]")) + end + + if haskey(grid["nodes"], "generator") + gens = [] + for (i, gen_row) in enumerate(grid["nodes"]["generator"]) + gen_data = _IM.row_to_typed_dict(gen_row, _opf_gen_columns) + gen_data["index"] = i + gen_data["source_id"] = ["gen", i] + gen_data["model"] = 2 + gen_data["ncost"] = 3 + gen_data["cost"] = [_IM.check_type(Float64, gen_data[key]) for key in ["cost_offset", "cost_linear", "cost_squared"]] + for key in ["cost_offset", "cost_linear", "cost_squared"] + delete!(gen_data, key) + end + push!(gens, gen_data) + end + case["gen"] = gens + else + Memento.error(string("no gen table found in OPFData file. The file seems to be missing \"gen\": [...]")) + end + + if haskey(grid["nodes"], "load") + loads = [] + for (i, load_row) in enumerate(grid["nodes"]["load"]) + load_data = _IM.row_to_typed_dict(load_row, _opf_load_columns) + load_data["index"] = i + load_data["source_id"] = ["load", i] + push!(loads, load_data) + end + case["load"] = loads + else + Momento.error(string("no gen table found in OPFData file. The file seems to be missing \"load\": [...]")) + end + + if haskey(grid["nodes"], "shunt") + shunts = [] + for (i, shunt_row) in enumerate(grid["nodes"]["shunt"]) + shunt_data = _IM.row_to_typed_dict(shunt_row, _opf_shunt_columns) + shunt_data["index"] = i + shunt_data["source_id"] = ["shunt", i] + push!(shunts, shunt_data) + end + case["shunt"] = shunts + else + Momento.error(string("no gen table found in OPFData file. The file seems to be missing \"shunt\": [...]")) + end + + if haskey(grid["edges"], "ac_line") + ac_lines = [] + for (i, ac_line_row) in enumerate(grid["edges"]["ac_line"]["features"]) + ac_line_data = _IM.row_to_typed_dict(ac_line_row, _opf_ac_line_feature_columns) + ac_line_data["f_bus"] = grid["edges"]["ac_line"]["senders"][i] + 1 + ac_line_data["t_bus"] = grid["edges"]["ac_line"]["receivers"][i] + 1 + ac_line_data["tap"] = 1.0 + ac_line_data["shift"] = 0.0 + ac_line_data["transformer"] = false + + if ac_line_data["rate_a"] == 0.0 + delete!(ac_line_data, "rate_a") + end + if ac_line_data["rate_b"] == 0.0 + delete!(ac_line_data, "rate_b") + end + if ac_line_data["rate_c"] == 0.0 + delete!(ac_line_data, "rate_c") + end + push!(ac_lines, ac_line_data) + end + case["ac_line"] = ac_lines + else + Momento.error(string("no gen table found in OPFData file. The file seems to be missing \"ac_line\": [...]")) + end + + if haskey(grid["edges"], "transformer") + transformer_lines = [] + for (i, transformer_line_row) in enumerate(grid["edges"]["transformer"]["features"]) + transformer_line_data = _IM.row_to_typed_dict(transformer_line_row, _opf_transformer_line_feature_columns) + transformer_line_data["f_bus"] = grid["edges"]["transformer"]["senders"][i] + 1 + transformer_line_data["t_bus"] = grid["edges"]["transformer"]["receivers"][i] + 1 + transformer_line_data["transformer"] = true + + if transformer_line_data["rate_a"] == 0.0 + delete!(transformer_line_data, "rate_a") + end + if transformer_line_data["rate_b"] == 0.0 + delete!(transformer_line_data, "rate_b") + end + if transformer_line_data["rate_c"] == 0.0 + delete!(transformer_line_data, "rate_c") + end + push!(transformer_lines, transformer_line_data) + end + case["transformer_line"] = transformer_lines + else + Momento.error(string("no gen table found in OPFData file. The file seems to be missing \"transformer\": [...]")) + end + + if haskey(grid, "context") + case["baseMVA"] = grid["context"][1][1][1] + else + Memento.warn(_LOGGER, string("no baseMVA found in OPFData file. The file seems to be missing \"context\": [...]")) + case["baseMVA"] = 1.0 + end + + if haskey(grid["edges"], "generator_link") + gen = case["gen"] + gen_links = grid["edges"]["generator_link"]["receivers"] + if length(gen_links) != length(gen) + if length(gen_links) > length(gen) + Memento.warn(_LOGGER, "The last $(length(gen_links) - length(gen)) generator links will be ignored due to too few generators.") + else + Memento.warn(_LOGGER, "The number of generators ($(length(gen))) does not match the number of generator link records ($(length(gen_links))).") + end + end + + for (i, bus_id) in enumerate(gen_links) + g = gen[i] + @assert(g["index"] == (grid["edges"]["generator_link"]["senders"][i] + 1)) + g["gen_bus"] = bus_id + 1 + bus = case["bus"][bus_id+1] + @assert(bus["index"] == (bus_id + 1)) + g["gen_status"] = convert(Int8, bus["bus_type"] != 4) + bus["vm"] = g["vg"] + end + end + + if haskey(grid["edges"], "load_link") + load = case["load"] + load_links = grid["edges"]["load_link"]["receivers"] + if length(load_links) != length(load) + if length(load_links) > length(load) + Memento.warn(_LOGGER, "The last $(length(load_links) - length(load)) load links will be ignored due to too few loads.") + else + Memento.warn(_LOGGER, "The number of loads ($(length(load))) does not match the number of load link records ($(length(load_links))).") + end + end + + for (i, bus_id) in enumerate(load_links) + l = load[i] + @assert(l["index"] == (grid["edges"]["load_link"]["senders"][i] + 1)) + l["load_bus"] = bus_id + 1 + bus = case["bus"][bus_id+1] + @assert(bus["index"] == (bus_id + 1)) + l["status"] = convert(Int8, bus["bus_type"] != 4) + end + end + + if haskey(grid["edges"], "shunt_link") + shunt = case["shunt"] + shunt_links = grid["edges"]["shunt_link"]["receivers"] + if length(shunt_links) != length(shunt) + if length(shunt_links) > length(shunt) + Memento.warn(_LOGGER, "The last $(length(shunt_links) - length(shunt)) shunt links will be ignored due to too few shunts.") + else + Memento.warn(_LOGGER, "The number of shunts ($(length(shunt))) does not match the number of shunt link records ($(length(shunt_links))).") + end + end + + for (i, bus_id) in enumerate(shunt_links) + s = shunt[i] + @assert(s["index"] == (grid["edges"]["shunt_link"]["senders"][i] + 1)) + s["shunt_bus"] = bus_id + 1 + bus = case["bus"][bus_id+1] + @assert(bus["index"] == (bus_id + 1)) + s["status"] = convert(Int8, bus["bus_type"] != 4) + end + end + + + # merge ac and transformer lines + _merge_lines!(case) + + # use once available + _IM.arrays_to_dicts!(case) + + for optional in ["dcline", "storage", "switch"] + case[optional] = Dict{String,Any}() + end + + return case +end + + +function _merge_lines!(data::Dict{String,Any}) + i = 1 + branches = [] + for ac_line in data["ac_line"] + ac_line["index"] = i + ac_line["source_id"] = ["branch", i] + ac_line["g_fr"] = 0.0 + ac_line["g_to"] = 0.0 + + bus_f_id = ac_line["f_bus"] + bus_t_id = ac_line["t_bus"] + bus_f = data["bus"][bus_f_id] + bus_t = data["bus"][bus_t_id] + @assert(bus_f["index"] == bus_f_id && bus_t["index"] == bus_t_id) + ac_line["br_status"] = convert(Int8, (bus_f["bus_type"] != 4 && bus_t["bus_type"] != 4)) + + push!(branches, ac_line) + i = i + 1 + end + for transformer_line in data["transformer_line"] + transformer_line["index"] = i + transformer_line["source_id"] = ["branch", i] + transformer_line["g_fr"] = 0.0 + transformer_line["g_to"] = 0.0 + + bus_f_id = transformer_line["f_bus"] + bus_t_id = transformer_line["t_bus"] + bus_f = data["bus"][bus_f_id] + bus_t = data["bus"][bus_t_id] + @assert(bus_f["index"] == bus_f_id && bus_t["index"] == bus_t_id) + transformer_line["br_status"] = convert(Int8, (bus_f["bus_type"] != 4 && bus_t["bus_type"] != 4)) + + push!(branches, transformer_line) + i = i + 1 + end + + @assert(length(branches) == (length(data["ac_line"]) + length(data["transformer_line"]))) + + data["branch"] = branches + delete!(data, "ac_line") + delete!(data, "transformer_line") +end diff --git a/test/data/opfdata/example_0.json b/test/data/opfdata/example_0.json new file mode 100755 index 00000000..a9cb0e95 --- /dev/null +++ b/test/data/opfdata/example_0.json @@ -0,0 +1,819 @@ +{ + "grid": { + "nodes": { + "bus": [ + [ + 1.0, + 3.0, + 0.94, + 1.06 + ], + [ + 1.0, + 2.0, + 0.94, + 1.06 + ], + [ + 1.0, + 2.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 2.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 2.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ] + ], + "generator": [ + [ + 100.0, + 1.7, + 0.0, + 3.4, + 0.05, + 0.0, + 0.1, + 1.0, + 0.0, + 792.0951, + 0.0 + ], + [ + 100.0, + 0.295, + 0.0, + 0.59, + 0.0, + -0.3, + 0.3, + 1.0, + 0.0, + 2326.9494, + 0.0 + ], + [ + 100.0, + 0.0, + 0.0, + 0.0, + 0.2, + 0.0, + 0.4, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + 100.0, + 0.0, + 0.0, + 0.0, + 0.09, + -0.06, + 0.24, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + 100.0, + 0.0, + 0.0, + 0.0, + 0.09, + -0.06, + 0.24, + 1.0, + 0.0, + 0.0, + 0.0 + ] + ], + "load": [ + [ + 0.2064968603085452, + 0.14970012102581254 + ], + [ + 1.1002051072684056, + 0.1714825511014747 + ], + [ + 0.3943608959855351, + -0.037804557974875204 + ], + [ + 0.06668190870599361, + 0.016214559425100764 + ], + [ + 0.12996544121220546, + 0.08470456782124867 + ], + [ + 0.32785581198178226, + 0.15377685308840916 + ], + [ + 0.09412705665214886, + 0.058667037629714106 + ], + [ + 0.041504695520452786, + 0.01856651645742139 + ], + [ + 0.05395843642948829, + 0.014595172762052628 + ], + [ + 0.12600966456698398, + 0.06849096760427663 + ], + [ + 0.1421917673138311, + 0.0425031077329722 + ] + ], + "shunt": [ + [ + 0.19, + 0.0 + ] + ] + }, + "edges": { + "ac_line": { + "senders": [ + 0, + 0, + 1, + 1, + 1, + 2, + 3, + 5, + 5, + 5, + 6, + 6, + 8, + 8, + 9, + 11, + 12 + ], + "receivers": [ + 1, + 4, + 2, + 3, + 4, + 3, + 4, + 10, + 11, + 12, + 7, + 8, + 9, + 13, + 10, + 12, + 13 + ], + "features": [ + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0264, + 0.0264, + 0.01938, + 0.05917, + 4.72, + 4.72, + 4.72 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0246, + 0.0246, + 0.05403, + 0.22304, + 1.28, + 1.28, + 1.28 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0219, + 0.0219, + 0.04699, + 0.19797, + 1.45, + 1.45, + 1.45 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.017, + 0.017, + 0.05811, + 0.17632, + 1.58, + 1.58, + 1.58 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0173, + 0.0173, + 0.05695, + 0.17388, + 1.61, + 1.61, + 1.61 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0064, + 0.0064, + 0.06701, + 0.17103, + 1.6, + 1.6, + 1.6 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.01335, + 0.04211, + 6.64, + 6.64, + 6.64 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.09498, + 0.1989, + 1.34, + 1.34, + 1.34 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.12291, + 0.25581, + 1.04, + 1.04, + 1.04 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.06615, + 0.13027, + 2.01, + 2.01, + 2.01 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0, + 0.17615, + 1.67, + 1.67, + 1.67 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0, + 0.11001, + 2.67, + 2.67, + 2.67 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.03181, + 0.0845, + 3.25, + 3.25, + 3.25 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.12711, + 0.27038, + 0.99, + 0.99, + 0.99 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.08205, + 0.19207, + 1.41, + 1.41, + 1.41 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.22092, + 0.19988, + 0.99, + 0.99, + 0.99 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.17093, + 0.34802, + 0.76, + 0.76, + 0.76 + ] + ] + }, + "transformer": { + "senders": [ + 3, + 3, + 4 + ], + "receivers": [ + 6, + 8, + 5 + ], + "features": [ + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.20912, + 1.41, + 1.41, + 1.41, + 0.978, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.55618, + 0.53, + 0.53, + 0.53, + 0.969, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.25202, + 1.17, + 1.17, + 1.17, + 0.932, + 0.0, + 0.0, + 0.0 + ] + ] + }, + "generator_link": { + "senders": [ + 0, + 1, + 2, + 3, + 4 + ], + "receivers": [ + 0, + 1, + 2, + 5, + 7 + ] + }, + "load_link": { + "senders": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10 + ], + "receivers": [ + 1, + 2, + 3, + 4, + 5, + 8, + 9, + 10, + 11, + 12, + 13 + ] + }, + "shunt_link": { + "senders": [ + 0 + ], + "receivers": [ + 8 + ] + } + }, + "context": [ + [ + [ + 100.0 + ] + ] + ] + }, + "solution": { + "nodes": { + "bus": [ + [ + 2.4775200266473475e-31, + 1.0600000103691605 + ], + [ + -0.10936515403682097, + 1.0301606863390769 + ], + [ + -0.26452967867951566, + 1.0034791643261707 + ], + [ + -0.20219070004617962, + 1.0060273039838827 + ], + [ + -0.17282269743709677, + 1.0085894350144067 + ], + [ + -0.2742443761605617, + 1.060000009134775 + ], + [ + -0.2592157646298017, + 1.042345010996333 + ], + [ + -0.2592157646298017, + 1.0600000081556855 + ], + [ + -0.2888796610067986, + 1.0398564490216893 + ], + [ + -0.2918139024406198, + 1.0355705276181477 + ], + [ + -0.28588245327616424, + 1.043725041979354 + ], + [ + -0.2882368111860503, + 1.0452923403449919 + ], + [ + -0.28957378397709366, + 1.0394116621735408 + ], + [ + -0.30661392593243236, + 1.0230496481261293 + ] + ], + "generator": [ + [ + 2.8607094806933344, + 0.03883803174297159 + ], + [ + -9.960525574086827e-09, + 0.2999999959187748 + ], + [ + 0.0, + 0.3775503537844742 + ], + [ + 0.0, + 0.16841676819210616 + ], + [ + 0.0, + 0.10624068767218972 + ] + ] + }, + "edges": { + "ac_line": { + "senders": [ + 0, + 0, + 1, + 1, + 1, + 2, + 3, + 5, + 5, + 5, + 6, + 6, + 8, + 8, + 9, + 11, + 12 + ], + "receivers": [ + 1, + 4, + 2, + 3, + 4, + 3, + 4, + 10, + 11, + 12, + 7, + 8, + 9, + 13, + 10, + 12, + 13 + ], + "features": [ + [ + -1.9401959071725068, + 0.198205854780751, + 2.0098745150262443, + -0.04314632222308059 + ], + [ + -0.8154462896010738, + 0.01143784986760535, + 0.8508349656670903, + 0.08198435396605216 + ], + [ + -0.7802325301146458, + 0.09063140542771973, + 0.809232814354386, + -0.013746122792560163 + ], + [ + -0.5248575375823412, + 0.04337979522458124, + 0.5408849265657996, + -0.029995237573526748 + ], + [ + -0.37567463800551726, + -0.007652504047577559, + 0.3835812959832505, + -0.004164619521701804 + ], + [ + 0.32777427611572396, + -0.10844606986729738, + -0.3199725771537598, + 0.11543639725527978 + ], + [ + 0.6635935180436355, + -0.13862030850037205, + -0.6575622872555336, + 0.15764466269415023 + ], + [ + -0.08577596086033816, + -0.044065692610948295, + 0.08658675434550893, + 0.04576359558210482 + ], + [ + -0.07253218838787719, + -0.024824738568972278, + 0.07319330963974521, + 0.026200716336773622 + ], + [ + -0.16898410315871187, + -0.07747001169122589, + 0.1710999956595023, + 0.08163686454198744 + ], + [ + 3.423332111639397e-24, + 0.10624068767218972, + 7.392251840851995e-25, + -0.10447117915897003 + ], + [ + -0.29222489940924085, + -0.019188253847541855, + 0.29222489940924085, + 0.02791371303526831 + ], + [ + -0.05005238624955255, + -0.03362806854023472, + 0.05016024086480135, + 0.03391457325537413 + ], + [ + -0.08138993567884857, + -0.024711268391391213, + 0.08226859989003213, + 0.026580304890642496 + ], + [ + 0.04427126533988538, + 0.0254991761535269, + -0.044074670402596314, + -0.025038969089479376 + ], + [ + -0.01848284165315186, + -0.010147313625990206, + 0.018573751958388895, + 0.01022956580691965 + ], + [ + -0.06080183163498252, + -0.01779183934158099, + 0.06145728024487977, + 0.01912635771293946 + ] + ] + }, + "transformer": { + "senders": [ + 3, + 3, + 4 + ], + "receivers": [ + 6, + 8, + 5 + ], + "features": [ + [ + -0.29222489940924085, + 0.07655746612370172, + 0.29222489940924085, + -0.05899295378695506 + ], + [ + -0.1680597533273749, + 0.010363795180975823, + 0.1680597533273749, + 0.00421912371039617 + ], + [ + -0.46084550085696185, + -0.06988897609000844, + 0.46084550085696185, + 0.11862040325524349 + ] + ] + } + } + }, + "metadata": { + "objective": 2265.953939003096 + } +} \ No newline at end of file diff --git a/test/data/opfdata/example_1.json b/test/data/opfdata/example_1.json new file mode 100755 index 00000000..0601b95f --- /dev/null +++ b/test/data/opfdata/example_1.json @@ -0,0 +1,1513 @@ +{ + "grid": { + "nodes": { + "bus": [ + [ + 132.0, + 3.0, + 0.94, + 1.06 + ], + [ + 132.0, + 2.0, + 0.94, + 1.06 + ], + [ + 132.0, + 1.0, + 0.94, + 1.06 + ], + [ + 132.0, + 1.0, + 0.94, + 1.06 + ], + [ + 132.0, + 2.0, + 0.94, + 1.06 + ], + [ + 132.0, + 1.0, + 0.94, + 1.06 + ], + [ + 132.0, + 1.0, + 0.94, + 1.06 + ], + [ + 132.0, + 2.0, + 0.94, + 1.06 + ], + [ + 1.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 11.0, + 2.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 11.0, + 2.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 132.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ], + [ + 33.0, + 1.0, + 0.94, + 1.06 + ] + ], + "generator": [ + [ + 100.0, + 1.355, + 0.0, + 2.71, + 0.05, + 0.0, + 0.1, + 1.0, + 0.0, + 1842.1527999999998, + 0.0 + ], + [ + 100.0, + 0.46, + 0.0, + 0.92, + 0.03, + -0.4, + 0.46, + 1.0, + 0.0, + 5218.2254, + 0.0 + ], + [ + 100.0, + 0.0, + 0.0, + 0.0, + 0.0, + -0.4, + 0.4, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + 100.0, + 0.0, + 0.0, + 0.0, + 0.15, + -0.1, + 0.4, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + 100.0, + 0.0, + 0.0, + 0.0, + 0.09, + -0.06, + 0.24, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + 100.0, + 0.0, + 0.0, + 0.0, + 0.09, + -0.06, + 0.24, + 1.0, + 0.0, + 0.0, + 0.0 + ] + ], + "load": [ + [ + 0.21652305241199318, + 0.12376348024886435 + ], + [ + 0.02643281946015912, + 0.009677070918119146 + ], + [ + 0.0626898671202077, + 0.012970499088875303 + ], + [ + 0.7574961067768713, + 0.18765761625718425 + ], + [ + 0.1839784906861687, + 0.11381849030241858 + ], + [ + 0.3230830880761706, + 0.2591730372377266 + ], + [ + 0.06674703219765298, + 0.01647467277243695 + ], + [ + 0.11905680341274072, + 0.06906340472177369 + ], + [ + 0.05476471760480974, + 0.014543294337105406 + ], + [ + 0.0730562626769836, + 0.023026142841071004 + ], + [ + 0.04086626875413942, + 0.020039735329351514 + ], + [ + 0.0949552060048842, + 0.052359353350328285 + ], + [ + 0.03780679545140214, + 0.009050991683428076 + ], + [ + 0.0907085539521729, + 0.02862627471342287 + ], + [ + 0.019965888034575857, + 0.0071041840674242115 + ], + [ + 0.155450272127215, + 0.09781411404462223 + ], + [ + 0.0365784987692655, + 0.013426437502852205 + ], + [ + 0.08498102673303634, + 0.0788558874564282 + ], + [ + 0.0304221964104798, + 0.019859026028222922 + ], + [ + 0.027150508102412572, + 0.008281014403112633 + ], + [ + 0.08752229808584731, + 0.021312406186365842 + ] + ], + "shunt": [ + [ + 0.19, + 0.0 + ], + [ + 0.043, + 0.0 + ] + ] + }, + "edges": { + "ac_line": { + "senders": [ + 0, + 0, + 1, + 2, + 1, + 1, + 3, + 4, + 5, + 5, + 11, + 11, + 11, + 13, + 15, + 14, + 17, + 18, + 9, + 9, + 9, + 9, + 20, + 14, + 21, + 22, + 23, + 24, + 24, + 26, + 26, + 28, + 7, + 5 + ], + "receivers": [ + 1, + 2, + 3, + 3, + 4, + 5, + 5, + 6, + 6, + 7, + 13, + 14, + 15, + 14, + 16, + 17, + 18, + 19, + 19, + 16, + 20, + 21, + 21, + 22, + 23, + 23, + 24, + 25, + 26, + 28, + 29, + 29, + 27, + 27 + ], + "features": [ + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0264, + 0.0264, + 0.0192, + 0.0575, + 1.38, + 1.38, + 1.38 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0204, + 0.0204, + 0.0452, + 0.1652, + 1.52, + 1.52, + 1.52 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0184, + 0.0184, + 0.057, + 0.1737, + 1.39, + 1.39, + 1.39 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0042, + 0.0042, + 0.0132, + 0.0379, + 1.35, + 1.35, + 1.35 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0209, + 0.0209, + 0.0472, + 0.1983, + 1.44, + 1.44, + 1.44 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0187, + 0.0187, + 0.0581, + 0.1763, + 1.39, + 1.39, + 1.39 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0045, + 0.0045, + 0.0119, + 0.0414, + 1.48, + 1.48, + 1.48 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0102, + 0.0102, + 0.046, + 0.116, + 1.27, + 1.27, + 1.27 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0085, + 0.0085, + 0.0267, + 0.082, + 1.4, + 1.4, + 1.4 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0045, + 0.0045, + 0.012, + 0.042, + 1.48, + 1.48, + 1.48 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.1231, + 0.2559, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0662, + 0.1304, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0945, + 0.1987, + 0.3, + 0.3, + 0.3 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.221, + 0.1997, + 0.2, + 0.2, + 0.2 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0524, + 0.1923, + 0.38, + 0.38, + 0.38 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.1073, + 0.2185, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0639, + 0.1292, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.034, + 0.068, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0936, + 0.209, + 0.3, + 0.3, + 0.3 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0324, + 0.0845, + 0.33, + 0.33, + 0.33 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0348, + 0.0749, + 0.3, + 0.3, + 0.3 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0727, + 0.1499, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.0116, + 0.0236, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.1, + 0.202, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.115, + 0.179, + 0.26, + 0.26, + 0.26 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.132, + 0.27, + 0.29, + 0.29, + 0.29 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.1885, + 0.3292, + 0.27, + 0.27, + 0.27 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.2544, + 0.38, + 0.25, + 0.25, + 0.25 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.1093, + 0.2087, + 0.28, + 0.28, + 0.28 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.2198, + 0.4153, + 0.28, + 0.28, + 0.28 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.3202, + 0.6027, + 0.28, + 0.28, + 0.28 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.0, + 0.2399, + 0.4533, + 0.28, + 0.28, + 0.28 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0214, + 0.0214, + 0.0636, + 0.2, + 1.4, + 1.4, + 1.4 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0065, + 0.0065, + 0.0169, + 0.0599, + 1.49, + 1.49, + 1.49 + ] + ] + }, + "transformer": { + "senders": [ + 5, + 5, + 8, + 8, + 3, + 11, + 27 + ], + "receivers": [ + 8, + 9, + 10, + 9, + 11, + 12, + 26 + ], + "features": [ + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.208, + 1.42, + 1.42, + 1.42, + 0.978, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.556, + 0.53, + 0.53, + 0.53, + 0.969, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.208, + 1.42, + 1.42, + 1.42, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.11, + 2.67, + 2.67, + 2.67, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.256, + 1.15, + 1.15, + 1.15, + 0.932, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.14, + 2.1, + 2.1, + 2.1, + 1.0, + 0.0, + 0.0, + 0.0 + ], + [ + -0.5235987755982988, + 0.5235987755982988, + 0.0, + 0.396, + 0.75, + 0.75, + 0.75, + 0.968, + 0.0, + 0.0, + 0.0 + ] + ] + }, + "generator_link": { + "senders": [ + 0, + 1, + 2, + 3, + 4, + 5 + ], + "receivers": [ + 0, + 1, + 4, + 7, + 10, + 12 + ] + }, + "load_link": { + "senders": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20 + ], + "receivers": [ + 1, + 2, + 3, + 4, + 6, + 7, + 9, + 11, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 22, + 23, + 25, + 28, + 29 + ] + }, + "shunt_link": { + "senders": [ + 0, + 1 + ], + "receivers": [ + 9, + 23 + ] + } + }, + "context": [ + [ + [ + 100.0 + ] + ] + ] + }, + "solution": { + "nodes": { + "bus": [ + [ + 8.899178861374916e-38, + 1.0600000104281542 + ], + [ + -0.07169366888417153, + 1.035654766637396 + ], + [ + -0.11453853285234956, + 1.018186099864371 + ], + [ + -0.14090178421829788, + 1.008207549316904 + ], + [ + -0.20254059869265503, + 1.0010199735310297 + ], + [ + -0.1685654625062981, + 1.006334986268946 + ], + [ + -0.189701080201323, + 0.9967750540449741 + ], + [ + -0.1831434891670364, + 1.0083295730842874 + ], + [ + -0.22173903283938992, + 1.0405366273259862 + ], + [ + -0.24961816065478037, + 1.0375315000938554 + ], + [ + -0.22173903283938992, + 1.0600000099023368 + ], + [ + -0.23826921633117495, + 1.0493420234756932 + ], + [ + -0.23826921633117495, + 1.0600000102474922 + ], + [ + -0.2526843339988973, + 1.035536552068319 + ], + [ + -0.2544317419178337, + 1.0307327619482565 + ], + [ + -0.24852688404331555, + 1.0363314495665628 + ], + [ + -0.2534704831283395, + 1.0323039425514924 + ], + [ + -0.265499186303707, + 1.021263619351295 + ], + [ + -0.26797393986453055, + 1.019188742953146 + ], + [ + -0.2642900155341062, + 1.023033115114945 + ], + [ + -0.25657655278262226, + 1.0261319459503753 + ], + [ + -0.2563324097651539, + 1.0264677830407647 + ], + [ + -0.26081607833747883, + 1.020131120561785 + ], + [ + -0.26170350611208987, + 1.0143539295762207 + ], + [ + -0.25226065049496427, + 1.0130307646818613 + ], + [ + -0.2587001609736415, + 0.9976885093441253 + ], + [ + -0.2423992254245469, + 1.019577564468895 + ], + [ + -0.17928178432395442, + 1.0035669451400657 + ], + [ + -0.26175328849385887, + 1.0008617580171053 + ], + [ + -0.27308143191969747, + 0.990964460609117 + ] + ], + "generator": [ + [ + 2.1538324476831736, + 0.08384001816768105 + ], + [ + 0.5686901979744026, + 0.20151376322433404 + ], + [ + 0.0, + 0.257089882818105 + ], + [ + 0.0, + 0.4000000075650039 + ], + [ + 0.0, + 0.09918839290223347 + ], + [ + 0.0, + 0.08069618633803521 + ] + ] + }, + "edges": { + "ac_line": { + "senders": [ + 0, + 0, + 1, + 2, + 1, + 1, + 3, + 4, + 5, + 5, + 11, + 11, + 11, + 13, + 15, + 14, + 17, + 18, + 9, + 9, + 9, + 9, + 20, + 14, + 21, + 22, + 23, + 24, + 24, + 26, + 26, + 28, + 7, + 5 + ], + "receivers": [ + 1, + 2, + 3, + 3, + 4, + 5, + 5, + 6, + 6, + 7, + 13, + 14, + 15, + 14, + 16, + 17, + 18, + 19, + 19, + 16, + 20, + 21, + 21, + 22, + 23, + 23, + 24, + 25, + 26, + 28, + 29, + 29, + 27, + 27 + ], + "features": [ + [ + -1.3474154466772201, + 0.03215728428889365, + 1.3799802289371024, + 0.007388280660776659 + ], + [ + -0.7493646370990151, + -0.03102305745456937, + 0.7738522187460716, + 0.07645173750690439 + ], + [ + -0.41821671980572916, + -0.026386116329784215, + 0.4280279685582974, + 0.01784584199934017 + ], + [ + -0.7162689253223001, + -0.010838788019948743, + 0.722931817638856, + 0.021345986536450225 + ], + [ + -0.6748602410159549, + 0.009543235626286098, + 0.6963568294195787, + 0.037410166574537065 + ], + [ + -0.5572701867334374, + 0.02506802198454748, + 0.5751977942617534, + -0.009663009887301195 + ], + [ + -0.6357334637392992, + 0.14203704956210733, + 0.6407350907609158, + -0.13376779773628378 + ], + [ + 0.08317499296202294, + -0.07888462803222104, + -0.08263586576091649, + 0.059889030934634706 + ], + [ + -0.26715348364819164, + -0.03493386227019753, + 0.2690902949398659, + 0.023828821457732983 + ], + [ + -0.31228403026057316, + 0.1351016409349285, + 0.31366529521922615, + -0.13939968742609407 + ], + [ + -0.07135815818698725, + -0.02109802367019144, + 0.07199379728129517, + 0.02241938877363076 + ], + [ + -0.1655193943320805, + -0.061982547268625045, + 0.16746590184789886, + 0.06581675542667051 + ], + [ + -0.07199040890014369, + -0.03333146614749372, + 0.07254418470497091, + 0.034495860352987726 + ], + [ + -0.016527840066743276, + -0.006495451401265605, + 0.016593440582177505, + 0.006554729333086037 + ], + [ + -0.03106825654749812, + -0.013086646543471454, + 0.03112414014600427, + 0.013291730818142205 + ], + [ + -0.06035268141162057, + -0.014325767155286483, + 0.060748523747609334, + 0.015131839386539747 + ], + [ + -0.022513038368648312, + -0.0052083606231729225, + 0.02254588596021843, + 0.005274775471858406 + ], + [ + 0.06836568901541251, + 0.023758260954025796, + -0.06819551558352459, + -0.023417914090249948 + ], + [ + -0.08833157704998837, + -0.030862445021450007, + 0.0891145568048526, + 0.032610765200580864 + ], + [ + -0.0638869494573861, + -0.03927270680685683, + 0.06405793779370046, + 0.03971864860989688 + ], + [ + -0.1408939661255152, + -0.0903679858107505, + 0.14181994683038857, + 0.0923609730175068 + ], + [ + -0.06830215165758138, + -0.04247483147555051, + 0.06874852755427065, + 0.04339521313873842 + ], + [ + 0.014559251106031913, + 0.007452119997851757, + -0.014556306001699791, + -0.007446128233871722 + ], + [ + -0.04793685624387579, + -0.02970272114696327, + 0.04824244797423084, + 0.030320016442279895 + ], + [ + -0.05329377745415633, + -0.034323641613059244, + 0.053742900551549476, + 0.03502271147769876 + ], + [ + -0.01130839077590688, + -0.01617407903312683, + 0.011358357474610285, + 0.016276283644111062 + ], + [ + 0.02050117121081434, + -0.015671521402048142, + -0.02037885850297313, + 0.015885130650966844 + ], + [ + -0.0304221964104798, + -0.019859026028222922, + 0.03075953437266514, + 0.02036291134909768 + ], + [ + 0.051542911769888344, + 0.005230241100786739, + -0.051260705583479484, + -0.004691389947049537 + ], + [ + -0.05560550451012014, + -0.015214856503311017, + 0.05633474449681157, + 0.01659271531347042 + ], + [ + -0.05927272529503027, + -0.014766719674064394, + 0.06048937829248499, + 0.01705677826733705 + ], + [ + -0.028249572790817044, + -0.006545686512301449, + 0.02845499640770757, + 0.006933842100198384 + ], + [ + 0.010853601559447647, + -0.04886473620982171, + -0.01079905781559747, + 0.005725329392348864 + ], + [ + -0.17922063611863254, + -0.0013894704069128, + 0.1797600591327792, + -0.009827678819201333 + ] + ] + }, + "transformer": { + "senders": [ + 5, + 5, + 8, + 8, + 3, + 11, + 27 + ], + "receivers": [ + 8, + 9, + 10, + 9, + 11, + 12, + 26 + ], + "features": [ + [ + -0.2735828696449282, + 0.06512648198136864, + 0.2735828696449282, + -0.049932733831601225 + ], + [ + -0.15690513153593705, + 0.004500135164734983, + 0.15690513153593705, + 0.00822620707250881 + ], + [ + 0.0, + 0.09918839290223347, + 0.0, + -0.09736712722284248 + ], + [ + -0.2735828696449282, + -0.024530801303363787, + 0.2735828696449282, + 0.03224064524147385 + ], + [ + -0.43106068724690566, + -0.11191059923722803, + 0.43106068724690566, + 0.15802220299714143 + ], + [ + 0.0, + 0.08069618633803521, + 5.7358517763087185e-34, + -0.07988481003783465 + ], + [ + -0.1683670345591849, + -0.03887973468159421, + 0.1683670345591849, + 0.050254206616734506 + ] + ] + } + } + }, + "metadata": { + "objective": 6935.242110031468 + } +} \ No newline at end of file diff --git a/test/opfdata.jl b/test/opfdata.jl new file mode 100644 index 00000000..b7551fea --- /dev/null +++ b/test/opfdata.jl @@ -0,0 +1,79 @@ +@testset "test opfdata parser" begin + @testset "example 0 file" begin + result = solve_opf("../test/data/opfdata/example_0.json", ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 2265.9539492937015; atol = 1e-3) + end + + @testset "example 0 case opfdata (parse_file)" begin + data = PowerModels.parse_file("../test/data/opfdata/example_0.json") + @test isa(JSON.json(data), String) + + result = solve_opf(data, ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 2265.953939003096; atol = 1e-3) + end + + @testset "example 0 case opfdata (parse_opfdata)" begin + data = PowerModels.parse_opfdata("../test/data/opfdata/example_0.json") + @test isa(JSON.json(data), String) + + result = solve_opf(data, ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 2265.953939003096; atol = 1e-3) + end + + @testset "example 0 case opfdata (parse_opfdata; iostream)" begin + open("../test/data/opfdata/example_0.json") do f + data = PowerModels.parse_opfdata(f) + @test isa(JSON.json(data), String) + + result = solve_opf(data, ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 2265.953939003096; atol = 1e-3) + end + end + + @testset "example 1 file" begin + result = solve_opf("../test/data/opfdata/example_1.json", ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 6935.242110031468; atol = 1e-2) + end + + @testset "example 1 case opfdata (parse_file)" begin + data = PowerModels.parse_file("../test/data/opfdata/example_1.json") + @test isa(JSON.json(data), String) + + result = solve_opf(data, ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 6935.242110031468; atol = 1e-2) + end + + @testset "example 1 case opfdata (parse_opfdata)" begin + data = PowerModels.parse_opfdata("../test/data/opfdata/example_1.json") + @test isa(JSON.json(data), String) + + result = solve_opf(data, ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 6935.242110031468; atol = 1e-2) + end + + @testset "example 1 case opfdata (parse_opfdata; iostream)" begin + open("../test/data/opfdata/example_1.json") do f + data = PowerModels.parse_opfdata(f) + @test isa(JSON.json(data), String) + + result = solve_opf(data, ACPPowerModel, nlp_solver) + + @test result["termination_status"] == LOCALLY_SOLVED + @test isapprox(result["objective"], 6935.242110031468; atol = 1e-2) + end + end +end diff --git a/test/runtests.jl b/test/runtests.jl index f1dc0af1..183e81e1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -33,6 +33,8 @@ include("common.jl") include("matpower.jl") + include("opfdata.jl") + include("pti.jl") include("psse.jl")