# Julia's processing capacity

**URL:** <https://discourse.julialang.org/t/julias-processing-capacity/26251>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [July 11, 2019, 12:19pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251 "2019-07-11T12:19:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [July 11, 2019, 12:19pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/1 "2019-07-11T12:19:55Z")

</div>

Julia provides information of type: number of iterations, solution time, gap, number of variables, number of constraints

---

<div class="post-metadata">

**Author:** ![Karajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karajan/32/8545_2.png) [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Post date:** [July 11, 2019, 12:30pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/2 "2019-07-11T12:30:10Z")

</div>

I am not sure what the context of your question is. Do you have some code to explain your situation to us? And finally, what is your question, what do you want to know?

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [July 11, 2019, 12:58pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/3 "2019-07-11T12:58:53Z")

</div>

I developed a mathematical code and need some information about the functions, and this information is the output data I mentioned earlier (number of iterations, solution time, interval, number of variables, number of constraints)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 11, 2019, 1:42pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/4 "2019-07-11T13:42:24Z")

</div>

> [@RaquelSantos](#):
>
> the output data I mentioned earlier

It would be much easier to help you if you provided an MWE, or at least linked the earlier discussion for context.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [July 11, 2019, 2:26pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/5 "2019-07-11T14:26:52Z")

</div>

The profiler can help with iterations and time:

[https://docs.julialang.org/en/v1/manual/profile/index.html](https://docs.julialang.org/en/v1/manual/profile/index.html)

It sounds like you are using an optimization package, so I’m not sure about the other two questions.

> [@Tamas\_Papp](#):
>
> It would be much easier to help you if you provided an MWE

In case it helps the original poster or anyone else, MWE == minimum working example, also known as minimum reproducible example. StackOverflow has a nice write-up about how to do this:

> **[How to create a Minimal, Reproducible Example - Help Center](https://stackoverflow.com/help/minimal-reproducible-example)**
>
> Stack Overflow | The World’s Largest Online Community for Developers

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [July 11, 2019, 4:23pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/6 "2019-07-11T16:23:47Z")

</div>

> [@ihnorton](#):
>
> StackOverflow has a nice write-up about how to do this

Also worth taking a look at [this post](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [July 11, 2019, 8:53pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/7 "2019-07-11T20:53:23Z")

</div>

Based on a previous question you had related to optimization code (Jump?), I assume that you refer to such problems.

The Optim package solvers provide a nice resume of several of the things you ask for. Optim is nice in the sense of being written in Julia, and the developers can therefore provide lots of information about the inner workings of the code. Unfortunately, solvers for general constrained problems are lacking in Optim (I think). Probably, integer/mixed-integer solvers are also lacking?? (It takes time to write good code…!!)

Jump is more of an optimization modeling language and provides access to industry strength solvers, typically based on compiled C (or Fortran?) code. Because of that, the Jump solvers are probably more limited in the scope of information available.

You ask for “gap” information. Are you referring to the duality gap?

Solution time… can easily be found using the `time` macro, i.e.:

```julia
julia> @time solve(...)

```

or:

```julia
julia> @time begin
solve(...)
....
end

```

if you want to time multiple commands.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [July 12, 2019, 6:48pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/9 "2019-07-12T18:48:02Z")

</div>

Yes, I mean an optimization problem.  
This is the code I am building, I have tried to summarize it to stay in MWE format (I do not know if it is correct).  
If it is an optimization model, the answer I want to get is about the time that Julia takes to calculate the constraint function, the number of variables, and the time it took to generate the objective value.

This is the code.  
I used the time macro as in the example, and it did not work.

```julia
using JuMP, GLPK
Model1 = Model(with_optimizer(GLPK.Optimizer))

L = [12; 60]
T = [0.25; 0.5]
D = [36]

@variable(Model1, Y[i=1:2] >=0)
@objective(Model1, Max, sum(Y[i]*L[i] for i ∈ 1:2))
Yy = transpose(Y)

for i in 1
   @constraint(Model1,Yy*T[2*i-2+1:2*i] <= D[i])
end

print(Model1)
optimize!(Model1) #model status
println("Objective value: ", JuMP.objective_value(Model1))
println("Y[1] = ", JuMP.value(Y[1]))
println("Y[2] = ", JuMP.value(Y[2]))

```

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [July 12, 2019, 7:11pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/10 "2019-07-12T19:11:07Z")

</div>

OK… I think this counts as MWE (eh – `tp`?)… at least your code runs on my PC, and I get:

```julia
Max 12 Y[1] + 60 Y[2]
Subject to
 Y[1] >= 0.0
 Y[2] >= 0.0
 0.25 Y[1] + 0.5 Y[2] <= 36.0
Objective value: 4320.0
Y[1] = 0.0
Y[2] = 72.0

```

Regarding timing – perhaps my suggestion missed what you are interested in – but here is what I get:

```julia
julia> @time optimize!(Model1) #model status
 0.000054 seconds (10 allocations: 576 bytes)

```

Next step: check documentation of JuMP and GLPK, and see if there is an information flag to provide the rest of the information you need.

By googling `GLPK`, I found the following link: `https://en.wikibooks.org/wiki/GLPK/Using_GLPSOL`, which may provide you with an answer to whether the underlying GLPK algorithm has the information you need. If it doesn’t, you may need to consider other solvers.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [July 15, 2019, 11:41am UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/12 "2019-07-15T11:41:25Z")

</div>

Ok, thanks very much!!

---

<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:** [July 16, 2019, 3:39am UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/13 "2019-07-16T03:39:56Z")

</div>

You can also do `MOI.get(Model1, MOI.SolveTime())`

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [July 16, 2019, 1:15pm UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/15 "2019-07-16T13:15:07Z")

</div>

Thank you for your help.  
Still about the optimization code I’m building, I’d like to get an output with the relative difference of the final optimization.  
I need to find the gap between the best value and the best possible target value. I tried to use RelativeGap (), but I did not succeed.

I would also like to output from my code the cumulative number of iterations during the optimization process in resolving the problem. I tried using the BarrierIterations (), but it did not force success.  
This is the code:

```julia
using JuMP, GLPK
Model1 = Model(with_optimizer(GLPK.Optimizer))

L = [12 ;60]
T = [0.25 0.1 0.1; 0.5 0.75 0.4]
D = [36; 22; 15]

@variable(Model1, Y[i=1:2] >=0)
@objective(Model1, Max, sum(Y[i]*L[i] for i ∈ 1:2))
Yy = transpose(Y)

for i in 1:3
   @constraint(Model1,Yy*T[2*i-2+1:2*i] <= D[i])
end

print(Model1)
optimize!(Model1) #model status
println("Objective value: ", JuMP.objective_value(Model1))
println("Y[1] = ", JuMP.value(Y[1]))
println("Y[2] = ", JuMP.value(Y[2]))
@time optimize!(Model1)
[Model1]
MOI.get(Model1, MOI.SolveTime())

```

---

<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:** [July 17, 2019, 4:02am UTC](https://discourse.julialang.org/t/julias-processing-capacity/26251/16 "2019-07-17T04:02:22Z")

</div>

The RelativeGap is not implemented yet for the GLPK interface but @odow is adding it in [https://github.com/JuliaOpt/GLPK.jl/pull/101](https://github.com/JuliaOpt/GLPK.jl/pull/101)
