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

Aggregated graph backend does not update variables correctly #110

Open
dlcole3 opened this issue Aug 7, 2024 · 2 comments
Open

Aggregated graph backend does not update variables correctly #110

dlcole3 opened this issue Aug 7, 2024 · 2 comments
Labels

Comments

@dlcole3
Copy link
Collaborator

dlcole3 commented Aug 7, 2024

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.

@jalving
Copy link
Member

jalving commented Aug 8, 2024

Thanks for reporting this. Admittedly, the aggregate_to_depth code is the least tested part of Plasmo.jl right now. I'm not at all surprised you're having issues with it. I'll take a look in the next few days and see if I can get a fix out.

@jalving
Copy link
Member

jalving commented Aug 30, 2024

This seems to be an issue with aggregating the objective function. We are not copying the objective data to the aggregated graph correctly when we specify a depth.

@jalving jalving added the bug label Aug 31, 2024
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