1. Home
  2. Docs
  3. Tutorials
  4. Pyomo tutorial
  5. Pyomo on Linux

Pyomo on Linux

Step 1: Make sure Pyomo is installed

Type “pyomo” in your terminal. If it’s not installed, you can check the Pyomo installation guide for more details.

Step 2: Extract the package and add it to the PATH

Assuming you’ve already downloaded the Octeract Engine package, extract the tar file to a directory of your choice. Next, add that directory to your PATH.

To temporarily add a directory to your PATH for the current terminal session, use:

export PATH=$PATH:/path/to/dir

To permanently add a directory to your PATH for all future terminal sessions for a single user, add the export command to your .bashrc, .bash_profile, or .profile file in your home directory. For bash, you can add it to ~/.bashrc like this:

echo 'export PATH=$PATH:/path/to/dir' >> ~/.bashrc

And then reload the profile with:

source ~/.bashrc

Step 3: Create and solve your model

import os
from pyomo.environ import *

os.environ["octeract_options"] = "num_cores=4"

model = m = ConcreteModel()

x1 = m.x1 = Var(within=Reals, bounds=(0,1), initialize=1)
x2 = m.x2 = Var(within=Reals, bounds=(0,1), initialize=1)
x3 = m.x3 = Var(within=Reals, bounds=(0,1), initialize=None)
x4 = m.x4 = Var(within=Reals, bounds=(0,1), initialize=1)
x5 = m.x5 = Var(within=Reals, bounds=(0,1), initialize=None)

m.obj = Objective(sense=minimize, expr=42*x1 - 0.5*(100*x1*x1 + 100*x2*x2 + 100*x3*x3 + 100*x4*x4 + 100*x5*x5) + 44*x2 + 45*x3 + 47*x4 + 47.5*x5)
m.e2 = Constraint(expr=20*x1 + 12*x2 + 11*x3 + 7*x4 + 4*x5 <= 40)

results = SolverFactory("octeract-engine").solve(m, tee=True, keepfiles=False, load_solutions=False)


If you’d prefer to get creative, refer to the list of modeling components for Pyomo.