Skip to content

Run and configure the solver

To run your optimization model call,

m.optimize()

Recall that you chose your solver upon creating your model.

Auto-generate IIS with Gurobi

Infeasible models are often hard to debug. Pyoframe offers Gurobi users the option to automatically compute and save the Irreducible Inconsistent Subsystem (IIS) whenever a model is infeasible. The IIS is the smallest possible model that is still infeasible, making it significantly easier to discover which constraints are causing the infeasibility. To enable this option, simply specify the file where the IIS should be save (filename must end in .ilp):

m.optimize(if_infeasible_write_iis_to_file="infeasible_model.ilp")

Note that solver_uses_variable_names must have been set to True when initializing the Model for this option to be available.

Configure solver parameters

Every solver has a set of parameters that you can read or set using model.params.<your-param>.

Refer to the list of Gurobi parameters.

m = pf.Model("gurobi")
m.params.Method = 2  # Use barrier method
m.params.TimeLimit = 100

Refer to the list of COPT parameters.

m = pf.Model("copt")
m.params.RelGap = 0.01
m.params.TimeLimit = 100

Refer to the list of HiGHS options.

m = pf.Model("highs")
m.params.time_limit = 100.0
m.params.mip_rel_gap = 0.01

Refer to the list of Ipopt options.

m = pf.Model("ipopt")
m.params.tol = 1e-6
m.params.max_iter = 1000

Warning

Ipopt does not support reading parameters (only setting them).

Configure solver attributes

Pyoframe lets you read and set solver attributes using model.attr.<your-attribute>. For example, if you'd like to prevent the solver from printing to the console you can do:

m = pf.Model()
m.attr.Silent = True

Pyoframe supports a set of standard attributes as well as additional Gurobi attributes and COPT attributes.

>>> m.optimize()
>>> m.attr.TerminationStatus  # PyOptInterface attribute (always available)
<TerminationStatusCode.OPTIMAL: 2>
>>> m.attr.Status  # Gurobi attribute (only available with Gurobi)
2

Variable and constraint attributes

Similar to above, Pyoframe allows directly accessing the PyOptInterface or the solver's variable and constraint attributes.

m = pf.Model()
m.X = pf.Variable()
m.X.attr.PrimalStart = 5  # Set initial value for warm start

If the variable or constraint is dimensioned, the attribute can accept/return a DataFrame instead of a constant.

Configure an advanced license

Both COPT and Gurobi support advanced license configurations through the solver_env parameter:

# Cluster configuration
m = pf.Model("copt", solver_env={"CLIENT_CLUSTER": "cluster.example.com"})
# Compute server
m = pf.Model(
    "gurobi",
    solver_env={"ComputeServer": "server.example.com", "ServerPassword": "password"},
)