Skip to main content

When does gurobipy call C code?

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Simon Bowly
    • 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

Post is closed for comments.