Skip to main content

SOS constraints in Gurobi with Julia

Answered

Comments

7 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi John,

    For reproducibility it is can be important to make sure the Julia environments are the same.

    I know you said you are pretty sure you have the latest versions, but I think we should make this 100% sure.

    Can I suggest you run the Pkg.status() function to print out the installed packages and their versions, in each of your environments?  In particular the versions for JuMP-dev packages will be relevant.

    Can you also check the version of Julia on each machine, with either the VERSION constant, or the versioninfo command?

    - Riley

    0
  • Albert John Crosby
    First Comment
    First Question

    From where do I run Pkg.status()? When I run it from the Julia prompt, I get Pkg not defined. 

    If I do versioninfo(), I get (on my laptop)

    Julia Version 1.9.3
    Commit bed2cd540a (2023-08-24 14:43 UTC)

    Build Info:
    Official https://julialang.org/ release

    Platform Info:
      OS: Windows (x86_64-w64-mingw32)
      CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
      WORD_SIZE: 64
      LIBM: libopenlibm
      LLVM: libLLVM-14.0.6 (ORCJIT, tigerlake)
      Threads: 4 on 8 virtual cores

    Environment:
      JULIA_EDITOR = code
      JULIA_NUM_THREADS = 4

    From the university High Performance Computing Center Linus shell, I get

    Julia Version 1.9.4
    Commit 8e5136fa297 (2023-11-14 08:46 UTC)
    Build Info:
      Official https://julialang.org/ release
    Platform Info:
      OS: Linux (x86_64-linux-gnu)
      CPU: 40 Ã Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
      WORD_SIZE: 64
      LIBM: libopenlibm
      LLVM: libLLVM-14.0.6 (ORCJIT, skylake-avx512)
      Threads: 40 on 40 virtual cores
    Environment:
      LD_LIBRARY_PATH = /opt/conda/lib/libfabric:/usr/local/lib:/cm/shared/applications/slurm/23.02.2/lib:/cm/shared/applications/slurm/23.02.2/lib/slurm:/.singularity.d/libs
      JULIA_EDITOR = code

    There is a slight mismatch in Julia versions: 1.9.3 v 1.9.4.

     

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi John,

    You will need to run

    using(Pkg)

    - Riley

    0
  • Albert John Crosby
    First Comment
    First Question

    On my laptop: 

    Pkg.status()
    Project FactorModels v0.1.0
    Status `C:\Users\ajcrosby\Documents\GitHub\FactorModels\Project.toml`
      [336ed68f] CSV v0.10.11
      [a93c6f00] DataFrames v1.6.1
      [8bb1440f] DelimitedFiles v1.9.1
      [aaf54ef3] DistributedArrays v0.6.7
    ⌃ [2e9cd046] Gurobi v1.0.3
    ⌃ [87dc4568] HiGHS v1.5.2
    ⌃ [4076af6c] JuMP v1.11.1
      [1fd47b50] QuadGK v2.9.1
    ⌃ [2913bbd2] StatsBase v0.34.0
      [fdbf4ff8] XLSX v0.10.0
      [37e2e46d] LinearAlgebra
      [9a3f8284] Random
      [10745b16] Statistics v1.9.0
    Info Packages marked with ⌃ have new versions available and may be upgradable.

    On Linux: 

    Status `~/.julia/environments/v1.9/Project.toml`
      [336ed68f] CSV v0.10.11
      [a93c6f00] DataFrames v1.6.1
      [8bb1440f] DelimitedFiles v1.9.1
      [2e9cd046] Gurobi v1.2.0
      [87dc4568] HiGHS v1.7.5
      [4076af6c] JuMP v1.17.0
      [1fd47b50] QuadGK v2.9.1
      [2913bbd2] StatsBase v0.34.2
    â [d1185830] SymbolicUtils v1.4.0
      [fdbf4ff8] XLSX v0.10.0
      [8ba89e20] Distributed
      [37e2e46d] LinearAlgebra
      [de0858da] Printf
      [9a3f8284] Random
      [10745b16] Statistics v1.9.0
    Info Packages marked with â have new versions available and may be upgradable.

    I notice there is quite a difference in JuMP versions   ----   and the error may connect to the way JuMP sets up constraints.

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    The JuMP package is the latest available, and this is where the error is coming from, so if it's not running on the linux machine I would guess there are at least two possible explanations:

    * There is a bug in JuMP 1.17.0 causing your issue
    * There was a bug in JuMP v1.11.1 and you should have got the same error on your laptop

    JuMP uses semantic versioning so we should be able to rule out a breaking change in the API since the major version hasn't changed.  You could try forcing the installation of JuMP 1.11.1 (or a version earlier than 1.17) and see what affect that has.

    Perhaps the JuMP forum could also be of help.

    - Riley

     

    0
  • Albert John Crosby
    First Comment
    First Question

    One further point: I can make the code run more robustly by inserting the variable declaration (the "beta"  β  is the name of one of the variables):   

    @variable(model, -1.0e200 <= β[1:nfac] <= 1.0e200). 
    Before I just had the variable declaration   @variable(model, β[1:nfac])
    It is clear from heuristics that the optimal value is between, say, -10 and +10, so the constraint -1.0e200 <= β[1:nfac] <= 1.0e200 will never bind but it has stopped the code (using SOS1) crashing immediately. 
     
     
     
    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Bounding the variable seems like a valid fix given the original error message.

    It looks like the difference you see may lie in versions 1.22+ of MathOptInterface.jl

    When you run Pkg.status() it displays the top level packages installed, but using Pkg.status(; mode=PKGMODE_MANIFEST) will show dependencies of dependencies and that's where MathOptInterface version will be shown.

    The MathOptInterface changelog makes reference to adding SOS1ToMILPBridge in version 1.22.

    Perhaps SOS1 constraints were just not translated to linear constraints prior to version 1.22 - but ideally adding this option wouldn't cause an error that crashes execution.  Perhaps it is worth opening a Github issue for MathOptInterface to address this problem?

     

    0

Please sign in to leave a comment.