From 59e8fb826968f110b40df6947de9f63f167a378e Mon Sep 17 00:00:00 2001 From: ccoffrin Date: Fri, 17 May 2019 15:57:40 -0500 Subject: [PATCH] add ! to mutating data functions, progress on #454 --- CHANGELOG.md | 1 + docs/src/network-data.md | 12 ++--- docs/src/result-data.md | 4 +- src/core/data.jl | 110 +++++++++++++++++++-------------------- src/io/common.jl | 20 +++---- src/io/json.jl | 2 +- src/io/matpower.jl | 6 +-- src/io/psse.jl | 2 +- src/util/obbt.jl | 4 +- test/common.jl | 12 ++--- test/data.jl | 88 +++++++++++++++---------------- test/modify.jl | 2 +- test/multi-nw-cnd.jl | 20 +++---- test/multiconductor.jl | 64 +++++++++++------------ test/multinetwork.jl | 38 +++++++------- test/opf-var.jl | 2 +- test/output.jl | 6 +-- test/psse.jl | 4 +- test/warmstart.jl | 8 +-- 19 files changed, 203 insertions(+), 202 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f314db04a..efaccebe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ PowerModels.jl Change Log ========================= ### Staged +- Renamed data functions to indicate when modification can occur - Renamed objective functions to make dcline flow costs more explicit ### Staged diff --git a/docs/src/network-data.md b/docs/src/network-data.md index 441ac8d24..158038a6b 100644 --- a/docs/src/network-data.md +++ b/docs/src/network-data.md @@ -133,11 +133,11 @@ The PowerModels network data dictionary differs from the Matpower format in the Data exchange via JSON files is ideal for building algorithms, however it is hard to for humans to read and process. To that end PowerModels provides various helper functions for manipulating the network data dictionary. -The first of these helper functions are `make_per_unit` and `make_mixed_units`, which convert the units of the data inside a network data dictionary. The *mixed units* format follows the unit conventions from Matpower and other common power network formats where some of the values are in per unit and others are the true values. These functions can be used as follows, +The first of these helper functions are `make_per_unit` and `make_mixed_units!`, which convert the units of the data inside a network data dictionary. The *mixed units* format follows the unit conventions from Matpower and other common power network formats where some of the values are in per unit and others are the true values. These functions can be used as follows, ``` network_data = PowerModels.parse_file("matpower/case3.m") PowerModels.print_summary(network_data) # default per-unit form -PowerModels.make_mixed_units(network_data) +PowerModels.make_mixed_units!(network_data) PowerModels.print_summary(network_data) # mixed units form ``` @@ -147,18 +147,18 @@ data = PowerModels.parse_file("matpower/case3.m") opf_result = run_ac_opf(data, JuMP.with_optimizer(Ipopt.Optimizer)) PowerModels.print_summary(opf_result["solution"]) -PowerModels.update_data(data, opf_result["solution"]) +PowerModels.update_data!(data, opf_result["solution"]) pf_result = run_ac_pf(data, JuMP.with_optimizer(Ipopt.Optimizer)) PowerModels.print_summary(pf_result["solution"]) ``` -A variety of helper functions are available for processing the topology of the network. For example, `connected_components` will compute the collections of buses that are connected by branches (i.e. the network's islands). By default PowerModels will attempt to solve all of the network components simultaneously. The `select_largest_component` function can be used to only consider the largest component in the network. Finally the `propagate_topology_status` can be used to explicitly deactivate components that are implicitly inactive due to the status of other components (e.g. deactivating branches based on the status of their connecting buses), like so, +A variety of helper functions are available for processing the topology of the network. For example, `connected_components` will compute the collections of buses that are connected by branches (i.e. the network's islands). By default PowerModels will attempt to solve all of the network components simultaneously. The `select_largest_component` function can be used to only consider the largest component in the network. Finally the `propagate_topology_status!` can be used to explicitly deactivate components that are implicitly inactive due to the status of other components (e.g. deactivating branches based on the status of their connecting buses), like so, ``` data = PowerModels.parse_file("matpower/case3.m") -PowerModels.propagate_topology_status(data) +PowerModels.propagate_topology_status!(data) opf_result = run_ac_opf(data, JuMP.with_optimizer(Ipopt.Optimizer)) ``` -The `test/data/matpower/case7_tplgy.m` case provides an example of the kind of component status deductions that can be made. The `propagate_topology_status` function can be helpful in diagnosing network models that converge to an infeasible solution. +The `test/data/matpower/case7_tplgy.m` case provides an example of the kind of component status deductions that can be made. The `propagate_topology_status!` function can be helpful in diagnosing network models that converge to an infeasible solution. For details on all of the network data helper functions see, `src/core/data.jl`. diff --git a/docs/src/result-data.md b/docs/src/result-data.md index 063411e96..3777e24de 100644 --- a/docs/src/result-data.md +++ b/docs/src/result-data.md @@ -81,10 +81,10 @@ PowerModels.print_summary(result["solution"]) ``` Because the data dictionary and the solution dictionary have the same structure -PowerModels provides an `update_data` helper function which can be used to +PowerModels provides an `update_data!` helper function which can be used to update a data dictionary with the values from a solution as follows, ``` -PowerModels.update_data(data, result["solution"]) +PowerModels.update_data!(data, result["solution"]) ``` diff --git a/src/core/data.jl b/src/core/data.jl index 975e78735..e68e688bc 100644 --- a/src/core/data.jl +++ b/src/core/data.jl @@ -198,7 +198,7 @@ component_table(data::Dict{String,<:Any}, component::String, args...) = Infrastr "recursively applies new_data to data, overwriting information" -function update_data(data::Dict{String,<:Any}, new_data::Dict{String,<:Any}) +function update_data!(data::Dict{String,<:Any}, new_data::Dict{String,<:Any}) if haskey(data, "conductors") && haskey(new_data, "conductors") if data["conductors"] != new_data["conductors"] Memento.error(LOGGER, "update_data requires datasets with the same number of conductors") @@ -232,23 +232,23 @@ end "Transforms network data into per-unit" -function make_per_unit(data::Dict{String,<:Any}) +function make_per_unit!(data::Dict{String,<:Any}) if !haskey(data, "per_unit") || data["per_unit"] == false data["per_unit"] = true mva_base = data["baseMVA"] if InfrastructureModels.ismultinetwork(data) for (i,nw_data) in data["nw"] - _make_per_unit(nw_data, mva_base) + _make_per_unit!(nw_data, mva_base) end else - _make_per_unit(data, mva_base) + _make_per_unit!(data, mva_base) end end end "" -function _make_per_unit(data::Dict{String,<:Any}, mva_base::Real) +function _make_per_unit!(data::Dict{String,<:Any}, mva_base::Real) # to be consistent with matpower's opf.flow_lim= 'I' with current magnitude # limit defined in MVA at 1 p.u. voltage ka_base = mva_base @@ -292,7 +292,7 @@ function _make_per_unit(data::Dict{String,<:Any}, mva_base::Real) apply_func(gen, "qmax", rescale) apply_func(gen, "qmin", rescale) - _rescale_cost_model(gen, mva_base) + _rescale_cost_model!(gen, mva_base) end end @@ -358,7 +358,7 @@ function _make_per_unit(data::Dict{String,<:Any}, mva_base::Real) apply_func(dcline, "qmaxf", rescale) apply_func(dcline, "qminf", rescale) - _rescale_cost_model(dcline, mva_base) + _rescale_cost_model!(dcline, mva_base) end end @@ -366,23 +366,23 @@ end "Transforms network data into mixed-units (inverse of per-unit)" -function make_mixed_units(data::Dict{String,<:Any}) +function make_mixed_units!(data::Dict{String,<:Any}) if haskey(data, "per_unit") && data["per_unit"] == true data["per_unit"] = false mva_base = data["baseMVA"] if InfrastructureModels.ismultinetwork(data) for (i,nw_data) in data["nw"] - _make_mixed_units(nw_data, mva_base) + _make_mixed_units!(nw_data, mva_base) end else - _make_mixed_units(data, mva_base) + _make_mixed_units!(data, mva_base) end end end "" -function _make_mixed_units(data::Dict{String,<:Any}, mva_base::Real) +function _make_mixed_units!(data::Dict{String,<:Any}, mva_base::Real) # to be consistent with matpower's opf.flow_lim= 'I' with current magnitude # limit defined in MVA at 1 p.u. voltage ka_base = mva_base @@ -425,7 +425,7 @@ function _make_mixed_units(data::Dict{String,<:Any}, mva_base::Real) apply_func(gen, "qmax", rescale) apply_func(gen, "qmin", rescale) - _rescale_cost_model(gen, 1.0/mva_base) + _rescale_cost_model!(gen, 1.0/mva_base) end end @@ -491,7 +491,7 @@ function _make_mixed_units(data::Dict{String,<:Any}, mva_base::Real) apply_func(dcline, "qmaxf", rescale) apply_func(dcline, "qminf", rescale) - _rescale_cost_model(dcline, 1.0/mva_base) + _rescale_cost_model!(dcline, 1.0/mva_base) end end @@ -499,7 +499,7 @@ end "" -function _rescale_cost_model(comp::Dict{String,<:Any}, scale::Real) +function _rescale_cost_model!(comp::Dict{String,<:Any}, scale::Real) if "model" in keys(comp) && "cost" in keys(comp) if comp["model"] == 1 for i in 1:2:length(comp["cost"]) @@ -812,7 +812,7 @@ end "checks that voltage angle differences are within 90 deg., if not tightens" -function check_voltage_angle_differences(data::Dict{String,<:Any}, default_pad = 1.0472) +function check_voltage_angle_differences!(data::Dict{String,<:Any}, default_pad = 1.0472) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_voltage_angle_differences does not yet support multinetwork data") end @@ -867,7 +867,7 @@ end "checks that each branch has a reasonable thermal rating-a, if not computes one" -function check_thermal_limits(data::Dict{String,<:Any}) +function check_thermal_limits!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_thermal_limits does not yet support multinetwork data") end @@ -932,7 +932,7 @@ end "checks that each branch has a reasonable current rating-a, if not computes one" -function check_current_limits(data::Dict{String,<:Any}) +function check_current_limits!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_current_limits does not yet support multinetwork data") end @@ -999,7 +999,7 @@ end "checks that all parallel branches have the same orientation" -function check_branch_directions(data::Dict{String,<:Any}) +function check_branch_directions!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_branch_directions does not yet support multinetwork data") end @@ -1112,7 +1112,7 @@ checks that each branch has a reasonable transformer parameters this is important because setting tap == 0.0 leads to NaN computations, which are hard to debug """ -function check_transformer_parameters(data::Dict{String,<:Any}) +function check_transformer_parameters!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_transformer_parameters does not yet support multinetwork data") end @@ -1224,7 +1224,7 @@ end "checks bus types are consistent with generator connections, if not, fixes them" -function check_bus_types(data::Dict{String,<:Any}) +function check_bus_types!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_bus_types does not yet support multinetwork data") end @@ -1264,7 +1264,7 @@ end "checks that parameters for dc lines are reasonable" -function check_dcline_limits(data::Dict{String,<:Any}) +function check_dcline_limits!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_dcline_limits does not yet support multinetwork data") end @@ -1370,21 +1370,21 @@ end "throws warnings if cost functions are malformed" -function check_cost_functions(data::Dict{String,<:Any}) +function check_cost_functions!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) Memento.error(LOGGER, "check_cost_functions does not yet support multinetwork data") end modified_gen = Set{Int}() for (i,gen) in data["gen"] - if _check_cost_function(i, gen, "generator") + if _check_cost_function!(i, gen, "generator") push!(modified_gen, gen["index"]) end end modified_dcline = Set{Int}() for (i, dcline) in data["dcline"] - if _check_cost_function(i, dcline, "dcline") + if _check_cost_function!(i, dcline, "dcline") push!(modified_dcline, dcline["index"]) end end @@ -1394,7 +1394,7 @@ end "" -function _check_cost_function(id, comp, type_name) +function _check_cost_function!(id, comp, type_name) #println(comp) modified = false @@ -1407,7 +1407,7 @@ function _check_cost_function(id, comp, type_name) Memento.error(LOGGER, "cost includes $(comp["ncost"]) points, but at least two points are required on $(type_name) $(id)") end - modified = _remove_pwl_cost_duplicates(id, comp, type_name) + modified = _remove_pwl_cost_duplicates!(id, comp, type_name) for i in 3:2:length(comp["cost"]) if comp["cost"][i-2] >= comp["cost"][i] @@ -1423,7 +1423,7 @@ function _check_cost_function(id, comp, type_name) end end end - modified |= _simplify_pwl_cost(id, comp, type_name) + modified |= _simplify_pwl_cost!(id, comp, type_name) elseif comp["model"] == 2 if length(comp["cost"]) != comp["ncost"] Memento.error(LOGGER, "ncost of $(comp["ncost"]) not consistent with $(length(comp["cost"])) cost values on $(type_name) $(id)") @@ -1438,7 +1438,7 @@ end "checks that each point in the a pwl function is unqiue, simplifies the function if duplicates appear" -function _remove_pwl_cost_duplicates(id, comp, type_name, tolerance = 1e-2) +function _remove_pwl_cost_duplicates!(id, comp, type_name, tolerance = 1e-2) @assert comp["model"] == 1 unique_costs = Float64[comp["cost"][1], comp["cost"][2]] @@ -1464,7 +1464,7 @@ end "checks the slope of each segment in a pwl function, simplifies the function if the slope changes is below a tolerance" -function _simplify_pwl_cost(id, comp, type_name, tolerance = 1e-2) +function _simplify_pwl_cost!(id, comp, type_name, tolerance = 1e-2) @assert comp["model"] == 1 slopes = Float64[] @@ -1504,7 +1504,7 @@ end "trims zeros from higher order cost terms" -function simplify_cost_terms(data::Dict{String,<:Any}) +function simplify_cost_terms!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) networks = data["nw"] else @@ -1561,7 +1561,7 @@ end "ensures all polynomial costs functions have the same number of terms" -function standardize_cost_terms(data::Dict{String,<:Any}; order=-1) +function standardize_cost_terms!(data::Dict{String,<:Any}; order=-1) comp_max_order = 1 if InfrastructureModels.ismultinetwork(data) @@ -1619,10 +1619,10 @@ function standardize_cost_terms(data::Dict{String,<:Any}; order=-1) for (i, network) in networks if haskey(network, "gen") - _standardize_cost_terms(network["gen"], comp_max_order, "generator") + _standardize_cost_terms!(network["gen"], comp_max_order, "generator") end if haskey(network, "dcline") - _standardize_cost_terms(network["dcline"], comp_max_order, "dcline") + _standardize_cost_terms!(network["dcline"], comp_max_order, "dcline") end end @@ -1630,7 +1630,7 @@ end "ensures all polynomial costs functions have at exactly comp_order terms" -function _standardize_cost_terms(components::Dict{String,<:Any}, comp_order::Int, cost_comp_name::String) +function _standardize_cost_terms!(components::Dict{String,<:Any}, comp_order::Int, cost_comp_name::String) modified = Set{Int}() for (i, comp) in components if haskey(comp, "model") && comp["model"] == 2 && length(comp["cost"]) != comp_order @@ -1663,19 +1663,19 @@ Works on a PowerModels data dict, so that a it can be used without a GenericPowe Warning: this implementation has quadratic complexity, in the worst case """ -function propagate_topology_status(data::Dict{String,<:Any}) +function propagate_topology_status!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) for (i,nw_data) in data["nw"] - _propagate_topology_status(nw_data) + _propagate_topology_status!(nw_data) end else - _propagate_topology_status(data) + _propagate_topology_status!(data) end end "" -function _propagate_topology_status(data::Dict{String,<:Any}) +function _propagate_topology_status!(data::Dict{String,<:Any}) buses = Dict(bus["bus_i"] => bus for (i,bus) in data["bus"]) for (i,load) in data["load"] @@ -1842,26 +1842,26 @@ function _propagate_topology_status(data::Dict{String,<:Any}) Memento.info(LOGGER, "topology status propagation fixpoint reached in $(iteration) rounds") - check_reference_buses(data) + check_reference_buses!(data) end """ determines the largest connected component of the network and turns everything else off """ -function select_largest_component(data::Dict{String,<:Any}) +function select_largest_component!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) for (i,nw_data) in data["nw"] - _select_largest_component(nw_data) + _select_largest_component!(nw_data) end else - _select_largest_component(data) + _select_largest_component!(data) end end "" -function _select_largest_component(data::Dict{String,<:Any}) +function _select_largest_component!(data::Dict{String,<:Any}) ccs = connected_components(data) Memento.info(LOGGER, "found $(length(ccs)) components") @@ -1877,26 +1877,26 @@ function _select_largest_component(data::Dict{String,<:Any}) end end - check_reference_buses(data) + check_reference_buses!(data) end """ checks that each connected components has a reference bus, if not, adds one """ -function check_reference_buses(data::Dict{String,<:Any}) +function check_reference_buses!(data::Dict{String,<:Any}) if InfrastructureModels.ismultinetwork(data) for (i,nw_data) in data["nw"] - _check_reference_buses(nw_data) + _check_reference_buses!(nw_data) end else - _check_reference_buses(data) + _check_reference_buses!(data) end end "" -function _check_reference_buses(data::Dict{String,<:Any}) +function _check_reference_buses!(data::Dict{String,<:Any}) bus_lookup = Dict(bus["bus_i"] => bus for (i,bus) in data["bus"]) bus_gen = bus_gen_lookup(data["gen"], data["bus"]) @@ -1920,7 +1920,7 @@ function _check_reference_buses(data::Dict{String,<:Any}) end for (i, cc) in enumerate(ccs_order) - check_component_refrence_bus(cc, bus_lookup, cc_gens[i]) + check_component_refrence_bus!(cc, bus_lookup, cc_gens[i]) end end @@ -1928,7 +1928,7 @@ end """ checks that a connected component has a reference bus, if not, adds one """ -function check_component_refrence_bus(component_bus_ids, bus_lookup, component_gens) +function check_component_refrence_bus!(component_bus_ids, bus_lookup, component_gens) refrence_buses = Set() for bus_id in component_bus_ids bus = bus_lookup[bus_id] @@ -1946,7 +1946,7 @@ function check_component_refrence_bus(component_bus_ids, bus_lookup, component_g gen_bus["bus_type"] = 3 Memento.warn(LOGGER, "setting bus $(gen_bus["index"]) as reference bus in connected component $(component_bus_ids), based on generator $(big_gen["index"])") else - Memento.warn(LOGGER, "no generators found in connected component $(component_bus_ids), try running propagate_topology_status") + Memento.warn(LOGGER, "no generators found in connected component $(component_bus_ids), try running propagate_topology_status!(") end end end @@ -2037,13 +2037,13 @@ end "Transforms single-conductor network data into multi-conductor data" -function make_multiconductor(data::Dict{String,<:Any}, conductors::Int) +function make_multiconductor!(data::Dict{String,<:Any}, conductors::Int) if InfrastructureModels.ismultinetwork(data) for (i,nw_data) in data["nw"] - _make_multiconductor(nw_data, conductors) + _make_multiconductor!(nw_data, conductors) end else - _make_multiconductor(data, conductors) + _make_multiconductor!(data, conductors) end end @@ -2059,7 +2059,7 @@ conductor_matrix = Set(["br_r", "br_x"]) "" -function _make_multiconductor(data::Dict{String,<:Any}, conductors::Real) +function _make_multiconductor!(data::Dict{String,<:Any}, conductors::Real) if haskey(data, "conductors") Memento.warn(LOGGER, "skipping network that is already multiconductor") return diff --git a/src/io/common.jl b/src/io/common.jl index e8c2b29e3..4ff0fd581 100644 --- a/src/io/common.jl +++ b/src/io/common.jl @@ -34,34 +34,34 @@ end Runs various data quality checks on a PowerModels data dictionary. Applies modifications in some cases. Reports modified component ids. """ -function check_network_data(data::Dict{String,<:Any}) +function check_network_data!(data::Dict{String,<:Any}) mod_bus = Dict{Symbol,Set{Int}}() mod_gen = Dict{Symbol,Set{Int}}() mod_branch = Dict{Symbol,Set{Int}}() mod_dcline = Dict{Symbol,Set{Int}}() check_conductors(data) - make_per_unit(data) + make_per_unit!(data) check_connectivity(data) - mod_branch[:xfer_fix] = check_transformer_parameters(data) - mod_branch[:vad_bounds] = check_voltage_angle_differences(data) - mod_branch[:mva_zero] = check_thermal_limits(data) - mod_branch[:orientation] = check_branch_directions(data) + mod_branch[:xfer_fix] = check_transformer_parameters!(data) + mod_branch[:vad_bounds] = check_voltage_angle_differences!(data) + mod_branch[:mva_zero] = check_thermal_limits!(data) + mod_branch[:orientation] = check_branch_directions!(data) check_branch_loops(data) - mod_dcline[:losses] = check_dcline_limits(data) + mod_dcline[:losses] = check_dcline_limits!(data) - mod_bus[:type] = check_bus_types(data) + mod_bus[:type] = check_bus_types!(data) check_voltage_setpoints(data) check_storage_parameters(data) - gen, dcline = check_cost_functions(data) + gen, dcline = check_cost_functions!(data) mod_gen[:cost_pwl] = gen mod_dcline[:cost_pwl] = dcline - simplify_cost_terms(data) + simplify_cost_terms!(data) return Dict( "bus" => mod_bus, diff --git a/src/io/json.jl b/src/io/json.jl index 69bc90d50..21ff85526 100644 --- a/src/io/json.jl +++ b/src/io/json.jl @@ -49,7 +49,7 @@ function parse_json(io::Union{IO,String}; kwargs...)::Dict{String,Any} end if get(kwargs, :validate, true) - PowerModels.check_network_data(pm_data) + PowerModels.check_network_data!(pm_data) end return pm_data diff --git a/src/io/matpower.jl b/src/io/matpower.jl index 556d115ec..7e588793e 100644 --- a/src/io/matpower.jl +++ b/src/io/matpower.jl @@ -9,7 +9,7 @@ function parse_matpower(file::Union{IO, String}; validate=true) mp_data = parse_matpower_file(file) pm_data = matpower_to_powermodels(mp_data) if validate - check_network_data(pm_data) + check_network_data!(pm_data) end return pm_data end @@ -640,11 +640,11 @@ function export_matpower(io::IO, data::Dict{String,Any}) #convert data to mixed unit if data["per_unit"] - make_mixed_units(data) + make_mixed_units!(data) end # make all costs have the name number of items (to prepare for table export) - standardize_cost_terms(data) + standardize_cost_terms!(data) # create some useful maps and data structures buses = Dict{Int, Dict}() diff --git a/src/io/psse.jl b/src/io/psse.jl index 2aa2d3e32..02d846850 100644 --- a/src/io/psse.jl +++ b/src/io/psse.jl @@ -698,7 +698,7 @@ function parse_psse(pti_data::Dict; import_all=false, validate=true)::Dict end if validate - check_network_data(pm_data) + check_network_data!(pm_data) end return pm_data diff --git a/src/util/obbt.jl b/src/util/obbt.jl index 3cc6ed0ef..2f9eef0d8 100644 --- a/src/util/obbt.jl +++ b/src/util/obbt.jl @@ -36,7 +36,7 @@ function constraint_obj_bound(pm::GenericPowerModel, bound) Memento.error(LOGGER, "Only quadratic generator cost models are supported at this time, given cost model of order $(cost_index-1)") end - PowerModels.standardize_cost_terms(pm.data, order=2) + PowerModels.standardize_cost_terms!(pm.data, order=2) from_idx = Dict(arc[1] => arc for arc in ref(pm, :arcs_from_dc)) @@ -401,7 +401,7 @@ function run_obbt_opf(data::Dict{String,<:Any}, optimizer; # populate the modifications, update the data, and rebuild the bound-tightening model modifications = create_modifications(model_bt, vm_lb, vm_ub, td_lb, td_ub) - PowerModels.update_data(data, modifications) + PowerModels.update_data!(data, modifications) model_bt = build_generic_model(data, model_constructor, PowerModels.post_opf) (upper_bound_constraint) && (constraint_obj_bound(model_bt, upper_bound)) vm = var(model_bt, :vm) diff --git a/test/common.jl b/test/common.jl index edae05cc7..ddbe86a49 100644 --- a/test/common.jl +++ b/test/common.jl @@ -29,7 +29,7 @@ function build_mn_data(base_data_1, base_data_2) delete!(data_2, "baseMVA") mn_data["nw"]["2"] = data_2 - PowerModels.standardize_cost_terms(mn_data) + PowerModels.standardize_cost_terms!(mn_data) return mn_data end @@ -37,14 +37,14 @@ end function build_mc_data(base_data; conductors::Int=3) mp_data = PowerModels.parse_file(base_data) - PowerModels.make_multiconductor(mp_data, conductors) + PowerModels.make_multiconductor!(mp_data, conductors) return mp_data end function build_mn_mc_data(base_data; replicates::Int=3, conductors::Int=3) mp_data = PowerModels.parse_file(base_data) - PowerModels.make_multiconductor(mp_data, conductors) + PowerModels.make_multiconductor!(mp_data, conductors) mn_mc_data = PowerModels.replicate(mp_data, replicates) mn_mc_data["conductors"] = mn_mc_data["nw"]["1"]["conductors"] return mn_mc_data @@ -59,11 +59,11 @@ function build_mn_mc_data(base_data_1, base_data_2; conductors_1::Int=3, conduct @assert mp_data_1["baseMVA"] == mp_data_2["baseMVA"] if conductors_1 > 0 - PowerModels.make_multiconductor(mp_data_1, conductors_1) + PowerModels.make_multiconductor!(mp_data_1, conductors_1) end if conductors_2 > 0 - PowerModels.make_multiconductor(mp_data_2, conductors_2) + PowerModels.make_multiconductor!(mp_data_2, conductors_2) end mn_data = Dict( @@ -84,7 +84,7 @@ function build_mn_mc_data(base_data_1, base_data_2; conductors_1::Int=3, conduct delete!(mp_data_2, "baseMVA") mn_data["nw"]["2"] = mp_data_2 - PowerModels.standardize_cost_terms(mn_data) + PowerModels.standardize_cost_terms!(mn_data) return mn_data end diff --git a/test/data.jl b/test/data.jl index 1d13081bc..137707ac3 100644 --- a/test/data.jl +++ b/test/data.jl @@ -83,8 +83,8 @@ end data = PowerModels.parse_file("../test/data/matpower/case3.m") data_base = deepcopy(data) - PowerModels.make_mixed_units(data) - PowerModels.make_per_unit(data) + PowerModels.make_mixed_units!(data) + PowerModels.make_per_unit!(data) @test InfrastructureModels.compare_dict(data, data_base) end @@ -92,8 +92,8 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_asym.m") data_base = deepcopy(data) - PowerModels.make_mixed_units(data) - PowerModels.make_per_unit(data) + PowerModels.make_mixed_units!(data) + PowerModels.make_per_unit!(data) @test InfrastructureModels.compare_dict(data, data_base) end @@ -101,8 +101,8 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_pwlc.m") data_base = deepcopy(data) - PowerModels.make_mixed_units(data) - PowerModels.make_per_unit(data) + PowerModels.make_mixed_units!(data) + PowerModels.make_per_unit!(data) @test InfrastructureModels.compare_dict(data, data_base) end @@ -110,8 +110,8 @@ end data = PowerModels.parse_file("../test/data/matpower/case24.m") data_base = deepcopy(data) - PowerModels.make_mixed_units(data) - PowerModels.make_per_unit(data) + PowerModels.make_mixed_units!(data) + PowerModels.make_per_unit!(data) @test InfrastructureModels.compare_dict(data, data_base) end @@ -121,8 +121,8 @@ end result = run_ac_opf("../test/data/matpower/case3.m", ipopt_solver) result_base = deepcopy(result) - PowerModels.make_mixed_units(result["solution"]) - PowerModels.make_per_unit(result["solution"]) + PowerModels.make_mixed_units!(result["solution"]) + PowerModels.make_per_unit!(result["solution"]) @test InfrastructureModels.compare_dict(result, result_base) end @@ -130,8 +130,8 @@ end result = run_ac_opf("../test/data/matpower/case5_asym.m", ipopt_solver, setting = Dict("output" => Dict("branch_flows" => true))) result_base = deepcopy(result) - PowerModels.make_mixed_units(result["solution"]) - PowerModels.make_per_unit(result["solution"]) + PowerModels.make_mixed_units!(result["solution"]) + PowerModels.make_per_unit!(result["solution"]) @test InfrastructureModels.compare_dict(result, result_base) end @@ -139,8 +139,8 @@ end result = run_ac_opf("../test/data/matpower/case24.m", ipopt_solver, setting = Dict("output" => Dict("branch_flows" => true))) result_base = deepcopy(result) - PowerModels.make_mixed_units(result["solution"]) - PowerModels.make_per_unit(result["solution"]) + PowerModels.make_mixed_units!(result["solution"]) + PowerModels.make_per_unit!(result["solution"]) @test InfrastructureModels.compare_dict(result, result_base) end @@ -150,8 +150,8 @@ end result = run_dc_opf("../test/data/matpower/case5.m", ipopt_solver, setting = Dict("output" => Dict("branch_flows" => true, "duals" => true))) result_base = deepcopy(result) - PowerModels.make_mixed_units(result["solution"]) - PowerModels.make_per_unit(result["solution"]) + PowerModels.make_mixed_units!(result["solution"]) + PowerModels.make_per_unit!(result["solution"]) @test InfrastructureModels.compare_dict(result, result_base) end @@ -164,7 +164,7 @@ end data_initial = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") data = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(data) + PowerModels.propagate_topology_status!(data) @test length(data_initial["bus"]) == length(data["bus"]) @test length(data_initial["gen"]) == length(data["gen"]) @@ -220,7 +220,7 @@ end @testset "connecected components with propagate topology status" begin data = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(data) + PowerModels.propagate_topology_status!(data) cc = PowerModels.connected_components(data) cc_ordered = sort(collect(cc); by=length) @@ -242,8 +242,8 @@ end data_initial = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") data = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(data) - PowerModels.select_largest_component(data) + PowerModels.propagate_topology_status!(data) + PowerModels.select_largest_component!(data) @test length(data_initial["bus"]) == length(data["bus"]) @test length(data_initial["gen"]) == length(data["gen"]) @@ -280,7 +280,7 @@ end @testset "output values" begin data = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(data) + PowerModels.propagate_topology_status!(data) result = run_opf(data, ACPPowerModel, ipopt_solver) @test result["status"] == :LocalOptimal @@ -316,17 +316,17 @@ end data["gen"]["1"]["model"] = 1 data["gen"]["1"]["ncost"] = 1 data["gen"]["1"]["cost"] = [0, 1, 0] - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(data)) data["gen"]["1"]["cost"] = [0, 0] - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(data)) data["gen"]["1"]["ncost"] = 2 data["gen"]["1"]["cost"] = [0, 1, 0, 2] - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(data)) data["gen"]["1"]["model"] = 2 - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(data)) # check_connectivity data["load"]["1"]["load_bus"] = 1000 @@ -361,34 +361,34 @@ end Memento.setlevel!(TESTLOG, "warn") data["gen"]["1"]["model"] = 3 - @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_mixed_units(data)) - @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_per_unit(data)) - @test_warn(TESTLOG, "Unknown cost model of type 3 on generator 1", PowerModels.check_cost_functions(data)) + @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_mixed_units!(data)) + @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_per_unit!(data)) + @test_warn(TESTLOG, "Unknown cost model of type 3 on generator 1", PowerModels.check_cost_functions!(data)) data["gen"]["1"]["model"] = 1 data["gen"]["1"]["cost"][3] = 3000 - @test_warn(TESTLOG, "pwl x value 3000 is outside the bounds 0.0-20.0 on generator 1", PowerModels.check_cost_functions(data)) + @test_warn(TESTLOG, "pwl x value 3000 is outside the bounds 0.0-20.0 on generator 1", PowerModels.check_cost_functions!(data)) data["dcline"]["1"]["loss0"] = -1.0 - @test_warn(TESTLOG, "this code only supports positive loss0 values, changing the value on dcline 1 from -100.0 to 0.0", PowerModels.check_dcline_limits(data)) + @test_warn(TESTLOG, "this code only supports positive loss0 values, changing the value on dcline 1 from -100.0 to 0.0", PowerModels.check_dcline_limits!(data)) data["dcline"]["1"]["loss1"] = -1.0 - @test_warn(TESTLOG, "this code only supports positive loss1 values, changing the value on dcline 1 from -1.0 to 0.0", PowerModels.check_dcline_limits(data)) + @test_warn(TESTLOG, "this code only supports positive loss1 values, changing the value on dcline 1 from -1.0 to 0.0", PowerModels.check_dcline_limits!(data)) @test data["dcline"]["1"]["loss0"] == 0.0 @test data["dcline"]["1"]["loss1"] == 0.0 data["dcline"]["1"]["loss1"] = 100.0 - @test_warn(TESTLOG, "this code only supports loss1 values < 1, changing the value on dcline 1 from 100.0 to 0.0", PowerModels.check_dcline_limits(data)) + @test_warn(TESTLOG, "this code only supports loss1 values < 1, changing the value on dcline 1 from 100.0 to 0.0", PowerModels.check_dcline_limits!(data)) delete!(data["branch"]["1"], "tap") - @test_warn(TESTLOG, "branch found without tap value, setting a tap to 1.0", PowerModels.check_transformer_parameters(data)) + @test_warn(TESTLOG, "branch found without tap value, setting a tap to 1.0", PowerModels.check_transformer_parameters!(data)) delete!(data["branch"]["1"], "shift") - @test_warn(TESTLOG, "branch found without shift value, setting a shift to 0.0", PowerModels.check_transformer_parameters(data)) + @test_warn(TESTLOG, "branch found without shift value, setting a shift to 0.0", PowerModels.check_transformer_parameters!(data)) data["branch"]["1"]["tap"] = -1.0 - @test_warn(TESTLOG, "branch found with non-positive tap value of -1.0, setting a tap to 1.0", PowerModels.check_transformer_parameters(data)) + @test_warn(TESTLOG, "branch found with non-positive tap value of -1.0, setting a tap to 1.0", PowerModels.check_transformer_parameters!(data)) Memento.setlevel!(TESTLOG, "error") end @@ -449,7 +449,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5.m") data["branch"]["4"]["br_status"] = 0 result = run_opf(data, ACPPowerModel, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))) - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) ac_flows = PowerModels.calc_branch_flow_ac(data) @@ -465,7 +465,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5.m") data["branch"]["4"]["br_status"] = 0 result = run_opf(data, ACRPowerModel, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))) - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) ac_flows = PowerModels.calc_branch_flow_ac(data) @@ -481,7 +481,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5.m") data["branch"]["4"]["br_status"] = 0 result = run_opf(data, DCPPowerModel, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))) - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) dc_flows = PowerModels.calc_branch_flow_dc(data) @@ -503,7 +503,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 result = run_opf(data, ACPPowerModel, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))) - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) balance = PowerModels.calc_power_balance(data) @@ -517,7 +517,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 result = run_opf(data, DCPPowerModel, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))) - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) balance = PowerModels.calc_power_balance(data) @@ -531,10 +531,10 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 result = run_opf(data, ACPPowerModel, ipopt_solver) - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) flows = PowerModels.calc_branch_flow_ac(data) - PowerModels.update_data(data, flows) + PowerModels.update_data!(data, flows) balance = PowerModels.calc_power_balance(data) @@ -548,10 +548,10 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 result = run_opf(data, DCPPowerModel, ipopt_solver) - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) flows = PowerModels.calc_branch_flow_dc(data) - PowerModels.update_data(data, flows) + PowerModels.update_data!(data, flows) balance = PowerModels.calc_power_balance(data) diff --git a/test/modify.jl b/test/modify.jl index b38fde412..1ae717c7e 100644 --- a/test/modify.jl +++ b/test/modify.jl @@ -51,7 +51,7 @@ } }") - PowerModels.update_data(data, data_delta) + PowerModels.update_data!(data, data_delta) result = run_opf(data, ACPPowerModel, ipopt_solver) @test result["status"] == :LocalOptimal diff --git a/test/multi-nw-cnd.jl b/test/multi-nw-cnd.jl index 7a283c710..66b884e4b 100644 --- a/test/multi-nw-cnd.jl +++ b/test/multi-nw-cnd.jl @@ -4,16 +4,16 @@ @testset "5-bus replicate case" begin mn_mc_data = build_mn_mc_data("../test/data/matpower/case5_dc.m") - PowerModels.make_mixed_units(mn_mc_data) - PowerModels.make_per_unit(mn_mc_data) + PowerModels.make_mixed_units!(mn_mc_data) + PowerModels.make_per_unit!(mn_mc_data) @test InfrastructureModels.compare_dict(mn_mc_data, build_mn_mc_data("../test/data/matpower/case5_dc.m")) end @testset "14+24 hybrid case" begin mn_mc_data = build_mn_mc_data("../test/data/matpower/case14.m", "../test/data/matpower/case24.m") - PowerModels.make_mixed_units(mn_mc_data) - PowerModels.make_per_unit(mn_mc_data) + PowerModels.make_mixed_units!(mn_mc_data) + PowerModels.make_per_unit!(mn_mc_data) @test InfrastructureModels.compare_dict(mn_mc_data, build_mn_mc_data("../test/data/matpower/case14.m", "../test/data/matpower/case24.m")) end @@ -23,7 +23,7 @@ @testset "topology processing" begin @testset "7-bus replicate status case" begin mn_mc_data = build_mn_mc_data("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(mn_mc_data) + PowerModels.propagate_topology_status!(mn_mc_data) active_buses = Set(["2", "4", "5", "7"]) active_branches = Set(["8"]) @@ -57,8 +57,8 @@ end @testset "7-bus replicate filer case" begin mn_mc_data = build_mn_mc_data("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(mn_mc_data) - PowerModels.select_largest_component(mn_mc_data) + PowerModels.propagate_topology_status!(mn_mc_data) + PowerModels.select_largest_component!(mn_mc_data) active_buses = Set(["4", "5", "7"]) active_branches = Set(["8"]) @@ -92,8 +92,8 @@ end @testset "7+14 hybrid filer case" begin mn_mc_data = build_mn_mc_data("../test/data/matpower/case7_tplgy.m", "../test/data/matpower/case14.m") - PowerModels.propagate_topology_status(mn_mc_data) - PowerModels.select_largest_component(mn_mc_data) + PowerModels.propagate_topology_status!(mn_mc_data) + PowerModels.select_largest_component!(mn_mc_data) case7_data = mn_mc_data["nw"]["1"] case14_data = mn_mc_data["nw"]["2"] @@ -265,7 +265,7 @@ @test result["status"] == :LocalOptimal @test isapprox(result["objective"], 90176.6; atol = 1e0) - PowerModels.update_data(mn_mc_data, result["solution"]) + PowerModels.update_data!(mn_mc_data, result["solution"]) @test !InfrastructureModels.compare_dict(mn_mc_data, build_mn_mc_data("../test/data/matpower/case5_dc.m", "../test/data/matpower/case5_asym.m", conductors_1=4, conductors_2=0)) end diff --git a/test/multiconductor.jl b/test/multiconductor.jl index ae8e7b628..0990d4637 100644 --- a/test/multiconductor.jl +++ b/test/multiconductor.jl @@ -81,16 +81,16 @@ end @testset "5-bus replicate case" begin mp_data = build_mc_data("../test/data/matpower/case5_dc.m") - PowerModels.make_mixed_units(mp_data) - PowerModels.make_per_unit(mp_data) + PowerModels.make_mixed_units!(mp_data) + PowerModels.make_per_unit!(mp_data) @test InfrastructureModels.compare_dict(mp_data, build_mc_data("../test/data/matpower/case5_dc.m")) end @testset "24-bus replicate case" begin mp_data = build_mc_data("../test/data/matpower/case24.m") - PowerModels.make_mixed_units(mp_data) - PowerModels.make_per_unit(mp_data) + PowerModels.make_mixed_units!(mp_data) + PowerModels.make_per_unit!(mp_data) @test InfrastructureModels.compare_dict(mp_data, build_mc_data("../test/data/matpower/case24.m")) end @@ -100,8 +100,8 @@ end @testset "topology processing" begin @testset "7-bus replicate status case" begin mp_data = build_mc_data("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(mp_data) - PowerModels.select_largest_component(mp_data) + PowerModels.propagate_topology_status!(mp_data) + PowerModels.select_largest_component!(mp_data) active_buses = Set(["4", "5", "7"]) active_branches = Set(["8"]) @@ -295,7 +295,7 @@ end @test result["status"] == :LocalOptimal @test isapprox(result["objective"], 52655.7; atol = 1e0) - PowerModels.update_data(mp_data, result["solution"]) + PowerModels.update_data!(mp_data, result["solution"]) @test !InfrastructureModels.compare_dict(mp_data, build_mc_data("../test/data/matpower/case5_asym.m")) end @@ -305,97 +305,97 @@ end mp_data_2p = PowerModels.parse_file("../test/data/matpower/case3.m") mp_data_3p = PowerModels.parse_file("../test/data/matpower/case3.m") - PowerModels.make_multiconductor(mp_data_2p, 2) - PowerModels.make_multiconductor(mp_data_3p, 3) + PowerModels.make_multiconductor!(mp_data_2p, 2) + PowerModels.make_multiconductor!(mp_data_3p, 3) - @test_throws(TESTLOG, ErrorException, PowerModels.update_data(mp_data_2p, mp_data_3p)) + @test_throws(TESTLOG, ErrorException, PowerModels.update_data!(mp_data_2p, mp_data_3p)) @test_throws(TESTLOG, ErrorException, PowerModels.check_keys(mp_data_3p, ["load"])) # check_cost_functions mp_data_3p["gen"]["1"]["model"] = 1 mp_data_3p["gen"]["1"]["ncost"] = 1 mp_data_3p["gen"]["1"]["cost"] = [0.0, 1.0, 0.0] - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(mp_data_3p)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(mp_data_3p)) mp_data_3p["gen"]["1"]["cost"] = [0.0, 0.0] - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(mp_data_3p)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(mp_data_3p)) mp_data_3p["gen"]["1"]["ncost"] = 2 mp_data_3p["gen"]["1"]["cost"] = [0.0, 1.0, 0.0, 2.0] - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(mp_data_3p)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(mp_data_3p)) mp_data_3p["gen"]["1"]["model"] = 2 - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(mp_data_3p)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(mp_data_3p)) Memento.setlevel!(TESTLOG, "info") mp_data_3p["gen"]["1"]["model"] = 3 - @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_mixed_units(mp_data_3p)) - @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_per_unit(mp_data_3p)) - @test_warn(TESTLOG, "Unknown cost model of type 3 on generator 1", PowerModels.check_cost_functions(mp_data_3p)) + @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_mixed_units!(mp_data_3p)) + @test_warn(TESTLOG, "Skipping cost model of type 3 in per unit transformation", PowerModels.make_per_unit!(mp_data_3p)) + @test_warn(TESTLOG, "Unknown cost model of type 3 on generator 1", PowerModels.check_cost_functions!(mp_data_3p)) mp_data_3p["gen"]["1"]["model"] = 1 mp_data_3p["gen"]["1"]["cost"][3] = 3000 - @test_warn(TESTLOG, "pwl x value 3000.0 is outside the bounds 0.0-60.0 on generator 1", PowerModels.check_cost_functions(mp_data_3p)) + @test_warn(TESTLOG, "pwl x value 3000.0 is outside the bounds 0.0-60.0 on generator 1", PowerModels.check_cost_functions!(mp_data_3p)) - @test_nowarn PowerModels.check_voltage_angle_differences(mp_data_3p) + @test_nowarn PowerModels.check_voltage_angle_differences!(mp_data_3p) mp_data_2p["branch"]["1"]["angmin"] = [-pi, 0] mp_data_2p["branch"]["1"]["angmax"] = [ pi, 0] @test_warn(TESTLOG, "this code only supports angmin values in -90 deg. to 90 deg., tightening the value on branch 1, conductor 1 from -180.0 to -60.0 deg.", - PowerModels.check_voltage_angle_differences(mp_data_2p)) + PowerModels.check_voltage_angle_differences!(mp_data_2p)) mp_data_2p["branch"]["1"]["angmin"] = [-pi, 0] mp_data_2p["branch"]["1"]["angmax"] = [ pi, 0] @test_warn(TESTLOG, "angmin and angmax values are 0, widening these values on branch 1, conductor 2 to +/- 60.0 deg.", - PowerModels.check_voltage_angle_differences(mp_data_2p)) + PowerModels.check_voltage_angle_differences!(mp_data_2p)) mp_data_2p["branch"]["1"]["angmin"] = [-pi, 0] mp_data_2p["branch"]["1"]["angmax"] = [ pi, 0] @test_warn(TESTLOG, "this code only supports angmax values in -90 deg. to 90 deg., tightening the value on branch 1, conductor 1 from 180.0 to 60.0 deg.", - PowerModels.check_voltage_angle_differences(mp_data_2p)) + PowerModels.check_voltage_angle_differences!(mp_data_2p)) - @test_warn(TESTLOG, "skipping network that is already multiconductor", PowerModels.make_multiconductor(mp_data_3p, 3)) + @test_warn(TESTLOG, "skipping network that is already multiconductor", PowerModels.make_multiconductor!(mp_data_3p, 3)) mp_data_3p["load"]["1"]["pd"] = mp_data_3p["load"]["1"]["qd"] = [0, 0, 0] mp_data_3p["shunt"]["1"] = Dict("gs"=>[0,0,0], "bs"=>[0,0,0], "status"=>1, "shunt_bus"=>1, "index"=>1) - Memento.TestUtils.@test_log(TESTLOG, "info", "deactivating load 1 due to zero pd and qd", PowerModels.propagate_topology_status(mp_data_3p)) + Memento.TestUtils.@test_log(TESTLOG, "info", "deactivating load 1 due to zero pd and qd", PowerModels.propagate_topology_status!(mp_data_3p)) @test mp_data_3p["load"]["1"]["status"] == 0 @test mp_data_3p["shunt"]["1"]["status"] == 0 mp_data_3p["dcline"]["1"]["loss0"][2] = -1.0 - @test_warn(TESTLOG, "this code only supports positive loss0 values, changing the value on dcline 1, conductor 2 from -100.0 to 0.0", PowerModels.check_dcline_limits(mp_data_3p)) + @test_warn(TESTLOG, "this code only supports positive loss0 values, changing the value on dcline 1, conductor 2 from -100.0 to 0.0", PowerModels.check_dcline_limits!(mp_data_3p)) mp_data_3p["dcline"]["1"]["loss1"][2] = -1.0 - @test_warn(TESTLOG, "this code only supports positive loss1 values, changing the value on dcline 1, conductor 2 from -1.0 to 0.0", PowerModels.check_dcline_limits(mp_data_3p)) + @test_warn(TESTLOG, "this code only supports positive loss1 values, changing the value on dcline 1, conductor 2 from -1.0 to 0.0", PowerModels.check_dcline_limits!(mp_data_3p)) @test mp_data_3p["dcline"]["1"]["loss0"][2] == 0.0 @test mp_data_3p["dcline"]["1"]["loss1"][2] == 0.0 mp_data_3p["dcline"]["1"]["loss1"][2] = 100.0 - @test_warn(TESTLOG, "this code only supports loss1 values < 1, changing the value on dcline 1, conductor 2 from 100.0 to 0.0", PowerModels.check_dcline_limits(mp_data_3p)) + @test_warn(TESTLOG, "this code only supports loss1 values < 1, changing the value on dcline 1, conductor 2 from 100.0 to 0.0", PowerModels.check_dcline_limits!(mp_data_3p)) delete!(mp_data_3p["branch"]["1"], "tap") - @test_warn(TESTLOG, "branch found without tap value, setting a tap to 1.0", PowerModels.check_transformer_parameters(mp_data_3p)) + @test_warn(TESTLOG, "branch found without tap value, setting a tap to 1.0", PowerModels.check_transformer_parameters!(mp_data_3p)) delete!(mp_data_3p["branch"]["1"], "shift") - @test_warn(TESTLOG, "branch found without shift value, setting a shift to 0.0", PowerModels.check_transformer_parameters(mp_data_3p)) + @test_warn(TESTLOG, "branch found without shift value, setting a shift to 0.0", PowerModels.check_transformer_parameters!(mp_data_3p)) mp_data_3p["branch"]["1"]["tap"][2] = -1.0 - @test_warn(TESTLOG, "branch found with non-positive tap value of -1.0, setting a tap to 1.0", PowerModels.check_transformer_parameters(mp_data_3p)) + @test_warn(TESTLOG, "branch found with non-positive tap value of -1.0, setting a tap to 1.0", PowerModels.check_transformer_parameters!(mp_data_3p)) mp_data_3p["branch"]["1"]["rate_a"][2] = -1.0 - @test_warn(TESTLOG, "this code only supports positive rate_a values, changing the value on branch 1, conductor 2 to 100.47", PowerModels.check_thermal_limits(mp_data_3p)) + @test_warn(TESTLOG, "this code only supports positive rate_a values, changing the value on branch 1, conductor 2 to 100.47", PowerModels.check_thermal_limits!(mp_data_3p)) @test isapprox(mp_data_3p["branch"]["1"]["rate_a"][2], 1.0047227335; atol=1e-6) mp_data_3p["branch"]["4"] = deepcopy(mp_data_3p["branch"]["1"]) mp_data_3p["branch"]["4"]["f_bus"] = mp_data_3p["branch"]["1"]["t_bus"] mp_data_3p["branch"]["4"]["t_bus"] = mp_data_3p["branch"]["1"]["f_bus"] - @test_warn(TESTLOG, "reversing the orientation of branch 1 (1, 3) to be consistent with other parallel branches", PowerModels.check_branch_directions(mp_data_3p)) + @test_warn(TESTLOG, "reversing the orientation of branch 1 (1, 3) to be consistent with other parallel branches", PowerModels.check_branch_directions!(mp_data_3p)) @test mp_data_3p["branch"]["4"]["f_bus"] == mp_data_3p["branch"]["1"]["f_bus"] @test mp_data_3p["branch"]["4"]["t_bus"] == mp_data_3p["branch"]["1"]["t_bus"] diff --git a/test/multinetwork.jl b/test/multinetwork.jl index ecc219e2d..e7768e9fb 100644 --- a/test/multinetwork.jl +++ b/test/multinetwork.jl @@ -7,15 +7,15 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "idempotent unit transformation" begin @testset "5-bus replicate case" begin mn_data = build_mn_data("../test/data/matpower/case5_dc.m") - PowerModels.make_mixed_units(mn_data) - PowerModels.make_per_unit(mn_data) + PowerModels.make_mixed_units!(mn_data) + PowerModels.make_per_unit!(mn_data) @test InfrastructureModels.compare_dict(mn_data, build_mn_data("../test/data/matpower/case5_dc.m")) end @testset "14+24 hybrid case" begin mn_data = build_mn_data("../test/data/matpower/case14.m", "../test/data/matpower/case24.m") - PowerModels.make_mixed_units(mn_data) - PowerModels.make_per_unit(mn_data) + PowerModels.make_mixed_units!(mn_data) + PowerModels.make_per_unit!(mn_data) @test InfrastructureModels.compare_dict(mn_data, build_mn_data("../test/data/matpower/case14.m", "../test/data/matpower/case24.m")) end @@ -25,7 +25,7 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "topology processing" begin @testset "7-bus replicate status case" begin mn_data = build_mn_data("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(mn_data) + PowerModels.propagate_topology_status!(mn_data) active_buses = Set(["2", "4", "5", "7"]) active_branches = Set(["8"]) @@ -59,8 +59,8 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "7-bus replicate filer case" begin mn_data = build_mn_data("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(mn_data) - PowerModels.select_largest_component(mn_data) + PowerModels.propagate_topology_status!(mn_data) + PowerModels.select_largest_component!(mn_data) active_buses = Set(["4", "5", "7"]) active_branches = Set(["8"]) @@ -94,8 +94,8 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "7+14 hybrid filer case" begin mn_data = build_mn_data("../test/data/matpower/case7_tplgy.m", "../test/data/matpower/case14.m") - PowerModels.propagate_topology_status(mn_data) - PowerModels.select_largest_component(mn_data) + PowerModels.propagate_topology_status!(mn_data) + PowerModels.select_largest_component!(mn_data) case7_data = mn_data["nw"]["1"] case14_data = mn_data["nw"]["2"] @@ -292,7 +292,7 @@ TESTLOG = Memento.getlogger(PowerModels) @test opf_result["status"] == :LocalOptimal @test isapprox(opf_result["objective"], 35103.8; atol = 1e0) - PowerModels.update_data(mn_data, opf_result["solution"]) + PowerModels.update_data!(mn_data, opf_result["solution"]) pf_result = PowerModels.run_mn_pf(mn_data, ACPPowerModel, ipopt_solver) @test pf_result["status"] == :LocalOptimal @@ -326,21 +326,21 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "test errors and warnings" begin mn_data = build_mn_data("../test/data/matpower/case5.m") - @test_throws(TESTLOG, ErrorException, PowerModels.check_voltage_angle_differences(mn_data)) - @test_throws(TESTLOG, ErrorException, PowerModels.check_thermal_limits(mn_data)) - @test_throws(TESTLOG, ErrorException, PowerModels.check_branch_directions(mn_data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_voltage_angle_differences!(mn_data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_thermal_limits!(mn_data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_branch_directions!(mn_data)) @test_throws(TESTLOG, ErrorException, PowerModels.check_branch_loops(mn_data)) @test_throws(TESTLOG, ErrorException, PowerModels.check_connectivity(mn_data)) - @test_throws(TESTLOG, ErrorException, PowerModels.check_transformer_parameters(mn_data)) - @test_throws(TESTLOG, ErrorException, PowerModels.check_bus_types(mn_data)) - @test_throws(TESTLOG, ErrorException, PowerModels.check_dcline_limits(mn_data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_transformer_parameters!(mn_data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_bus_types!(mn_data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_dcline_limits!(mn_data)) @test_throws(TESTLOG, ErrorException, PowerModels.check_voltage_setpoints(mn_data)) - @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions(mn_data)) + @test_throws(TESTLOG, ErrorException, PowerModels.check_cost_functions!(mn_data)) @test_throws(TESTLOG, ErrorException, PowerModels.connected_components(mn_data)) Memento.setlevel!(TESTLOG, "warn") - @test_nowarn PowerModels.check_reference_buses(mn_data) - @test_nowarn PowerModels.make_multiconductor(mn_data, 3) + @test_nowarn PowerModels.check_reference_buses!(mn_data) + @test_nowarn PowerModels.make_multiconductor!(mn_data, 3) @test_nowarn PowerModels.check_conductors(mn_data) Memento.setlevel!(TESTLOG, "error") diff --git a/test/opf-var.jl b/test/opf-var.jl index a1cc6f284..1c5194e9f 100644 --- a/test/opf-var.jl +++ b/test/opf-var.jl @@ -2,7 +2,7 @@ function build_current_data(base_data) c_data = PowerModels.parse_file(base_data) - PowerModels.check_current_limits(c_data) + PowerModels.check_current_limits!(c_data) for (i,branch) in c_data["branch"] delete!(branch, "rate_a") end diff --git a/test/output.jl b/test/output.jl index cf452f541..8aae5a0f1 100644 --- a/test/output.jl +++ b/test/output.jl @@ -72,7 +72,7 @@ end settings = Dict("output" => Dict("duals" => true)) result = run_dc_opf("../test/data/matpower/case14.m", ipopt_solver, setting = settings) - PowerModels.make_mixed_units(result["solution"]) + PowerModels.make_mixed_units!(result["solution"]) @testset "14 bus - kcl duals" begin for (i, bus) in result["solution"]["bus"] @test haskey(bus, "lam_kcl_r") @@ -94,7 +94,7 @@ end result = run_dc_opf("../test/data/matpower/case5.m", ipopt_solver, setting = settings) - PowerModels.make_mixed_units(result["solution"]) + PowerModels.make_mixed_units!(result["solution"]) @testset "5 bus - kcl duals" begin for (i, bus) in result["solution"]["bus"] @test bus["lam_kcl_r"] <= -9.00 @@ -124,7 +124,7 @@ end @test opf_result["status"] == :LocalOptimal @test isapprox(opf_result["objective"], ac_opf_obj; atol = 1e0) - PowerModels.update_data(data, opf_result["solution"]) + PowerModels.update_data!(data, opf_result["solution"]) pf_result = run_ac_pf(data, ipopt_solver) @test pf_result["status"] == :LocalOptimal diff --git a/test/psse.jl b/test/psse.jl index fa58860f2..2788d01c1 100644 --- a/test/psse.jl +++ b/test/psse.jl @@ -138,8 +138,8 @@ end data_pti = PowerModels.parse_file("../test/data/pti/case7_tplgy.raw") data_mp = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") - PowerModels.propagate_topology_status(data_pti) - PowerModels.propagate_topology_status(data_mp) + PowerModels.propagate_topology_status!(data_pti) + PowerModels.propagate_topology_status!(data_mp) set_costs!(data_mp) diff --git a/test/warmstart.jl b/test/warmstart.jl index bf07409b1..18a00d458 100644 --- a/test/warmstart.jl +++ b/test/warmstart.jl @@ -42,7 +42,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5.m") result = run_dc_opf(data, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))); - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) # 14 iterations result = run_dc_opf(data, ipopt_solver); @@ -57,7 +57,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_pwlc.m") result = run_dc_opf(data, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))); - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) # 35 iterations result = run_dc_opf(data, ipopt_solver); @@ -75,7 +75,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5.m") result = run_ac_opf(data, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))); - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) # 22 iterations result = run_ac_opf(data, ipopt_solver); @@ -90,7 +90,7 @@ end data = PowerModels.parse_file("../test/data/matpower/case5_pwlc.m") result = run_ac_opf(data, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true))); - PowerModels.update_data(data, result["solution"]) + PowerModels.update_data!(data, result["solution"]) # 40 iterations result = run_ac_opf(data, ipopt_solver);