# Wram start of HermitianPSDCone in JuMP

**URL:** https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [October 27, 2023, 8:59pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491 "2023-10-27T20:59:32Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![akirakyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akirakyle/32/202781_2.png) [@akirakyle](https://discourse.julialang.org/u/akirakyle)
#### Post date: [October 27, 2023, 8:59pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/1 "2023-10-27T20:59:32Z")

</div>

I’m having trouble figuring out how to use set\_start\_value with HermitianPSDCone.

Here’s a minimal script based on the the [quantum discrimination example](https://jump.dev/JuMP.jl/stable/tutorials/conic/quantum_discrimination/) in the docs:

```julia
using JuMP
using LinearAlgebra
import COSMO

ρs = [[[1 0]; [0 0]],
       [[1 1]; [1 1]]/2 ]
ρs = map(Hermitian, ρs)

model = Model(COSMO.Optimizer)
set_silent(model)

@variable(model, E1[1:2, 1:2] in HermitianPSDCone())
@variable(model, E2[1:2, 1:2] in HermitianPSDCone())
@constraint(model, E1+E2 == LinearAlgebra.I)
@objective(model, Max, real(dot(ρs, [E1,E2])) / 2)

set_start_value.(E1, Hermitian(I(2)/2))
set_start_value.(E2, Hermitian(I(2)/2))

optimize!(model)
solution_summary(model)
println("value: ", objective_value(model))
println("true: ", 0.5 + 0.25 * sum(svdvals(ρs[1] - ρs[2])))

```

The set\_start\_value line gives the error:

```julia
MethodError: no method matching set_start_value(::GenericAffExpr{ComplexF64, VariableRef}, ::Float64)

```

I wasn’t sure if this was a bug or if there’s something special I need to do to set the initial value of a hermitian variable.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [October 27, 2023, 10:18pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/2 "2023-10-27T22:18:57Z")

</div>

Hi @akirakyle, welcome to the forum!

This is a bug (really, a missing feature). I’ve opened an issue: [set\_start\_value for complex variables · Issue #3550 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/3550)

For now, you can set a start value using the `start` keyword in `@variable`:

```julia
julia> using JuMP, LinearAlgebra

julia> model = Model();

julia> E1_start = Hermitian(I(2)/2)
2×2 Hermitian{Float64, Diagonal{Float64, Vector{Float64}}}:
 0.5 0.0
 0.0 0.5

julia> @variable(model, E1[i=1:2, j=1:2] in HermitianPSDCone(), start=E1_start[i,j])
2×2 Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}:
 real(E1[1,1]) real(E1[1,2]) + imag(E1[1,2]) im
 real(E1[1,2]) - imag(E1[1,2]) im real(E1[2,2])

julia> all_variables(model)
4-element Vector{VariableRef}:
 real(E1[1,1])
 real(E1[1,2])
 real(E1[2,2])
 imag(E1[1,2])

julia> start_value.(all_variables(model))
4-element Vector{Float64}:
 0.5
 0.0
 0.5
 0.0

```

---

<div class="post-metadata">

### Author: ![akirakyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akirakyle/32/202781_2.png) [@akirakyle](https://discourse.julialang.org/u/akirakyle)
#### Post date: [October 28, 2023, 12:00am UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/3 "2023-10-28T00:00:18Z")

</div>

Thanks @odow for replying to me! Good to know that this was a bug and that I can use the start keyword.  
However it seems to now error when calling `optimize!` with COSMO here’s what I ran:

```julia
using JuMP, LinearAlgebra, COSMO

model = Model(COSMO.Optimizer)
set_silent(model)

ρs = [[[1 0]; [0 0]],
       [[1 1]; [1 1]]/2 ]
ρs = map(Hermitian, ρs)

E_ = Hermitian(I(2)/2)

@variable(model, E1[i=1:2, j=1:2] in HermitianPSDCone(), start = E_[i,j])
@variable(model, E2[i=1:2, j=1:2] in HermitianPSDCone(), start = E_[i,j])
@constraint(model, E1+E2 == LinearAlgebra.I)
@objective(model, Max, real(dot(ρs, [E1,E2])) / 2)

optimize!(model)
solution_summary(model)

```

Then I get the error:

```julia
MathOptInterface.UnsupportedAttribute{MathOptInterface.VariablePrimalStart}: Attribute MathOptInterface.VariablePrimalStart() is not supported by the model.

```

However this seems to be the result of using COSMO as it seems to work with SCS. I’m not sure if this is also a bug?

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [October 28, 2023, 12:21am UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/4 "2023-10-28T00:21:58Z")

</div>

> Thanks @odow for replying to me!

No problem 😄

> However this seems to be the result of using COSMO as it seems to work with SCS. I’m not sure if this is also a bug?

Hmm. That shouldn’t happen. Let me take a look.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [October 28, 2023, 12:37am UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/5 "2023-10-28T00:37:26Z")

</div>

Okay, this is indeed a bug: [Starting value in unsupported bridge errors instead of skipping · Issue #2327 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/issues/2327).

Here’s what is happening:

- If a solver does not support `HermitianPSDCone` explicitly, then JuMP will reformulate it into an equivalent `PositiveSemidefiniteConeTriangle` constraint through a _bridge_.
- When you set the starting value of `E1` and `E2`, the bridge needs to convert those starting values into equivalent starting values for the reformulated variables inside the solver
- Some bridges (such as the hermitian to PSD bridge) do not yet have support for mapping starting values ([Add support for starting values in bridges · Issue #684 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/issues/684))
- Since starting values are an optional hint that can improve performance but not correctness, JuMP should silently ignore them if they are not supported by the solver.
- COSMO and SCS supports starting values, but the Hermitan to PSD bridge does not, so JuMP should skip copying the starting values.
- JuMP correctly skips the values for SCS (even though it doesn’t warn the user, this is a choice we made), but it errors for COSMO.
- I don’t know why it errors, which is the bug.

So the conclusion is: don’t use starting values for now if you are using HermitianPSDCone 😢

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [October 29, 2023, 10:25pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/6 "2023-10-29T22:25:56Z")

</div>

The starting values are implemented in [Implement starting values for Variable.Hermitian bridge by blegat · Pull Request #2330 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/pull/2330)  
You can try it out with:

```julia
using Pkg
pkg"add MathOptInterface#bl/start_herm"

```

restart Julia for the changes to take effect.

---

<div class="post-metadata">

### Author: ![akirakyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akirakyle/32/202781_2.png) [@akirakyle](https://discourse.julialang.org/u/akirakyle)
#### Post date: [November 2, 2023, 7:05pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/7 "2023-11-02T19:05:13Z")

</div>

Thanks @odow and @blegat for all the fast fixes related to this issue, I’m really quite impressed how quickly this has been addressed!

I’ve been trying to follow along the linked github issues and PRs as best I can but I may not be understanding exactly what’s been fixed yet.

The example I’ve posted now works for me with the latest master versions of JuMP and MathOptInterface when using the `start =` keyword of `@variable`. I can even get `set_start_value` working when using real starting values like so: `set_start_value.(real.(E2), real.(E_))`. However I can’t seem to figure out how to use `set_starting_value` with a hermitian starting value that has imaginary components. For example

```julia
using JuMP, LinearAlgebra, COSMO

model = Model(COSMO.Optimizer)
set_silent(model)

ρs = [[[1 0]; [0 0]],
       [[1 1]; [1 1]]/2 ]

E_ = [[1 1im]; [-1im 1]]

@variable(model, E1[1:2, 1:2] in HermitianPSDCone())
@variable(model, E2[1:2, 1:2] in HermitianPSDCone())
@constraint(model, E1+E2 == LinearAlgebra.I)
@objective(model, Max, real(dot(ρs, [E1,E2])) / 2)

set_start_value.(real.(E2), real.(E_))
set_start_value.(imag.(E2), imag.(E_))

optimize!(model)
solution_summary(model)

```

gives me the error

```julia
Cannot call set_start_value with 0 because it is not an affine expression of one variable.

```

Using the `start=` keyword instead works just fine for this example so I can just use that for now, but I assume for repeatedly solving same problem with different coefficients, it would be more efficient to update the start value of with `set_start_value` rather than having to remove then re-add the variable?

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 2, 2023, 7:22pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/8 "2023-11-02T19:22:13Z")

</div>

The issue is that the off-diagonal entries in `E1` and `E2` are actually the same variable. So there is a problem setting the `imag(E2[2, 1])` element, which is actually `-imag(E2[1, 2])`

I didn’t test, but you could do something like this:

```julia
function set_hermitian_start(x, start)
    for j in 1:size(x, 2), i in 1:size(x, 1)
        set_start_value(real(x[i, j]), real(start[i, j]))
        if i < j
            set_start_value(imag(x[i, j]), imag(start[i, j]))
        end
    end
    return
end
set_hermitian_start(E2, E_)

```

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [November 2, 2023, 7:23pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/9 "2023-11-02T19:23:43Z")

</div>

The other issue is that there is no imaginary variable associated to the diagonal entries, so imag returns `0` hence the error message saying that you cannot call `set_start_value` with `0 .

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 2, 2023, 7:25pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/10 "2023-11-02T19:25:27Z")

</div>

@blegat, I guess we could handle that case if the start is also 0?

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [November 2, 2023, 7:31pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/11 "2023-11-02T19:31:37Z")

</div>

Yes, setting a starting value to a constant could be ignored, especially if they are the same.

---

<div class="post-metadata">

### Author: ![akirakyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akirakyle/32/202781_2.png) [@akirakyle](https://discourse.julialang.org/u/akirakyle)
#### Post date: [November 2, 2023, 10:14pm UTC](https://discourse.julialang.org/t/wram-start-of-hermitianpsdcone-in-jump/105491/12 "2023-11-02T22:14:43Z")

</div>

@odow the `set_hermitian_start` function works for me. Thanks for explaining why what I was doing wasn’t working!
