plasmo-dev / Plasmo.jl

A Platform for Scalable Modeling and Optimization
Other
143 stars 20 forks source link

Calling `optimize!` on an expanded subgraph resets the solution of a different subgraph #85

Closed dlcole3 closed 10 months ago

dlcole3 commented 1 year ago

I am using expanded subgraphs in Plasmo using the Plasmo.expand function. The solution of whichever subgraph is optimized first is reset when optimize! is called on the other expanded subgraph. This only happens in the first instance, and I am not sure why. You can see the error replicated in the code below.

using Plasmo, JuMP, Ipopt

graph = OptiGraph()
set_optimizer(graph, Ipopt.Optimizer)

@optinode(graph, nodes[1:4])
for (i, node) in enumerate(nodes)
    @variable(node, x >= i)
    @objective(node, Min, 2 * x)
end
for i in 1:3
    @linkconstraint(graph, nodes[i + 1][:x] + nodes[i][:x] >= i * 4)
end

node_membership = [1, 1, 2, 2]
hypergraph, hyper_map = gethypergraph(graph)
partition = Partition(hypergraph, node_membership, hyper_map)
apply_partition!(graph, partition)
subgraphs = getsubgraphs(graph)
expanded_subgraphs = Plasmo.expand.(graph, subgraphs, 1)
set_optimizer(expanded_subgraphs[1], Ipopt.Optimizer)
set_optimizer(expanded_subgraphs[2], Ipopt.Optimizer)

optimize!(expanded_subgraphs[1])
vars1 = value.(all_variables(expanded_subgraphs[1])) #solution exists and can be queried

optimize!(expanded_subgraphs[2]) # this line resets the solutino of expanded_subgraphs[1]
vars1 = value.(all_variables(expanded_subgraphs[1])) # this line returns an "OptimizeNotCalled()" error

Note that the solution is only reset once, and only for the very first expanded subgraph optimized. If I call optimize!(expanded_subgraphs[1]) after the above code, no solutions are reset and I can query solutions from either expanded subgraph

dlcole3 commented 1 year ago

The above error happens on the most recent version of Plasmo.jl (v0.5.3). However, I just tried this with the most recent master branch of Plasmo, and the error no longer occurs. So maybe this will not be an issue in the next release?

jalving commented 10 months ago

Yes, i confirm this works on main. We can close this once we cut v0.5.4.