Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Classify the change according to the following categories:
### Deprecated
### Removed

## dict-type
### Fixed
- Added dicttype arg to _JSON.parsefile_ (solves _MethodError_ when the parsed JSON file is passed to the next function (e.g. `Scenario`) as a _JSON.Object_ but expecting _Dict_)
Comment thread
hdunham marked this conversation as resolved.

## v0.59.2
### Fixed
- Restrictive validation to let CHP heuristic sizing parameters (avg heating and cooling values) be zero
Expand Down
2 changes: 1 addition & 1 deletion src/core/pv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ function get_pv_defaults_size_class()
throw(ErrorException("pv_defaults.json not found at path: $pv_defaults_path"))
end

pv_defaults_all = JSON.parsefile(pv_defaults_path)
pv_defaults_all = parse_json_file_to_dict(pv_defaults_path)
return pv_defaults_all["size_classes"]
end

Expand Down
6 changes: 3 additions & 3 deletions src/core/reopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Solve the model using the `Scenario` defined in JSON file stored at the file pat
function run_reopt(m::JuMP.AbstractModel, fp::String)

try
s = Scenario(JSON.parsefile(fp))
s = Scenario(parse_json_file_to_dict(fp))
run_reopt(m, REoptInputs(s))
Comment thread
hdunham marked this conversation as resolved.
catch e
if isnothing(e) # Error thrown by REopt
Expand Down Expand Up @@ -99,7 +99,7 @@ Solve the `Scenario` and `BAUScenario` in parallel using the first two (empty) m
JSON file at the filepath `fp`.
"""
function run_reopt(ms::AbstractArray{T, 1}, fp::String) where T <: JuMP.AbstractModel
d = JSON.parsefile(fp)
d = parse_json_file_to_dict(fp)
run_reopt(ms, d)
end

Expand Down Expand Up @@ -172,7 +172,7 @@ Add variables and constraints for REopt model.
`fp` is used to load in JSON file to construct REoptInputs.
"""
function build_reopt!(m::JuMP.AbstractModel, fp::String)
s = Scenario(JSON.parsefile(fp))
s = Scenario(parse_json_file_to_dict(fp))
build_reopt!(m, REoptInputs(s))
nothing
end
Expand Down
4 changes: 2 additions & 2 deletions src/core/reopt_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ end
Use `fp` to load in JSON scenario:
```
function REoptInputs(fp::String)
s = Scenario(JSON.parsefile(fp))
s = Scenario(parse_json_file_to_dict(fp))
REoptInputs(s)
end
```
Useful if you want to manually modify REoptInputs before solving the model.
"""
function REoptInputs(fp::String)
s = Scenario(JSON.parsefile(fp))
s = Scenario(parse_json_file_to_dict(fp))
REoptInputs(s)
end

Expand Down
3 changes: 1 addition & 2 deletions src/core/scenario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function Scenario(d::Dict; flex_hvac_from_json=false)
else
settings = Settings()
end

site = Site(;dictkeys_tosymbols(d["Site"])...)

# Check that only PV, electric storage, and generator are modeled for off-grid
Expand Down Expand Up @@ -1077,7 +1076,7 @@ end
Consruct Scenario from filepath `fp` to JSON with keys aligned with the `Scenario(d::Dict)` method.
"""
function Scenario(fp::String)
Scenario(JSON.parsefile(fp); flex_hvac_from_json=true)
Scenario(parse_json_file_to_dict(fp); flex_hvac_from_json=true)
end


Expand Down
9 changes: 9 additions & 0 deletions src/core/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# REopt®, Copyright (c) Alliance for Energy Innovation, LLC. See also https://github.com/NatLabRockies/REopt.jl/blob/master/LICENSE.
"""
parse_json_file_to_dict(fp::String)::Dict{String, Any}

Parse a JSON file at filepath `fp` and return a `Dict{String, Any}`.
"""
function parse_json_file_to_dict(fp::String)::Dict{String, Any}
JSON.parsefile(fp, dicttype = Dict{String, Any})
end

function time_step_wrap_around(time_step::Int; time_steps_per_hour::Int=1)::Int
time_steps_per_year = 8760 * time_steps_per_hour
((time_step - 1) % time_steps_per_year) + 1
Expand Down
2 changes: 1 addition & 1 deletion src/mpc/inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end


function MPCInputs(fp::String)
s = MPCScenario(JSON.parsefile(fp))
s = MPCScenario(parse_json_file_to_dict(fp))
MPCInputs(s)
end

Expand Down
2 changes: 1 addition & 1 deletion src/mpc/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Solve the model predictive control problem using the `MPCScenario` defined in th
Returns a Dict of results with keys matching those in the `MPCScenario`.
"""
function run_mpc(m::JuMP.AbstractModel, fp::String)
s = MPCScenario(JSON.parsefile(fp))
s = MPCScenario(parse_json_file_to_dict(fp))
run_mpc(m, MPCInputs(s))
end

Expand Down
Loading