Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dlcole3 opened this issue Aug 7, 2023 · 2 comments
Labels

Comments

@dlcole3
Copy link
Collaborator

dlcole3 commented Aug 7, 2023

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
Copy link
Collaborator Author

dlcole3 commented Aug 7, 2023

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
Copy link
Member

jalving commented Oct 8, 2023

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

@jalving jalving added the bug label Oct 9, 2023
@jalving jalving closed this as completed Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants