Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to redirect gurobi's log into julia logging #487

Closed
Betristor opened this issue Oct 3, 2022 · 2 comments
Closed

Is there a way to redirect gurobi's log into julia logging #487

Betristor opened this issue Oct 3, 2022 · 2 comments

Comments

@Betristor
Copy link

Typically julia's output (mostly println and minor logging messages) will show in the REPL, but is there a way to redirect gurobi's log into logging too, as Logging and LoggingExtras modules will do.

@odow
Copy link
Member

odow commented Oct 8, 2022

I'm not sure if there is an easy way to redirect to Logging.jl, but I guess you could write a solver-specific callback that intercepted all MESSAGE callbacks:

using JuMP, Gurobi
model = Model(Gurobi.Optimizer)
set_optimizer_attribute(model, "LogToConsole", false)
function my_callback_function(cb_data, cb_where::Cint)
    if cb_where == GRB_CB_MESSAGE
        resultP = Ref{Ptr{Cchar}}()
        GRBcbget(cb_data, cb_where, GRB_CB_MSG_STRING, resultP) 
        @info unsafe_string(resultP[])
    end
    return
end
MOI.set(model, Gurobi.CallbackFunction(), my_callback_function)

julia> optimize!(model)
[ Info: Gurobi Optimizer version 9.5.1 build v9.5.1rc2 (mac64[x86])
[ Info: Thread count: 4 physical cores, 8 logical processors, using up to 8 threads
[ Info: Optimize a model with 0 rows, 0 columns and 0 nonzeros
[ Info: Model fingerprint: 0xf9715da1
[ Info: Coefficient statistics:
[ Info:   Matrix range     [0e+00, 0e+00]
[ Info:   Objective range  [0e+00, 0e+00]
[ Info:   Bounds range     [0e+00, 0e+00]
[ Info:   RHS range        [0e+00, 0e+00]
[ Info: Presolve time: 0.00s
[ Info: Presolve: All rows and columns removed
[ Info: Iteration    Objective       Primal Inf.    Dual Inf.      Time
[ Info:        0    0.0000000e+00   0.000000e+00   0.000000e+00      0s
[ Info: 
[ Info: Solved in 0 iterations and 0.00 seconds (0.00 work units)
[ Info: Optimal objective  0.000000000e+00
[ Info: 
[ Info: User-callback calls 20, time in user-callback 0.03 sec

See also:

@Betristor
Copy link
Author

Thanks a lot. I implemented this function by passing LogFile parameter into gurobi's setting when using JuMP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants