Skip to content

Commit c226f7a

Browse files
authored
FIX: property assignment in different file (#420)
Fixes a bug where if a property is assigned via the pattern, e.g., `load.a1.bus1 = some_bus` in a file that is different from the one where `load.a1` was defined, the assignment would fail. Closes #397
1 parent 748c4ce commit c226f7a

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## staged
44

5+
- Fixed bug in dss parser where properties assigned via `assign_property!` would fail if the object they applied to was not created in the same file [#397](https://github.com/lanl-ansi/PowerModelsDistribution.jl/issues/397)
56
- Fixed bug in `get_defined_buses` to check if `"bus"` property is a `Vector` instead of checking if it is a `String` [#416](https://github.com/lanl-ansi/PowerModelsDistribution.jl/issues/416)
67
- Fixed bug in `_map_eng2math_bus!()` regarding calculation of shunt element susceptance parameter
78
- Added SOC transformer relaxations

src/io/dss/dss_parse.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -795,37 +795,37 @@ end
795795

796796

797797
"""
798-
parse_dss(filename::String)::Dict{String,Any}
798+
parse_dss(filename::String; data_dss::Union{Missing,Dict{String,Any}}=missing)::Dict{String,Any}
799799
800800
Parses a OpenDSS file given by `filename` into a Dict{Array{Dict}}. Only
801801
supports components and options, but not commands, e.g. "plot" or "solve".
802802
Will also parse files defined inside of the originating DSS file via the
803803
"compile", "redirect" or "buscoords" commands.
804804
"""
805-
function parse_dss(path::Union{AbstractString,FilePaths.AbstractPath})::Dict{String,Any}
805+
function parse_dss(path::Union{AbstractString,FilePaths.AbstractPath}; data_dss::Union{Missing,Dict{String,Any}}=missing)::Dict{String,Any}
806806
path = isa(path, FilePaths.AbstractPath) ? path : FilePaths.Path(path)
807807
data_dss = open(first(Glob.glob([Glob.FilenameMatch(basename(path), "i")], dirname(path)))) do io
808-
parse_dss(io)
808+
parse_dss(io; data_dss=data_dss)
809809
end
810810
return data_dss
811811
end
812812

813813

814814
"""
815-
parse_dss(io::IO)::Dict{String,Any}
815+
parse_dss(io::IO; data_dss::Union{Missing,Dict{String,Any}}=missing)::Dict{String,Any}
816816
817817
Parses a OpenDSS file aleady in IO into a Dict{Array{Dict}}. Only
818818
supports components and options, but not commands, e.g. "plot" or "solve".
819819
Will also parse files defined inside of the originating DSS file via the
820820
"compile", "redirect" or "buscoords" commands.
821821
"""
822-
function parse_dss(io::IO)::Dict{String,Any}
822+
function parse_dss(io::IO; data_dss::Union{Missing,Dict{String,Any}}=missing)::Dict{String,Any}
823823
filename = isa(io, IOStream) ? match(r"^<file\s(.+)>$", io.name).captures[1] : "GenericIOBuffer"
824824
current_file = basename(FilePaths.Path(filename))
825825
path = dirname(FilePaths.Path(filename))
826-
data_dss = Dict{String,Any}()
826+
data_dss = ismissing(data_dss) ? Dict{String,Any}() : data_dss
827827

828-
data_dss["filename"] = Set{String}([string(filename)])
828+
data_dss["filename"] = haskey(data_dss, "filename") ? union(data_dss["filename"], Set{String}([string(filename)])) : Set{String}([string(filename)])
829829

830830
current_obj = Dict{String,Any}()
831831
current_obj_type = ""
@@ -871,7 +871,7 @@ function parse_dss(io::IO)::Dict{String,Any}
871871
if !(joinpath(file_path...) in data_dss["filename"])
872872
full_path = joinpath(path, file_path...)
873873
@info "Redirecting to '$(joinpath(file_path...))' on line $real_line_num in '$current_file'"
874-
_merge_dss!(data_dss, parse_dss(full_path))
874+
data_dss = parse_dss(full_path; data_dss=data_dss)
875875
end
876876

877877
continue
@@ -949,11 +949,8 @@ function parse_dss(io::IO)::Dict{String,Any}
949949
if property_name in ["wdg", "bus", "conn", "kv", "kva", "tap", "%r", "rneut", "xneut"]
950950
property_name = join(filter(p->!isempty(p), [property_name, wdg]), "_")
951951
end
952-
953-
_assign_property!(data_dss, obj_type, obj_name, property_name, property_value)
954-
else
955-
_assign_property!(data_dss, obj_type, obj_name, property_name, property_value)
956952
end
953+
_assign_property!(data_dss, obj_type, obj_name, property_name, property_value)
957954
end
958955
else
959956
@warn "Command '$cmd' on line $real_line_num in '$current_file' is not recognized, skipping."

test/data/opendss/test2_edit.dss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
edit transformer.t5 wdg=2 %r=0.76 wdg=1 %r=0.74
2+
3+
storage.s1.bus1 = _b2

test/opendss.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
@test all(eng["transformer"]["t5"]["rw"] .== [0.0074, 0.0076])
6565
end
6666

67+
@testset "dss assign property in different file" begin
68+
@test eng["storage"]["s1"]["bus"] == "_b2"
69+
end
70+
6771
@testset "subdirectory parsing" begin
6872
@test haskey(eng["linecode"], "lc7")
6973
end

0 commit comments

Comments
 (0)