Skip to content

Commit

Permalink
REF: Update to PowerModels v0.12 conventions (#149)
Browse files Browse the repository at this point in the history
* UPD: PowerModels v0.11 (#141)

* UPD: PowerModels v0.11 Compatibilty

* REF: rename internal functions

* UPD: PMs version req in docs

* ADD: export.jl

Adds explicit exports

* PowerModels v0.12 update (#142)

* UPD: function names

* UPD: LOGGER to internal global

* UPD: function names

Updated constraint names to be more consistent with PowerModels

PMs to _PMs const

constraint_tp_voltage -> constraint_tp_model_voltage
constraint_kcl_... -> constraint_power_balance_...
constraint_tp_branch_current -> constraint_tp_model_current
constraint_ohms_tp_yt_... -> constraint_tp_ohms_yt_...
constraint_voltage_magnitude_difference -> constraint_tp_voltage_magnitude_difference
constraint_flow_losses -> constraint_tp_flow_losses
add_... -> add_...!

* UPD: cm -> ccm

* REM: unused function commented out

constraint_tp_flow_losses function is duplicate and old one no longer used?

* ADD: auto export

* UPD: changelog

* UPD: manifest for PowerModels#master

* UPD: PMs version in Docs

* FIX: update function names

Updates function names from load models PR (#123) to new names / conventions

* UPD: add_arcs_trans!

Rename `add_arcs_trans!` -> `ref_add_arcs_trans!`

Moves `ref_add_arcs_trans!` to `ref_extensions` in build model step

Removes explicit exports (handled by `src/core/export.jl` automatically)

Closes #144

* UPD: calc_tp_voltage_product_bounds

renames calc_tp_voltage_product_bounds -> _calc_tp_voltage_product_bounds to be consistent with internal function naming conventions

* UPD: Function names and Docs updates

Documentation updates:
- all functions have docstrings (empty incl.)
- enforces two lines between function definitions
- single line docstrings are always wrapped in single double quotes, instead of triple double quotes

Refactors:
- Moves `_wrap_to_180`, `_wrap_to_pi` and `_roll` to `core/data.jl`

Function renames:
- roll -> _roll
- sqr -> _sqr
- double_operators -> _double_operators
- single_operators -> _single_operators
- parse_conn -> _parse_conn
- isa_conn -> _isa_conn
- get_prop_name -> _get_prop_name
- parse_matrix -> _parse_matrix
- parse_array -> _parse_array
- parse_rpn -> _parse_rpn
- parse_buscoords -> _parse_buscoords
- parse_element_with_dtype -> _parse_element_with_dtype
- parse_busname -> _parse_busname
- get_conductors_ordered -> _get_conductors_orders
- to_sym_keys -> _to_sym_keys
- to_meters -> _convert_to_meters
- parse_matlab_string -> _parse_matlab_string
- ml2pm_bus -> ml2tppm_bus!
- ml2pm_load -> ml2tppm_load!
- ml2pm_shunt -> ml2tppm_shunt!
- ml2pm_gen -> ml2tppm_gen!
- ml2pm_branch -> ml2tppm_branch!
- dss2tppm_bus! -> _dss2tppm_bus!
- dss2tppm_load! -> _dss2tppm_load!
- dss2tppm_shunt! -> _dss2tppm_shunt!
- dss2tppm_gen! -> _dss2tppm_gen!
- dss2tppm_branch! -> _dss2tppm_branch!
- dss2tppm_transformer! -> _dss2tppm_transformer!
- dss2tppm_reactor! -> _dss2tppm_reactor!
- dss2tppm_pvsystem! -> _dss2tppm_pvsystem
- dss2tppm_storage! -> _dss2tppm_storage!
- correct_duplicate_components -> _correct_duplicate_components
- get_pbs_solution -> solution_pbs!
- add_bus_slack_setpoint -> add_setpoint_bus_slack!
- get_solution_tp -> solution_tp!

Fixes:
- some run_tp_... functions pointed to the wrong post_tp_... function, fixed
- added some run_tp_... functions to parse files (storage)
- simplified run_tp_... functions that parse files

* UPD: voltage balance constraints function updates

- fix PMs function names
- PMs -> _PMs
- move add_arcs_trans! -> ref_extensions

* UPD: v0.5

* REF: move solution functions

moves solution related functions to core/solution.jl

* FIX: broken function names

* REF: Move types to core/types.jl

* UPD: dss_structs names

Update names to follow pep8 naming conventions (not a struct, don't use camelcase
  • Loading branch information
pseudocubic authored Jul 1, 2019
1 parent 846c398 commit 149a1ff
Show file tree
Hide file tree
Showing 57 changed files with 2,686 additions and 2,677 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
PowerModelsDistribution.jl Change Log
===================================

### staged
- none

### v0.5.0
- Enforce function naming conventions (starts with `_`: internal function; ends with `!`: transforms data; `correct_`: corrects network data; `check_`: warnings about network data) (breaking)
- Update for PowerModels.jl v0.12 (breaking)
- Enforce constraint/variable naming conventions to include `_tp` (breaking)
- Add automatic export of non-internal functions (all functions not prefixed with `_`)
- Enforce function naming conventions (starts with `_`: internal function; ends with `!`: transforms data; `correct_`: corrects network data; `check_`: warnings about network data)

### v0.4
- First version of PowerModelsDistribution.jl

Expand All @@ -14,6 +24,7 @@ PowerModelsDistribution.jl Change Log
- Fix bug in OpenDSS parse of Capacitors [zbase factor and wrong sign] (#138)
- Add voltage balance constraints (#129)


### v0.3.0
- Update to JuMP v0.19/MathOptInterface

Expand Down
34 changes: 15 additions & 19 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ version = "0.10.3"

[[InfrastructureModels]]
deps = ["JuMP", "Memento"]
git-tree-sha1 = "ec3f1ba27dbfd29a93f3c520ee189ce32deec049"
git-tree-sha1 = "131d2d24a2a0d404f59dceab2fb8f8cca2aadce5"
uuid = "2030c09a-7f63-5d83-885d-db604e0e9cc0"
version = "0.2.0"
version = "0.2.1"

[[InteractiveUtils]]
deps = ["Markdown"]
Expand Down Expand Up @@ -141,12 +141,6 @@ git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.2"

[[Nullables]]
deps = ["Compat"]
git-tree-sha1 = "ae1a63457e14554df2159b0b028f48536125092d"
uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd"
version = "0.0.8"

[[OrderedCollections]]
deps = ["Random", "Serialization", "Test"]
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
Expand All @@ -159,9 +153,11 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PowerModels]]
deps = ["InfrastructureModels", "JSON", "JuMP", "LinearAlgebra", "MathOptInterface", "Memento", "SparseArrays"]
git-tree-sha1 = "07ab528b4c9316a17cdd8d207f260c11efa6688d"
git-tree-sha1 = "9538663d7a58472d0a642a3efa97cc97481353f2"
repo-rev = "master"
repo-url = "https://github.com/lanl-ansi/PowerModels.jl.git"
uuid = "c36e90e8-916a-50a6-bd94-075b64ef4655"
version = "0.10.0"
version = "0.12.0"

[[Printf]]
deps = ["Unicode"]
Expand Down Expand Up @@ -199,30 +195,30 @@ uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "0.7.2"

[[StaticArrays]]
deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"]
git-tree-sha1 = "3841b39ed5f047db1162627bf5f80a9cd3e39ae2"
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "db23bbf50064c582b6f2b9b043c8e7e98ea8c0c6"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "0.10.3"
version = "0.11.0"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[Syslogs]]
deps = ["Compat", "Nullables"]
git-tree-sha1 = "d3e512a044cc8873c741d88758f8e1888c7c47d3"
deps = ["Printf", "Sockets"]
git-tree-sha1 = "46badfcc7c6e74535cc7d833a91f4ac4f805f86d"
uuid = "cea106d9-e007-5e6c-ad93-58fe2094e9c4"
version = "0.2.0"
version = "0.3.0"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[TimeZones]]
deps = ["Dates", "EzXML", "Mocking", "Printf", "Serialization", "Test", "Unicode"]
git-tree-sha1 = "fdf5d2136d16498cb67d648cedd33b83c599e0c5"
deps = ["Dates", "EzXML", "Mocking", "Printf", "Serialization", "Unicode"]
git-tree-sha1 = "859bfc1832ea52e413c96fa5c92130516db62bdb"
uuid = "f269a46b-ccf7-5d73-abea-4c690281aa53"
version = "0.9.0"
version = "0.9.1"

[[URIParser]]
deps = ["Test", "Unicode"]
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "PowerModelsDistribution"
uuid = "d7431456-977f-11e9-2de3-97ff7677985e"
authors = ["David M Fobes <[email protected]>", "Carleton Coffrin"]
repo = "https://github.com/lanl-ansi/PowerModelsDistribution.jl.git"
version = "0.4.0"
version = "0.5.0"

[deps]
InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0"
Expand All @@ -20,7 +20,7 @@ JuMP = "^0.19.2"
JSON = ">= 0.18"
Juniper = ">= 0.4"
Memento = ">= 0.8, < 0.13"
PowerModels = "^0.10"
PowerModels = "^0.12"
SCS = ">= 0.4"
julia = "^1"

Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"

[compat]
InfrastructureModels = "~0.2"
PowerModels = "~0.10"
PowerModels = "~0.12"
4 changes: 2 additions & 2 deletions docs/src/quickguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The following example demonstrates how to break a `run_tp_opf` call into seperat

```julia
data = PowerModelsDistribution.parse_file("case3_unbalanced.dss")
pm = PowerModels.build_generic_model(data, ACPPowerModel, PowerModelsDistribution.post_tp_opf; multiconductor=true)
pm = PowerModels.build_model(data, ACPPowerModel, PowerModelsDistribution.post_tp_opf; multiconductor=true)
print(pm.model)
solve_generic_model(pm, IpoptSolver())
optimize_model!(pm, IpoptSolver())
```
24 changes: 12 additions & 12 deletions docs/src/specifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ variable_tp_oltc_tap(pm)

### Constraints
```julia
constraint_tp_voltage(pm)
constraint_tp_model_voltage(pm)

for i in PMs.ids(pm, :ref_buses)
constraint_tp_theta_ref(pm, i)
end

for i in PMs.ids(pm, :bus), c in PMs.conductor_ids(pm)
constraint_kcl_shunt_trans(pm, i, cnd=c)
constraint_tp_power_balance_shunt_trans(pm, i, cnd=c)
end

for i in PMs.ids(pm, :branch)
for c in PMs.conductor_ids(pm)
constraint_ohms_tp_yt_from(pm, i, cnd=c)
constraint_ohms_tp_yt_to(pm, i, cnd=c)
constraint_tp_ohms_yt_from(pm, i, cnd=c)
constraint_tp_ohms_yt_to(pm, i, cnd=c)

PMs.constraint_voltage_angle_difference(pm, i, cnd=c)

Expand Down Expand Up @@ -77,14 +77,14 @@ variable_tp_oltc_tap(pm)

### Constraints
```julia
constraint_tp_voltage(pm)
constraint_tp_model_voltage(pm)

for i in PMs.ids(pm, :ref_buses)
constraint_tp_theta_ref(pm, i)
end

for i in PMs.ids(pm, :bus), c in PMs.conductor_ids(pm)
constraint_kcl_shunt_trans_load(pm, i, cnd=c)
constraint_tp_power_balance_shunt_trans_load(pm, i, cnd=c)
end

for id in PMs.ids(pm, :load)
Expand All @@ -102,8 +102,8 @@ end

for i in PMs.ids(pm, :branch)
for c in PMs.conductor_ids(pm)
constraint_ohms_tp_yt_from(pm, i, cnd=c)
constraint_ohms_tp_yt_to(pm, i, cnd=c)
constraint_tp_ohms_yt_from(pm, i, cnd=c)
constraint_tp_ohms_yt_to(pm, i, cnd=c)

PMs.constraint_voltage_angle_difference(pm, i, cnd=c)

Expand Down Expand Up @@ -140,7 +140,7 @@ variable_tp_trans_flow(pm, bounded=false)

### Constraints
```julia
constraint_tp_voltage(pm, bounded=false)
constraint_tp_model_voltage(pm, bounded=false)

for (i,bus) in PMs.ref(pm, :ref_buses)
constraint_tp_theta_ref(pm, i)
Expand All @@ -152,7 +152,7 @@ for (i,bus) in PMs.ref(pm, :ref_buses)
end

for (i,bus) in PMs.ref(pm, :bus), c in PMs.conductor_ids(pm)
constraint_kcl_shunt_trans_load(pm, i, cnd=c)
constraint_tp_power_balance_shunt_trans_load(pm, i, cnd=c)

# PV Bus Constraints
if length(PMs.ref(pm, :bus_gens, i)) > 0 && !(i in PMs.ids(pm,:ref_buses))
Expand Down Expand Up @@ -180,8 +180,8 @@ for id in PMs.ids(pm, :load)
end

for i in PMs.ids(pm, :branch), c in PMs.conductor_ids(pm)
constraint_ohms_tp_yt_from(pm, i, cnd=c)
constraint_ohms_tp_yt_to(pm, i, cnd=c)
constraint_tp_ohms_yt_from(pm, i, cnd=c)
constraint_tp_ohms_yt_to(pm, i, cnd=c)
# PMs.constraint_ohms_yt_from(pm, i, cnd=c)
# PMs.constraint_ohms_yt_to(pm, i, cnd=c)
end
Expand Down
108 changes: 56 additions & 52 deletions src/PowerModelsDistribution.jl
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
module PowerModelsDistribution

import JuMP
import PowerModels
import InfrastructureModels
import Memento

import LinearAlgebra

const PMs = PowerModels

function __init__()
global LOGGER = Memento.getlogger(PowerModels)
end

include("core/ref.jl")
include("core/multiconductor.jl")
include("core/variable.jl")
include("core/constraint.jl")
include("core/objective.jl")
include("core/solution.jl")

include("form/acp.jl")
include("form/acr.jl")
include("form/apo.jl")
include("form/dcp.jl")
include("form/bf.jl")
include("form/bf_mx.jl")
include("form/bf_mx_lin.jl")
include("form/bf_mx_soc.jl")
include("form/bf_mx_sdp.jl")
include("form/shared.jl")
include("form/wr.jl")

include("core/constraint_template.jl")
include("core/relaxation_scheme.jl")

include("io/matlab.jl")
include("io/common.jl")
include("io/dss_parse.jl")
include("io/dss_structs.jl")
include("io/opendss.jl")

include("prob/tp_opf.jl")
include("prob/tp_opf_lm.jl")
include("prob/tp_opf_oltc.jl")
include("prob/tp_opf_bctr.jl")
include("prob/tp_opf_bf.jl")
include("prob/tp_ots.jl")
include("prob/tp_pf.jl")
include("prob/tp_pf_lm.jl")
include("prob/tp_pf_bf.jl")
include("prob/tp_debug.jl")
include("prob/tp_test.jl")
import JuMP
import PowerModels
import InfrastructureModels
import Memento

import LinearAlgebra

const _PMs = PowerModels

function __init__()
global _LOGGER = Memento.getlogger(PowerModels)
end

include("core/types.jl")
include("core/data.jl")
include("core/ref.jl")
include("core/multiconductor.jl")
include("core/variable.jl")
include("core/constraint.jl")
include("core/objective.jl")
include("core/solution.jl")

include("form/acp.jl")
include("form/acr.jl")
include("form/apo.jl")
include("form/dcp.jl")
include("form/bf.jl")
include("form/bf_mx.jl")
include("form/bf_mx_lin.jl")
include("form/bf_mx_soc.jl")
include("form/bf_mx_sdp.jl")
include("form/shared.jl")
include("form/wr.jl")

include("core/constraint_template.jl")
include("core/relaxation_scheme.jl")

include("io/matlab.jl")
include("io/common.jl")
include("io/dss_parse.jl")
include("io/dss_structs.jl")
include("io/opendss.jl")

include("prob/tp_opf.jl")
include("prob/tp_opf_lm.jl")
include("prob/tp_opf_oltc.jl")
include("prob/tp_opf_bctr.jl")
include("prob/tp_opf_bf.jl")
include("prob/tp_ots.jl")
include("prob/tp_pf.jl")
include("prob/tp_pf_lm.jl")
include("prob/tp_pf_bf.jl")
include("prob/tp_debug.jl")
include("prob/tp_test.jl")

include("core/export.jl")

end
28 changes: 15 additions & 13 deletions src/core/constraint.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@

function constraint_tp_branch_current(pm::PMs.GenericPowerModel, i::Int; kwargs...)
for c in PMs.conductor_ids(pm)
PMs.constraint_branch_current(pm, i, cnd=c; kwargs...)
""
function constraint_tp_model_current(pm::_PMs.GenericPowerModel; kwargs...)
for c in _PMs.conductor_ids(pm)
_PMs.constraint_model_current(pm; cnd=c, kwargs...)
end
end


function constraint_tp_theta_ref(pm::PMs.GenericPowerModel, i::Int; nw::Int=pm.cnw)
for cnd in PMs.conductor_ids(pm)
""
function constraint_tp_theta_ref(pm::_PMs.GenericPowerModel, i::Int; nw::Int=pm.cnw)
for cnd in _PMs.conductor_ids(pm)
constraint_tp_theta_ref(pm, nw, cnd, i)
end
end


function constraint_tp_storage_loss(pm::PMs.GenericPowerModel, n::Int, i, bus, r, x, standby_loss)
conductors = PMs.conductor_ids(pm)
vm = [PMs.var(pm, n, c, :vm, bus) for c in conductors]
ps = [PMs.var(pm, n, c, :ps, i) for c in conductors]
qs = [PMs.var(pm, n, c, :qs, i) for c in conductors]
sc = PMs.var(pm, n, :sc, i)
sd = PMs.var(pm, n, :sd, i)
""
function constraint_tp_storage_loss(pm::_PMs.GenericPowerModel, n::Int, i, bus, r, x, standby_loss)
conductors = _PMs.conductor_ids(pm)
vm = [_PMs.var(pm, n, c, :vm, bus) for c in conductors]
ps = [_PMs.var(pm, n, c, :ps, i) for c in conductors]
qs = [_PMs.var(pm, n, c, :qs, i) for c in conductors]
sc = _PMs.var(pm, n, :sc, i)
sd = _PMs.var(pm, n, :sd, i)

JuMP.@NLconstraint(pm.model, sum(ps[c] for c in conductors) + (sd - sc) == standby_loss + sum( r[c]*(ps[c]^2 + qs[c]^2)/vm[c]^2 for c in conductors))
end
Loading

2 comments on commit 149a1ff

@pseudocubic
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/1698

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 149a1ffe760f897519209e94c2267e94ddb1433b
git push origin v0.5.0

Please sign in to comment.