amplify.client.GurobiClient

class GurobiClient

Bases: pybind11_object

A class for using Gurobi client.

__init__(self: amplify.client.GurobiClient) None

Methods

__init__(self)

solve(*args, **kwargs)

Solves a given polynomial or matrix model.

tune(*args, **kwargs)

Tune parameters for a given model.

Attributes

gurobi_path

The filepath to the shared library file of gurobi.

num_bits

The maximum number of available variables.

parameters

Obtains the parameter class of GurobiClient.

version

Get the version string of the Gurobi dynamic library.

write_model

Set or get the file path to save the model.

write_solution

Set or get the file path to save the solution.

property gurobi_path

The filepath to the shared library file of gurobi.

Type:

str

property num_bits

The maximum number of available variables.

Type:

int

property parameters

Obtains the parameter class of GurobiClient.

Type:

GurobiClientParameters

solve(*args, **kwargs)

Solves a given polynomial or matrix model.

Overloads:

  • solve(poly)
  • solve(matrix, constant)
Parameters:
Returns:

A result class that provides information about execution.

Return type:

GurobiClientResult

Example

from amplify import BinarySymbolGenerator
from amplify.client import GurobiClient

gen = BinarySymbolGenerator()
q = gen.array(3)
f = 2 * q[0] * q[1] - q[0] - q[2] + 1  # BinaryPoly type input model

client = GurobiClient()
client.token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client.parameters.time_limit = 1  # time_limit 1 second

result = client.solve(f)
>>> f
2 q_0 q_1 - q_0 - q_2 + 1
>>> [f"energy = {s.energy}, q = {q.decode(s.values)}" for s in result]
['energy = -1.0, q = [1. 0. 1.]']
tune(*args, **kwargs)

Tune parameters for a given model.

Overloads:

  • tune(poly)
  • tune(matrix, constant)
  • tune(model)
Parameters:
Returns:

int

Example

from amplify import BinarySymbolGenerator
from amplify.client import GurobiClient

gen = BinarySymbolGenerator()
q = gen.array(3)
f = 2 * q[0] * q[1] - q[0] - q[2] + 1  # BinaryPoly type input model

client = GurobiClient()
client.parameters.time_limit = 10  # time_limit 10 second

prmfile = client.tune(f)

if prmfile is not None:
    client.parameters.prmfile = prmfile
client.solve(f)
property version

Get the version string of the Gurobi dynamic library.

Type:

str

property write_model

Set or get the file path to save the model. The default value is an empty string, so saving is disabled. Valid extentions are .mps, .rew, .lp, or .rlp for writing the model itself, .dua or .dlp for writing the dualized model (only pure LP).

Type:

str

property write_solution

Set or get the file path to save the solution. The default value is an empty string, so saving is disabled. Valid extentions are .sol or .json.

Type:

str