Skip to content

Commit

Permalink
Merge pull request #66 from jalving/jump_v1.2
Browse files Browse the repository at this point in the history
Update JuMP dependency to v1.2
  • Loading branch information
jalving authored Aug 26, 2022
2 parents bcdb151 + 87ea855 commit 2169adc
Show file tree
Hide file tree
Showing 17 changed files with 313 additions and 410 deletions.
87 changes: 41 additions & 46 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,17 @@ git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"

[[Calculus]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f641eb0a4f00c343bbc32346e1217b86f3ce9dad"
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
version = "0.5.1"

[[ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "9950387274246d08af38f6eef8cb5480862a435f"
git-tree-sha1 = "2dd813e5f2f7eec2d1268c57cf2373d3ee91fcea"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.14.0"
version = "1.15.1"

[[ChangesOfVariables]]
deps = ["ChainRulesCore", "LinearAlgebra", "Test"]
git-tree-sha1 = "bf98fa45a0a4cee295de98d4c1462be26345b9a1"
git-tree-sha1 = "1e315e3f4b0b7ce40feded39c73049692126cf53"
uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
version = "0.1.2"
version = "0.1.3"

[[CodecBzip2]]
deps = ["Bzip2_jll", "Libdl", "TranscodingStreams"]
Expand All @@ -64,29 +58,25 @@ uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.3.0"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "b153278a25dd42c65abbf4e62344f9d22e59191b"
deps = ["Dates", "LinearAlgebra", "UUIDs"]
git-tree-sha1 = "924cdca592bc16f14d2f7006754a621735280b74"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.43.0"
version = "4.1.0"

[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"

[[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d"
git-tree-sha1 = "d1fff3a548102f48987a52a2e0d114fa97d730f0"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.11"
version = "0.18.13"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[DiffResults]]
deps = ["StaticArrays"]
git-tree-sha1 = "c18e98cba888c6c25d1c3b048e4b3380ca956805"
Expand All @@ -95,9 +85,9 @@ version = "1.0.3"

[[DiffRules]]
deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"]
git-tree-sha1 = "dd933c4ef7b4c270aacd4eb88fa64c147492acf0"
git-tree-sha1 = "28d605d9a0ac17118fe2c5e9ce0fbb76c3ceb120"
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
version = "1.10.0"
version = "1.11.0"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
Expand All @@ -115,9 +105,9 @@ uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[ForwardDiff]]
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "LogExpFunctions", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions", "StaticArrays"]
git-tree-sha1 = "1bd6fc0c344fc0cbee1f42f8d2e7ec8253dda2d2"
git-tree-sha1 = "2f18915445b248731ec5db4e4a17e451020bf21e"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.25"
version = "0.10.30"

[[Inflate]]
git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c"
Expand All @@ -130,9 +120,9 @@ uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[InverseFunctions]]
deps = ["Test"]
git-tree-sha1 = "91b5dcf362c5add98049e6c29ee756910b03051d"
git-tree-sha1 = "b3364212fb5d870f724876ffcd34dd8ec6d98918"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.3"
version = "0.1.7"

[[IrrationalConstants]]
git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151"
Expand All @@ -152,10 +142,10 @@ uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.3"

[[JuMP]]
deps = ["Calculus", "DataStructures", "ForwardDiff", "LinearAlgebra", "MathOptInterface", "MutableArithmetics", "NaNMath", "OrderedCollections", "Printf", "SparseArrays", "SpecialFunctions"]
git-tree-sha1 = "936e7ebf6c84f0c0202b83bb22461f4ebc5c9969"
deps = ["LinearAlgebra", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "Printf", "SparseArrays"]
git-tree-sha1 = "81e17aab8447b7af79ee4f5e0450922991969dd2"
uuid = "4076af6c-e467-56ae-b986-b466b2749572"
version = "1.0.0"
version = "1.2.1"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
Expand Down Expand Up @@ -188,9 +178,9 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[LogExpFunctions]]
deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "a970d55c2ad8084ca317a4658ba6ce99b7523571"
git-tree-sha1 = "09e4b894ce6a976c354a69041a04748180d43637"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.12"
version = "0.3.15"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand All @@ -206,10 +196,10 @@ deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MathOptInterface]]
deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "JSON", "LinearAlgebra", "MutableArithmetics", "OrderedCollections", "Printf", "SparseArrays", "Test", "Unicode"]
git-tree-sha1 = "779ad2ee78c4a24383887fdba177e9e5034ce207"
deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "DataStructures", "ForwardDiff", "JSON", "LinearAlgebra", "MutableArithmetics", "NaNMath", "OrderedCollections", "Printf", "SparseArrays", "SpecialFunctions", "Test", "Unicode"]
git-tree-sha1 = "10d26d62dab815306bbd2c46eb52460e98f01e46"
uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
version = "1.1.2"
version = "1.6.0"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
Expand All @@ -223,14 +213,14 @@ uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[MutableArithmetics]]
deps = ["LinearAlgebra", "SparseArrays", "Test"]
git-tree-sha1 = "ba8c0f8732a24facba709388c74ba99dcbfdda1e"
git-tree-sha1 = "4e675d6e9ec02061800d6cfb695812becbd03cdf"
uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
version = "1.0.0"
version = "1.0.4"

[[NaNMath]]
git-tree-sha1 = "b086b7ea07f8e38cf122f5016af580881ac914fe"
git-tree-sha1 = "737a5957f387b17e74d4ad2f440eb330b39a62c5"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.7"
version = "1.0.0"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
Expand All @@ -252,19 +242,19 @@ version = "1.4.1"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "621f4f3b4977325b9128d5fae7a8b4829a0c2222"
git-tree-sha1 = "0044b23da09b5608b4ecacb4e5e6c6332f833a7e"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.2.4"
version = "2.3.2"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Preferences]]
deps = ["TOML"]
git-tree-sha1 = "d3538e7f8a790dc8903519090857ef8e1283eecd"
git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.5"
version = "1.3.0"

[[Printf]]
deps = ["Unicode"]
Expand Down Expand Up @@ -319,15 +309,20 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[SpecialFunctions]]
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
git-tree-sha1 = "5ba658aeecaaf96923dce0da9e703bd1fe7666f9"
git-tree-sha1 = "d75bda01f8c31ebb72df80a46c88b25d1c79c56d"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "2.1.4"
version = "2.1.7"

[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "4f6ec5d99a28e1a749559ef7dd518663c5eca3d5"
deps = ["LinearAlgebra", "Random", "StaticArraysCore", "Statistics"]
git-tree-sha1 = "9f8a5dc5944dc7fbbe6eb4180660935653b0a9d9"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.4.3"
version = "1.5.0"

[[StaticArraysCore]]
git-tree-sha1 = "66fe9eb253f910fe8cf161953880cfdaef01cdf0"
uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
version = "1.0.1"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Plasmo"
uuid = "d3f7391f-f14a-50cc-bbe4-76a32d1bad3c"
authors = ["Jordan Jalving <jhjalving@gmail.com>"]
repo = "https://github.com/plasmo-dev/Plasmo.jl.git"
version = "0.5.1"
version = "0.5.2"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand All @@ -19,9 +19,9 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
DataStructures = "0.18"
JuMP = "1.0.0 - 1.1.1"
LightGraphs = "~1.3"
MathOptInterface = "1"
MathOptInterface = "1.6"
JuMP = "1.2"
Reexport = "~0.2, 1"
Requires = "~1.0, 1"
julia = "1"
Expand Down
2 changes: 0 additions & 2 deletions src/Plasmo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ include("graph_projections.jl")

include("graph_functions.jl")

include("nlp_macro.jl")

include("nlp_evaluator.jl")

include("partition.jl")
Expand Down
64 changes: 37 additions & 27 deletions src/aggregate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
struct AggregateMap
varmap::Dict{JuMP.VariableRef,JuMP.VariableRef} #map variables in original optigraph to optinode
# TODO: fix printing of nonlinear constraint ref on optinode
conmap::Dict{JuMP.ConstraintRef,JuMP.ConstraintRef} #map constraints in original optigraph to optinode
linkconstraintmap::Dict{LinkConstraint,JuMP.ConstraintRef}
end
Expand Down Expand Up @@ -86,7 +87,7 @@ function aggregate(optigraph::OptiGraph)
for optinode in all_nodes(optigraph)
# Need to pass master reference so we use those variables instead of creating new ones
# node_agg_map = _add_to_aggregate_node!(aggregate_node,optinode,reference_map) #updates combined_model and reference_map
_add_to_aggregate_node!(aggregate_node, optinode, reference_map, graph_obj)
graph_obj = _add_to_aggregate_node!(aggregate_node, optinode, reference_map, graph_obj)

#NOTE:This doesn't seem to work. I have to pass the reference map to the function for some reason
#merge!(reference_map,node_agg_map)
Expand All @@ -105,9 +106,9 @@ function aggregate(optigraph::OptiGraph)
reference_map.linkconstraintmap[JuMP.constraint_object(linkconstraint)] = cref
end

aggregate_node.nlp_data = aggregate_node.model.nlp_data
#aggregate_node.nlp_data = aggregate_node.model.nlp_data

return aggregate_node,reference_map
return aggregate_node, reference_map
end
@deprecate combine aggregate

Expand Down Expand Up @@ -135,56 +136,65 @@ function _add_to_aggregate_node!(aggregate_node::OptiNode, add_node::OptiNode, a
constraint_refs = JuMP.all_constraints(add_node, func, set)
for constraint_ref in constraint_refs
constraint = JuMP.constraint_object(constraint_ref)
new_constraint = _copy_constraint(constraint,reference_map)
new_ref= JuMP.add_constraint(aggregate_node,new_constraint)
new_constraint = _copy_constraint(constraint, reference_map)
new_ref= JuMP.add_constraint(aggregate_node, new_constraint)
reference_map[constraint_ref] = new_ref
end
end

#COPY NONLINEAR CONSTRAINTS
nlp_initialized = false
if add_node.nlp_data !== nothing
d = JuMP.NLPEvaluator(add_node) #Get the NLP evaluator object. Initialize the expression graph
MOI.initialize(d,[:ExprGraph])
nlp = JuMP.nonlinear_model(add_node)
#if add_node.nlp_data !== nothing
if nlp != nothing
#d = JuMP.NLPEvaluator(add_node) #Get the NLP evaluator object. Initialize the expression graph
evaluator = JuMP.NLPEvaluator(add_node; _differentiation_backend = MOI.Nonlinear.ExprGraphOnly())
MOI.initialize(evaluator, [:ExprGraph])
nlp_initialized = true
add_node.nlp_data = add_node.model.nlp_data
for i = 1:length(add_node.nlp_data.nlconstr)
expr = MOI.constraint_expr(d,i) #this returns a julia expression
_splice_nonlinear_variables!(expr,add_node,reference_map) #splice the variables from var_map into the expression
new_nl_constraint = JuMP.add_nonlinear_constraint(aggregate_node,expr) #raw expression input for non-linear constraint
constraint_ref = JuMP.ConstraintRef(add_node,JuMP.NonlinearConstraintIndex(i),new_nl_constraint.shape)
#add_node.nlp_data = add_node.model.nlp_data
for i = 1:length(nlp.constraints)
#for i = 1:length(add_node.nlp_data.nlconstr)
expr = MOI.constraint_expr(evaluator, i) #this returns a julia expression
_splice_nonlinear_variables!(expr, add_node, reference_map) #splice the variables from var_map into the expression
new_nl_constraint = JuMP.add_nonlinear_constraint(aggregate_node, expr) #raw expression input for non-linear constraint
constraint_ref = JuMP.ConstraintRef(
add_node,
JuMP.NonlinearConstraintIndex(i),
new_nl_constraint.shape)
reference_map[constraint_ref] = new_nl_constraint
end
end

#ADD TO OBJECTIVE Expression
if isa(graph_obj,Union{Expr,Int}) #NLP
# if graph objective is a Julia expression
if isa(graph_obj, Union{Expr,Int})
if !nlp_initialized
JuMP._init_NLP(add_node)
d = JuMP.NLPEvaluator(add_node)
MOI.initialize(d,[:ExprGraph])
add_node.nlp_data = add_node.model.nlp_data
#d = JuMP.NLPEvaluator(add_node)
evaluator = JuMP.NLPEvaluator(add_node; _differentiation_backend = MOI.Nonlinear.ExprGraphOnly())
MOI.initialize(evaluator, [:ExprGraph])
#add_node.nlp_data = add_node.model.nlp_data
end
new_obj = _copy_nl_objective(d,reference_map)
graph_obj = Expr(:call,:+,graph_obj,new_obj) #update graph objective
new_obj = _copy_nl_objective(add_node, evaluator, reference_map)
graph_obj = Expr(:call, :+, graph_obj, new_obj) #update graph objective
else #AFFINE OR QUADTRATIC OBJECTIVE
new_objective = _copy_objective(add_node,reference_map)
new_objective = _copy_objective(add_node, reference_map)
sense = JuMP.objective_sense(add_node)
s = sense == MOI.MAX_SENSE ? -1.0 : 1.0
JuMP.add_to_expression!(graph_obj,s,new_objective)
JuMP.add_to_expression!(graph_obj, s, new_objective)
end

merge!(aggregate_map,reference_map)
merge!(aggregate_map, reference_map)

# COPY OBJECT DATA
#BUG? The object dictionary can really have anything
# BUG? The object dictionary can really have anything
node_obj_dict = Dict()
for (name, value) in JuMP.object_dictionary(add_node)
node_obj_dict[name] = getindex.(Ref(reference_map),value)
node_obj_dict[name] = getindex.(Ref(reference_map), value)
end
push!(JuMP.object_dictionary(aggregate_node)[:nodes],node_obj_dict)
push!(JuMP.object_dictionary(aggregate_node)[:nodes], node_obj_dict)

return reference_map, graph_obj
return graph_obj
end

#aggregate subgraphs in optigraph to given depth
Expand Down
Loading

2 comments on commit 2169adc

@jalving
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/67117

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.2 -m "<description of version>" 2169adc998a9b76cdfd51354f39176c546960e41
git push origin v0.5.2

Please sign in to comment.