-
Notifications
You must be signed in to change notification settings - Fork 2
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
Ensure compatibility with Plasmo 0.5.4 and static partition example #5
Open
tso-martin
wants to merge
3
commits into
plasmo-dev:main
Choose a base branch
from
tso-martin:dev_schwarzopt_example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Example demonstrating the use of overlap to solve a long horizon control problem | ||
# Uses a static partitioning of the graph (useful if KaHyPar is not available) | ||
using Plasmo, Ipopt | ||
using SchwarzOpt | ||
|
||
T = 8 # number of time points | ||
d = sin.(1:T) # a disturbance vector | ||
imbalance = 0.1 # partition imbalance | ||
distance = 2 # expand distance | ||
n_parts = 5 # number of partitions | ||
|
||
# Create the model (an optigraph) | ||
graph_schwarz = OptiGraph() | ||
|
||
@optinode(graph_schwarz, state[1:T]) | ||
@optinode(graph_schwarz, control[1:(T-1)]) | ||
|
||
for (i, node) in enumerate(state) | ||
@variable(node, x) | ||
@constraint(node, x >= 0) | ||
@objective(node, Min, x^2) #- 2*x*d[i]) | ||
end | ||
for node in control | ||
@variable(node, u) | ||
@constraint(node, u >= -1000) | ||
@objective(node, Min, u^2) | ||
end | ||
n1 = state[1] | ||
@constraint(n1, n1[:x] == 0) | ||
|
||
for i in 1:(T-1) | ||
@linkconstraint(graph_schwarz, state[i][:x] + control[i][:u] + d[i] == state[i+1][:x]) | ||
end | ||
|
||
hypergraph, hyper_map = hyper_graph(graph_schwarz) # create hypergraph object based on graph | ||
# Create an equally sized partition based on the number of time points and number of partitions. | ||
N_node = 2 * T - 1 | ||
partition_vector = repeat(1:n_parts, inner=N_node ÷ n_parts) | ||
remaining = N_node % n_parts | ||
if remaining > 0 | ||
partition_vector = [partition_vector; repeat(1:remaining)] | ||
end | ||
|
||
|
||
# apply partition to graph | ||
partition = Partition(hypergraph, partition_vector, hyper_map) | ||
## | ||
@run apply_partition!(graph_schwarz, partition) | ||
## | ||
# calculate subproblems using expansion distance | ||
subs = subgraphs(graph_schwarz) | ||
expanded_subgraphs = Plasmo.expand.(graph_schwarz, subs, distance) | ||
sub_optimizer = optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0) | ||
|
||
# optimize using schwarz overlapping decomposition | ||
optimizer = SchwarzOpt.optimize!( | ||
graph_schwarz; | ||
subgraphs=expanded_subgraphs, | ||
sub_optimizer=sub_optimizer, | ||
max_iterations=100, | ||
mu=100.0, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tso-martin: Are the
value
anddual
functions not working as expected when given the graph as an argument in Plasmo v0.5.4? Removing the graph argument should cause issues when running on multiple threads.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get errors for each thread, when
value
anddual
are called with the graph argument. Example:Removing the graph argument worked fine in multiple threads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, that is definitely a bug. Without the graph argument,
value
grabs the last solution the node was used in. So it's possible it takes the wrong one if there are multiple subgraphs that use it. I will take a look at this and get a fix out. Thanks for checking into this!