Skip to content

Commit

Permalink
revert to original reopt logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bpulluta committed Jan 22, 2025
1 parent fcbf35b commit 00b9e40
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 51 deletions.
76 changes: 25 additions & 51 deletions src/core/reopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,59 +137,33 @@ Solve the `Scenario` and `BAUScenario` in parallel using the first two (empty) m
"""

function run_reopt(ms::AbstractArray{T, 1}, p::REoptInputs) where T <: JuMP.AbstractModel
try
# Create BAU inputs
bau_inputs = try
BAUInputs(p)
catch e
@error "BAU initialization failed"
rethrow(e)
end

# Run optimizations in parallel
inputs = ((ms[1], bau_inputs), (ms[2], p))
rs = Any[0, 0]

Threads.@threads for i = 1:2
rs[i] = run_reopt(inputs[i])
end

# Validate results
if !isa(rs[1], Dict) || !isa(rs[2], Dict)
throw(ErrorException("Invalid optimization results: Expected Dict outputs"))
end

if rs[1]["status"] == "error" || rs[2]["status"] == "error"
error_msg = """
Optimization failed:
BAU status: $(rs[1]["status"])
Optimal status: $(rs[2]["status"])
Error details: $(get(rs[2], "Messages", Dict()).get("errors", "None"))
"""
throw(ErrorException(error_msg))
end

# Process results
try
results_dict = combine_results(p, rs[1], rs[2], bau_inputs.s)
results_dict["Financial"] = merge(results_dict["Financial"], proforma_results(p, results_dict))

if !isempty(p.techs.pv)
organize_multiple_pv_results(p, results_dict)
end
return results_dict
catch e
@error "Results processing failed" exception=e
rethrow(e)
end
try
bau_inputs = BAUInputs(p)
inputs = ((ms[1], bau_inputs), (ms[2], p))
rs = Any[0, 0]
Threads.@threads for i = 1:2
rs[i] = run_reopt(inputs[i])
end
if typeof(rs[1]) <: Dict && typeof(rs[2]) <: Dict && rs[1]["status"] != "error" && rs[2]["status"] != "error"
# TODO when a model is infeasible the JuMP.Model is returned from run_reopt (and not the results Dict)
results_dict = combine_results(p, rs[1], rs[2], bau_inputs.s)
results_dict["Financial"] = merge(results_dict["Financial"], proforma_results(p, results_dict))

catch e
if isnothing(e)
handle_errors()
else
handle_errors(e, stacktrace(catch_backtrace()))
end
end
if !isempty(p.techs.pv)
organize_multiple_pv_results(p, results_dict)
end
return results_dict
else
throw(@error("REopt scenarios solved either with errors or non-optimal solutions."))
end
catch e
if isnothing(e) # Error thrown by REopt
handle_errors()
else
handle_errors(e, stacktrace(catch_backtrace()))
end
end
end


Expand Down
13 changes: 13 additions & 0 deletions src/core/reopt_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,19 @@ function setup_pv_inputs(s::AbstractScenario, max_sizes, min_sizes,
push!(techs.no_curtail, pv.name)
end
end

if pv_roof_limited
maxsize_pv_locations[:roof] = float(roof_existing_pv_kw + roof_max_kw)
end
if pv_ground_limited
maxsize_pv_locations[:ground] = float(ground_existing_pv_kw + land_max_kw)
end
if pv_space_limited
maxsize_pv_locations[:both] = float(both_existing_pv_kw + roof_max_kw + land_max_kw)
end

return nothing

end

"""
Expand Down

0 comments on commit 00b9e40

Please sign in to comment.