# Convex optimisation over complex variables

**URL:** <https://discourse.julialang.org/t/convex-optimisation-over-complex-variables/1388>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [January 10, 2017, 12:48pm UTC](https://discourse.julialang.org/t/convex-optimisation-over-complex-variables/1388 "2017-01-10T12:48:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jedrek](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@Jedrek](https://discourse.julialang.org/u/Jedrek)\
**Post date:** [January 10, 2017, 12:48pm UTC](https://discourse.julialang.org/t/convex-optimisation-over-complex-variables/1388/1 "2017-01-10T12:48:21Z")

</div>

Hello Everyone, I’ve just installed Julia and Convex.jl (package for convex optimisation) and things work fine as long as my variables are real, e.g.

> using Convex  
> using SCS  
> x = Variable()

And then I can optimise. However, I want to deal with complex variables. According to [http://convexjl.readthedocs.io/en/latest/complex-domain\_optimization.html](http://convexjl.readthedocs.io/en/latest/complex-domain_optimization.html)

this should just work if I type

> x = ComplexVariable()

Unfortunately, what I get is:

> ERROR: UndefVarError: ComplexVariable not defined

I guess I must be missing a package or something… Could anyone help me to figure this out? Thanks a lot.

In case this matters:

> julia\> versioninfo()  
> Julia Version 0.5.0  
> Commit 3c9d753\* (2016-09-19 18:14 UTC)  
> Platform Info:  
> System: Linux (x86\_64-suse-linux)  
> CPU: Intel(R) Core™ i3-2350M CPU @ 2.30GHz  
> WORD\_SIZE: 64  
> BLAS: libopenblas (DYNAMIC\_ARCH NO\_AFFINITY Sandybridge)  
> LAPACK: libopenblas\_openmp.so.0  
> LIBM: libopenlibm  
> LLVM: libLLVM-3.7.1 (ORCJIT, sandybridge)

> julia\> Pkg.installed()  
> Dict{String,VersionNumber} with 24 entries:  
> “NaNMath” =\> v"0.2.2"  
> “ForwardDiff” =\> v"0.3.3"  
> “Optim” =\> v"0.7.4"  
> “JuMP” =\> v"0.15.0"  
> “Conda” =\> v"0.4.0"  
> “LineSearches” =\> v"0.1.3"  
> “DiffBase” =\> v"0.0.2"  
> “SHA” =\> v"0.3.0"  
> “Lazy” =\> v"0.11.4"  
> “ReverseDiffSparse” =\> v"0.6.0"  
> “ZMQ” =\> v"0.4.0"  
> “JSON” =\> v"0.8.0"  
> “DataStructures” =\> v"0.5.1"  
> “Compat” =\> v"0.11.0"  
> “IJulia” =\> v"1.3.3"  
> “SCS” =\> v"0.2.7"  
> “Calculus” =\> v"0.1.15"  
> “MathProgBase” =\> v"0.5.8"  
> “MacroTools” =\> v"0.3.4"  
> “BinDeps” =\> v"0.4.5"  
> “Convex” =\> v"0.4.0"  
> “PositiveFactorizations” =\> v"0.0.3"  
> “Nettle” =\> v"0.2.4"  
> “URIParser” =\> v"0.1.6"

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [January 10, 2017, 12:56pm UTC](https://discourse.julialang.org/t/convex-optimisation-over-complex-variables/1388/2 "2017-01-10T12:56:23Z")

</div>

I don’t think your Convex is new enough. The docs you are linking to are “latest”, and in the docs for 0.4.0, this feature isn’t available. It doesn’t look like there is a release that supports this, but you can checkout the master version to try it.

---

<div class="post-metadata">

**Author:** ![Jedrek](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@Jedrek](https://discourse.julialang.org/u/Jedrek)\
**Post date:** [January 10, 2017, 2:53pm UTC](https://discourse.julialang.org/t/convex-optimisation-over-complex-variables/1388/3 "2017-01-10T14:53:31Z")

</div>

Great, thanks a lot 🙂 !  
Pulling the master branch did the trick. Below a small working example with complex variables:

> using Convex  
> using SCS  
> X = [0 1; 1 0]  
> Y = [0 -im; im 0]  
> Z = [1 0; 0 -1]  
> rho = ComplexVariable(2, 2)  
> prob = maximize(real(trace(rho \* X)))  
> prob.constraints += [rho in :SDP]  
> prob.constraints += [trace(rho) == 1]  
> prob.constraints += [trace(rho \* Y) == 1/sqrt(2)]  
> prob.constraints += [trace(rho \* Z) == 0.5]  
> solve!(prob, SCSSolver(verbose=0))

---

<div class="post-metadata">

**Author:** ![KrishnaKanhaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krishnakanhaiya/32/443_2.png) [@KrishnaKanhaiya](https://discourse.julialang.org/u/KrishnaKanhaiya)\
**Post date:** [February 3, 2017, 8:24am UTC](https://discourse.julialang.org/t/convex-optimisation-over-complex-variables/1388/4 "2017-02-03T08:24:28Z")

</div>

@Jedrek I am glad that you got your problem solved. Do let us know how you are using Convex.jl. We are trying to keep the record of the people who are using Convex.jl in their work.

---

<div class="post-metadata">

**Author:** ![KrishnaKanhaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krishnakanhaiya/32/443_2.png) [@KrishnaKanhaiya](https://discourse.julialang.org/u/KrishnaKanhaiya)\
**Post date:** [February 3, 2017, 11:38am UTC](https://discourse.julialang.org/t/convex-optimisation-over-complex-variables/1388/5 "2017-02-03T11:38:51Z")

</div>

Also, support for complex numbers is in it’s initial stages. Any pull request regarding it’s application would be appreciated 🙂
