1. Home
  2. Docs
  3. Octeract Neural
  4. Pyomo
  5. Octeract Neural with Pyomo on Linux

Octeract Neural with 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 Neural client, extract the “octeract-neural” binary from the tar package 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: Retrieve your API key

In order for the Neural client to connect to our cloud you need to specify the API key associated with your user account. You can see your API key in your user area.

This key is unique to your account. Make sure to keep it safe and never share it with anyone.

Step 4: Create and solve your model

import os
from pyomo.environ import *

os.environ['OCTERACT_API_KEY'] = 'the_api_key_from_your_user_account'

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-neural").solve(m, tee=True)

print("Objective value: ", value(m.obj))

print("Variable values:")
for v in m.component_data_objects(Var):
  print(str(v), v.value)

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