--- sd_hide_title: true hide-toc: true --- # Gurobi (clients-GurobiClient)= ## Gurobi Optimizer Gurobi Optimizer is a Mixed Integer Programming (MIP) solver provided by Gurobi that can handle quadratic problems in integer and real variables, including QUBO. ```{note} To use Gurobi, you need to install the [Gurobi Optimizer](https://www.gurobi.com/solutions/gurobi-optimizer/) and license on the machine running the Amplify SDK. ``` :**Solver specification**: ```{list-table} :width: 100% :widths: 2 3 * - Client class - {py:class}`amplify.GurobiClient` * - [Execution parameters](amplify.GurobiClient.parameters) - {py:class}`amplify.GurobiClient.Parameters` * - [Execution result](amplify.Result.client_result) - {py:class}`amplify.GurobiClient.Result` * - [Execution time](amplify.Result.execution_time) - {py:attr}`amplify.GurobiClient.Result.runtime` * - Supported version - 9.0.0 or later * - API reference - [{bdg-info}`📖 Reference Manual`](https://www.gurobi.com/documentation/current/refman/index.html) ``` ```{csv-table} :header-rows: 1 :stub-columns: 1 :width: 100% :widths: 1 1 1 1 1 ,Binary variable,Ising variable,Integer variable,Real variable Objective function,2nd,\-,2nd,2nd Equality constraint,2nd,\-,2nd,2nd Inequality constraint,2nd,\-,2nd,2nd ``` :**Client class**: In addition to [the common interface](#client-common-interface), the client class has the following method. ```{list-table} :width: 100% :header-rows: 1 :widths: 1 1 3 * - Method - Return type - Details * - {py:meth}`~amplify.GurobiClient.tune` - {py:obj}`None` - Perform execution parameter search ``` ```{note} {py:class}`~amplify.GurobiClient` file output works as follows. - {py:attr}`~amplify.GurobiClient.write_request_data`: : Output the model to a file with the specified file path extension. Possible file extensions are `.mps`, `.rew`, `.lp`, `.rlp`, `.dua/.dlp` (as a model of LP dual problem). - {py:attr}`~amplify.GurobiClient.write_response_data`: : Output the solution in a file with the specified file path extension. Possible file extensions are `.sol` or `.json`. ``` ```{seealso} See [Gurobi Parameters](https://www.gurobi.com/documentation/current/refman/parameters.html#sec:Parameters) for details on the attributes of the {py:class}`~amplify.GurobiClient.Parameters` class that can be specified in {py:attr}`~amplify.GurobiClient.parameters`. Note that the attribute names of the {py:class}`~amplify.GurobiClient.Parameters` class are standardized to *snake_case*. ``` ```{note} All attributes of the {py:class}`~amplify.GurobiClient.Parameters` class are initialized to {py:obj}`None` (unset) by default, but some attributes are explicitly passed to Gurobi when {py:obj}`None` is specified for convenience, as follows. - {py:attr}`~amplify.GurobiClient.Parameters.log_to_console`: : Contrary to Gurobi's default (`1`{l=python}), `0`{l=python} (no output) is treated as default. - {py:attr}`~amplify.GurobiClient.Parameters.seed`: : Contrary to Gurobi's default (`0`{l=python}), this is initialized by generating a hardware random number. ``` :**Configuration example**: ```{testcode} from amplify import GurobiClient from datetime import timedelta client = GurobiClient() # Set installation path # (necessary if the installation path is not detected automatically) # client.library_path = "/opt/gurobi950/linux64/lib/libgurobi.so.9.5.0" # Set the execution time to 100 seconds client.parameters.time_limit = timedelta(seconds=100) ``` :**Execution example**: ```python from amplify import Model, VariableGenerator, solve # Create decision variables and the objective function g = VariableGenerator() q = g.array("Binary", 2) f = q[0] * q[1] + q[0] - q[1] + 1 # Create a model model = Model(f) # Run the solver result = solve(model, client) ``` To obtain the solver version: ```python >>> client.version '9.5.0' ```