# StructuredOptimization.jl : parsing issue when adding constraints

**URL:** <https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411>\
**Category:** Optimization (Mathematical)\
**Created:** [February 10, 2020, 1:27pm UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411 "2020-02-10T13:27:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpetit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rpetit/32/12552_2.png) [@rpetit](https://discourse.julialang.org/u/rpetit)\
**Post date:** [February 10, 2020, 1:27pm UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/1 "2020-02-10T13:27:35Z")

</div>

Hi,

I’m trying to solve a modified LASSO where weights are constrained to be nonnegative, using StructuredOptimization.jl. The documentation suggests this should be possible using a code similar to the one below :

```julia
using StructuredOptimization

n = 5
p = 10
A = rand(n, p)
y = rand(n)

x = Variable(n)

@minimize ls(A*x-y) + norm(x, 1) st x >= 0.

```

This however gives me the following error message :  
“Sorry, I cannot parse this problem for solver of type PANOC{Float64}”

Does someone (maybe @nantonel or @lostella ?) have any idea what is wrong with this ? Thanks anyway for developping this package which I have found extremly useful and easy to use aside this particular case 🙂

---

<div class="post-metadata">

**Author:** ![nantonel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nantonel/32/2889_2.png) [@nantonel](https://discourse.julialang.org/u/nantonel)\
**Post date:** [February 20, 2020, 4:30pm UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/2 "2020-02-20T16:30:30Z")

</div>

Glad you’re enjoying the package! 😀

Unfortunately you cannot solve that type of problem at the moment…  
See the [this section of the documentation](https://kul-forbes.github.io/StructuredOptimization.jl/stable/tutorial/#Limitations-1).

---

<div class="post-metadata">

**Author:** ![rpetit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rpetit/32/12552_2.png) [@rpetit](https://discourse.julialang.org/u/rpetit)\
**Post date:** [February 20, 2020, 5:16pm UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/3 "2020-02-20T17:16:58Z")

</div>

I’ll have a look at it! Thank you for your reply!

---

<div class="post-metadata">

**Author:** ![nboyd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nboyd/32/13251_2.png) [@nboyd](https://discourse.julialang.org/u/nboyd)\
**Post date:** [February 20, 2020, 5:49pm UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/4 "2020-02-20T17:49:50Z")

</div>

For this particular problem, I think the l\_1 norm can be rewritten as sum(x) or 1^Tx (as x is non-negative) and absorbed into the smooth part of the objective. The problem could then be solved with a proximal method (though if your problem is small I’d recommend LBFGS-B).

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [February 20, 2020, 9:52pm UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/5 "2020-02-20T21:52:49Z")

</div>

> [@nboyd](#):
>
> For this particular problem, I think the l\_1 norm can be rewritten as sum(x) or 1^Tx (as x is non-negative) and absorbed into the smooth part of the objective.

I was about to suggest the same:

```julia
using StructuredOptimization

n = 5
p = 10
A = rand(n, p)
y = rand(n)

x = Variable(p)

@minimize ls(A*x-y) + dot(ones(p), x) st x >= 0.0

```

should do the trick?

Edit: fixed the snippet after @nantonel’s suggestion

---

<div class="post-metadata">

**Author:** ![rpetit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rpetit/32/12552_2.png) [@rpetit](https://discourse.julialang.org/u/rpetit)\
**Post date:** [February 21, 2020, 8:47am UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/6 "2020-02-21T08:47:23Z")

</div>

Sure ! I’m a bit ashamed to not have noticed this earlier ! Thank you all for your help 🙂

---

<div class="post-metadata">

**Author:** ![nantonel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nantonel/32/2889_2.png) [@nantonel](https://discourse.julialang.org/u/nantonel)\
**Post date:** [February 21, 2020, 8:53am UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/7 "2020-02-21T08:53:58Z")

</div>

well then, I’m even more ashamed! 🤣

---

<div class="post-metadata">

**Author:** ![nantonel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nantonel/32/2889_2.png) [@nantonel](https://discourse.julialang.org/u/nantonel)\
**Post date:** [February 21, 2020, 9:03am UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/8 "2020-02-21T09:03:23Z")

</div>

Just some minor correction to have the problem accepted:

```julia
n = 5
p = 10
A = rand(n, p)
y = rand(n)

x = Variable(p)

@minimize ls(A*x-y) + dot(ones(p),x) st x >= 0.0

```

that is currently `dot` needs inputs to be `(::Array,::Variable)` and `x >= float(0)`.

---

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [February 21, 2020, 1:50pm UTC](https://discourse.julialang.org/t/structuredoptimization-jl-parsing-issue-when-adding-constraints/34411/9 "2020-02-21T13:50:49Z")

</div>

No one needs to feel shame – this is a textbook example of an [XY Problem](https://en.wikipedia.org/wiki/XY_problem). And for readers, it’s a great reminder to keep this in mind.
