# Can I query is\_continuous about a JuMP model?

**URL:** https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [March 29, 2025, 10:51am UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484 "2025-03-29T10:51:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [March 29, 2025, 10:51am UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484/1 "2025-03-29T10:51:30Z")

</div>

We can learn from the `print(model)` (`🍅`) that if a `model` has a **variable** which is **not purely continuous** (e.g. Integer/binary/semi~).

```julia
julia> model
A JuMP Model
├ solver: Gurobi
├ objective_sense: FEASIBILITY_SENSE
├ num_variables: 1
├ num_constraints: 1
│ └ JuMP.VariableRef in MOI.ZeroOne: 1 🍅
└ Names registered in the model
  └ :x

```

Then, can I _programmatically_ query this related property?  
e.g. the provisional `JuMP.is_continuous(model)` as follows

```julia
import JuMP, Gurobi
model = JuMP.Model(Gurobi.Optimizer)
JuMP.@variable(model, x[1:3] >= 0)
JuMP.set_integer(x[3])
JuMP.is_continuous(model) # false
JuMP.unset_integer(x[3])
JuMP.is_continuous(model) # true
JuMP.@variable(model, y, Bin)
JuMP.is_continuous(model) # false

```

Since linear optimization (LP) is the staple part of continuous optimization, it is indeed more favorable to have `JuMP.is_linear`,

```julia
model = JuMP.Model(Gurobi.Optimizer)
JuMP.@variable(model, z)
JuMP.@constraint(model, z * z <= 0)
JuMP.is_linear(model) || JuMP.is_continuous(model) && error("NLP") # ERROR: NLP

```

---

<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: [March 29, 2025, 7:34pm UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484/2 "2025-03-29T19:34:53Z")

</div>

What is the motivation for adding `is_continuous`? In what settings is it useful?

JuMP doesnt have strict categories like “this model is linear”.

You could loop over `list_of_constraint_types(model)` to decide what type of model you have.

You could do

```julia
function is_linear(model)
    if objective_sense(model) != FEASIBILITY_SENSE
        F = objective_function_type(model)
        # But what about Vector{AffExpr}?
        if !(F <: VariableRef || F <: AffExpr)
            return false
        end
    end
    for (F, S) in list_of_constraint_types(model)
        # But what about F = Vector{AffExpr}? Some sets are linear...
        if !(F <: VariableRef || F <: AffExpr)
            return false
        end
    end
    return true
end

```

and

```julia
function is_continuous(model)
    for (F, S) in list_of_constraint_types(model)
        if S <: Union{
            MOI.ZeroOne,
            MOI.Integer,
            MOI.Semiinteger,
            MOI.Semicontinuous,
            # What about MOI.SOS1, MOI.SOS2, MOI.Indicator, MOI.Complements,
            # MOI.AllDifferent, MOI.BinPacking... there are others
        }
            return false
        end
    end
    return true
end

```

An issue is that the concept of “is linear” and “is continuous” is not perfectly defined.

---

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [March 30, 2025, 1:24am UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484/3 "2025-03-30T01:24:26Z")

</div>

We could make it much easier, i.e.,  
is there a method to associate a String to a `model`? (e.g. a so-called _name_?)

```julia
model = JuMP.Model()
JuMP.write_note(model, "mip_master"::String)
# many lines ...
my_note = JuMP.read_note(model)
occursin("mip", my_note) && print("I know it is a mip!")

```

Currently do we already have these two functions?

> [@odow](#):
>
> `# But what about F = Vector{AffExpr}? Some sets are linear...`

What is meant by “Some sets are linear…”? Please give me a link? I wonder what sets are linear.

---

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [March 30, 2025, 1:35am UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484/4 "2025-03-30T01:35:44Z")

</div>

Yes, this is a good idea. It can also simplify this function you wrote

> [@Add an "optimize\_assert\_optimal" functionality in JuMP would be handier?](https://discourse.julialang.org/t/add-an-optimize-assert-optimal-functionality-in-jump-would-be-handier/124458/2):
>
> For example, at the cost of an extra argument, you could use a function:
> 
> ```julia
> function optimize!_and_assert_optimality(model, name)
> JuMP.optimize!(model)
> if (status = JuMP.termination_status(model)) != JuMP.OPTIMAL
> error("$name: $status")
> end
> end
> 
> optimize!_and_assert_optimality(model_123, "model_123")
> 
> ```
> 
> One place where the function approach would be better is:
> 
> ```julia
> models = Dict("A" => model_123, "B" => model456)
> for (name, model) in models
> @optimise_assert_optimal model
> # or
> optimize!_and_assert_optimality(model, name)
> end
> 
> ```

---

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [March 30, 2025, 11:24am UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484/5 "2025-03-30T11:24:14Z")

</div>

JuMP already has `set_name` for `ConstraintRef` and `GenericVariableRef`, what about also for `Model (alias for JuMP.GenericModel{Float64})`.  
And then use `JuMP.get_name(model)` to fetch it (the `get_name` do not exist though). These 2 API should be not very strenuous?

In this case users will feel more convenience, e.g. memorizing attributes of different models they have created.

---

<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: [March 30, 2025, 7:13pm UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484/6 "2025-03-30T19:13:25Z")

</div>

You have always been able to use the MOI interface:

```Julia
julia> model = Model();

julia> MOI.get(model, MOI.Name())
""

julia> MOI.set(model, MOI.Name(), "My Model")

julia> MOI.get(model, MOI.Name())
"My Model"

```

I’ve opened a PR in JuMP to add support for `set_name(::Model, ::String)`. We already had `name(::Model)`.

See [Add set\_name(model::GenericModel, name::AbstractString) by odow · Pull Request #3967 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/pull/3967)

---

<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: [March 30, 2025, 7:16pm UTC](https://discourse.julialang.org/t/can-i-query-is-continuous-about-a-jump-model/127484/7 "2025-03-30T19:16:50Z")

</div>

> [@WalterMadelim](#):
>
> What is meant by “Some sets are linear…”?

See [Standard form problem · JuMP](https://jump.dev/JuMP.jl/stable/moi/manual/standard_form/#Vector-cones)

`VectorOfVariables` or `VectorAffineFunction` in `Zeros`, `Nonpositives`, `Nonnegatives`, and `Hyperrectangle`, depending on how you wanted to define things, perhaps also `NormOneCone` and `NormInfinityCone`, and then if those, `NormCone`, but only if `p` is `1.0` or `Inf`.

JuMP does not have a neat standard form like you might find in a textbook. Questions like `is_linear` are surprisingly nuanced.
