Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions ext/ManoptJuMPExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -623,37 +623,31 @@ and the [`ManifoldSet`](@ref) in which they should belong as well as the
shape of the manifold, that is, a [`ManifoldArrayShape`](@ref).
"""
function JuMP.build_variable(::Function, array, M::ManifoldsBase.AbstractManifold)
shape = _shape(M)
return JuMP.VariablesConstrainedOnCreation(
JuMP.vectorize(array, shape), ManifoldSet(M), shape
)
if array isa JuMP.ScalarVariable
return ManifoldVariable(array.info.start, M)
else
shape = _shape(M)
return JuMP.VariablesConstrainedOnCreation(
JuMP.vectorize(array, shape), ManifoldSet(M), shape
)
end
end

#
#
# NonArrayPoints define own variable
# TODO: Document
struct ManifoldVariable{P<:ManifoldsBase.AbstractManifoldPoint} <: JuMP.AbstractVariable
p::P
end
# Taken / adapted from https://github.com/JuliaManifolds/Manopt.jl/pull/466#issuecomment-2862071520
# TODO: I think I would prefer PoincareHalfPlanePoint(p) in Hyperbolic(3),
# but it seems the in and such where not present for polynomials?
function JuMP.build_variable(
_error::Function,
info::JuMP.VariableInfo,
p::ManifoldsBase.AbstractManifoldPoint;
extra_kwargs...,
)
# cvarchecks(_error, info; extra_kwargs...) # What does this do? Necessary?
# _warnbounds(_error, p, info) # What does this do?
return ManifoldVariable(p)
struct ManifoldVariable{P<:ManifoldsBase.AbstractManifoldPoint,M<:ManifoldsBase.AbstractManifold} <: JuMP.AbstractVariable
start::P
manifold::M
end
#
#

# TODO: Understand parameters here and document them
function JuMP.add_variable(model::JuMP.AbstractModel, v::ManifoldVariable, name::String="")
return nothing
function JuMP.add_variable(model::JuMP.AbstractModel, v::ManifoldVariable, ::String="")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we maybe have a it of documentation here? The official docs mainly state “please ask a developer”. If that code is here in Manopt I am a developer and by now I tried for about half a year maybe to understand something – and I simply do not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

...your docs do not help https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.add_variable – they state I should ask you, and neither are my code archeology skill that good nor have all my tries of that not lead to me understanding how this is supposed to work, nor what for example the string is.

shape = _shape(v.manifold, v.start)
n = length(JuMP.vectorize(v.start, shape))
vars = [JuMP.VariableRef(model) for _ in 1:n]
return JuMP.reshape_vector(vars, shape)
end

"""
Expand Down
6 changes: 3 additions & 3 deletions ext/ManoptJuMPManifoldsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ end
function JuMP.reshape_vector(
v::Vector{T}, shape::MJE.ManifoldPointShape{M,Manifolds.HyperboloidPoint}
) where {T,M<:ManifoldsBase.AbstractManifold}
p = rand(shape.manifold, HyperboloidPoint)
p.value .= v
return p
return HyperboloidPoint(v)
end
# point -> vector
function JuMP.vectorize(
Expand All @@ -43,4 +41,6 @@ function JuMP.vectorize(
return p.value # is a vector already
end

MJE._shape(m::M, ::Manifolds.HyperboloidPoint) where {M} = MJE.ManifoldPointShape{M,Manifolds.HyperboloidPoint}(m)

end # module ManoptJuMPManifoldsExt