Skip to main content

When does gurobipy call C code?

Answered

Comments

1 comment

  • Simon Bowly
    Gurobi Staff Gurobi Staff

    Hi Samuel,

    gurobipy is tightly integrated with the Gurobi C API, so C code is called any time you make a gurobipy API call. For example:

    1. gp.Model(...) calls the C API to construct a model
    2. x = model.addVar() calls the C API to add a variable to a model
    3. model.addConstr(x + y <= 1) calls the C API to add a constraint (though the expression arithmetic is done on the python side)

    All C code that is called here is compiled: gurobipy itself is a compiled extension module, which is linked to the compiled Gurobi library.

    Execution does return back to Python during solving in a few cases. One case is logging: log messages from the solver are routed back to Python's logging module and output streams. Another case is callbacks: if you provide a callback function, execution returns to your Python code on every callback invocation.

    0

Please sign in to leave a comment.