Skip to content

Accessing the solver

Model 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 support all PyOptInterface attributes and, when using Gurobi, all Gurobi attributes.

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

Model parameters (Gurobi only)

Gurobi supports model attributes (see above) and model parameters (full list here). You can read or set model parameters with model.params.<your-parameter>. For example:

m.params.method = 2  # Use a barrier method to solve

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

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