FICO Xpress Optimizer Python Interface
The FICO Xpress Optimizer Python interface (xpress) enables users to formulate, manage, and solve a comprehensive range of mathematical optimization problems including Linear Programming (LP), Quadratic Programming (QP), Second-Order Conic Programming (SOCP), and their mixed-integer counterparts (MILP, MIQP, MIQCQP, MISOCP), along with general nonlinear and mixed-integer nonlinear problems. It offers seamless integration with numerical libraries like NumPy and supports advanced features such as callbacks for solver control. The library is currently at version 9.8.1, with frequent updates including patches and minor versions released multiple times a year.
Common errors
-
ModuleNotFoundError: No module named 'xpress'
cause The `xpress` Python package has not been installed in the current environment, or the environment is not correctly activated.fixRun `pip install xpress` to install the package. Ensure your Python environment is correctly set up and activated. -
xpress.InterfaceError: Xpress licensing error 89: Your license only supports platform(s) win32, win_x86_64. Please contact support@fico.com to upgrade it.
cause This error indicates a mismatch between the platform for which the Xpress license (`xpauth.xpr`) was generated and the current operating system (e.g., using a Windows license on Linux), or the license file is invalid/missing.fixVerify that your license file is valid for your current platform and that the `XPRESS` environment variable is correctly set to the directory containing `xpauth.xpr`. Obtain a platform-appropriate license if necessary. -
SystemError: <built-in method addVariable of xpress.problem object at 0x...> returned NULL without setting an error
cause This generic Python error typically masks a more specific underlying Xpress API error, such as attempting to add a variable with a duplicate name or providing invalid arguments. The true error message is often logged to the console.fixCheck the terminal or IDE console output immediately preceding this error for a more descriptive message (e.g., '1030 Error: Duplicate column names are not allowed'). Correct the modeling mistake based on the detailed console error.
Warnings
- gotcha The `xpress` library, while installable via pip, requires an underlying FICO Xpress license to solve problems. A 'Community License' is included, but it imposes strict limits on problem size (e.g., sum of variables and linear constraints <= 5000, nonlinear tokens <= 1000).
- gotcha Generic `SystemError` or `RuntimeError` messages like `<built-in method [...] of xpress.problem object at [...]> returned NULL without setting an error` are frequently encountered in Jupyter notebooks or similar environments. These often obscure the actual, more descriptive error.
- breaking Model properties on variable, constraint, and SOS objects (e.g., `var.lb`, `constraint.rhs`) are not accessible from within callbacks or while the problem is in a presolved state.
- deprecated Several older Xpress Python module versions (specifically 8.14.1, and 8.14.5 through 8.14.8) were removed from PyPI and Conda repositories on April 22, 2024.
Install
-
pip install xpress
Imports
- xpress
import xpress as xp
Quickstart
import xpress as xp
p = xp.problem(name='my_first_lp')
x1 = p.addVariable(name='x1', lb=0, ub=xp.infinity)
x2 = p.addVariable(name='x2', lb=0, ub=xp.infinity)
p.setObjective(3*x1 + 2*x2, sense=xp.minimize)
p.addConstraint(4*x1 + 2*x2 >= 10, name='c1')
p.addConstraint(x1 + x2 >= 3, name='c2')
p.optimize()
if p.getProbStatus() == xp.lp_optimal:
print(f"Solution Status: Optimal")
print(f"Objective Value: {p.getObjVal()}")
print(f"x1 = {p.getSolution(x1)}")
print(f"x2 = {p.getSolution(x2)}")
else:
print(f"Solution Status: {p.getProbStatusString()}")