Ran into this problem trying to implement a copy function for an OptiGraph, and it might be related to the way backends are set up. In the following code, the aggregated graph backend does not correctly record the variables:
using Plasmo
function build_partitioned_graph()
g = OptiGraph()
@optinode(g, nodes[1:4])
for node in nodes
@variable(node, 0 <= x)
@objective(node, Min, x)
end
@linkconstraint(g, nodes[1][:x] + nodes[2][:x] >= 1)
@linkconstraint(g, nodes[2][:x] + nodes[3][:x] >= 1)
@linkconstraint(g, nodes[3][:x] + nodes[4][:x] >= 1)
@linkconstraint(g, nodes[4][:x] + nodes[1][:x] >= 1)
node_membership_vector = [1, 1, 2, 2]
partition = Plasmo.Partition(g, node_membership_vector)
apply_partition!(g, partition)
return g
end
g1 = build_partitioned_graph()
g2 = build_partitioned_graph()
g0 = OptiGraph()
add_subgraph!(g0, g1)
add_subgraph!(g0, g2)
set_to_node_objectives(g0)
@optinode(g1, n_g1)
@optinode(g2, n_g2)
@optinode(g0, n_g)
agg_graph_layer1, ref_map_layer1 = aggregate_to_depth(g0, 1)
gb = graph_backend(g0)
gb_agg = graph_backend(agg_graph_layer1
If you look at graph backend of the original vs. aggregated graphs (gb vs. gb_agg), the latter reports 0 variables and constraints. In addition, the element_to_graph_map and graph_to_element_map are both empty and node_variables is missing nodes and variables. The all_variables function still correctly works though.
I looked into this a little deeper, and I think it may have to do with MOIU.pass_attributes in the aggregate.jl file here. In the source code for MOIU.pass_attributes here, it relies on the function MOI.get function to collect attributes of the MOI.ListOfModelAttributesSet() or MOI.ListOfVariableAttributesSet(). However, if I call either MOI.get(gb, MOI.ListOfVariableAttributesSet()) or MOI.get(gb.backend, MOI.ListOfVariableAttributesSet()), I get an empty vector returned. However, the vector is nonempty if I call it on the lowest level subgraph's backend (e.g., on graph_backend(getsubgraphs(g1)[1]). I think perhaps the MOI backend is not seeing the subgraph information correctly? Any thoughts on how best to address this? I think my knowledge on the MOI backend and graph backend interfaces is not yet good enough to know how to resolve this.
Ran into this problem trying to implement a
copyfunction for an OptiGraph, and it might be related to the way backends are set up. In the following code, the aggregated graph backend does not correctly record the variables:If you look at graph backend of the original vs. aggregated graphs (
gbvs.gb_agg), the latter reports 0 variables and constraints. In addition, theelement_to_graph_mapandgraph_to_element_mapare both empty andnode_variablesis missing nodes and variables. Theall_variablesfunction still correctly works though.I looked into this a little deeper, and I think it may have to do with
MOIU.pass_attributesin theaggregate.jlfile here. In the source code forMOIU.pass_attributeshere, it relies on the functionMOI.getfunction to collect attributes of theMOI.ListOfModelAttributesSet()orMOI.ListOfVariableAttributesSet(). However, if I call eitherMOI.get(gb, MOI.ListOfVariableAttributesSet())orMOI.get(gb.backend, MOI.ListOfVariableAttributesSet()), I get an empty vector returned. However, the vector is nonempty if I call it on the lowest level subgraph's backend (e.g., ongraph_backend(getsubgraphs(g1)[1]). I think perhaps the MOI backend is not seeing the subgraph information correctly? Any thoughts on how best to address this? I think my knowledge on the MOI backend and graph backend interfaces is not yet good enough to know how to resolve this.