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

Octeract Neural with Pyomo on Windows

Step 1: Make sure Python and Pyomo are installed

If Python is not installed, go to https://www.python.org/downloads and download the Python installer and install Python 3.8+.

If Pyomo is not installed, do:

python -m pip install pyomo


py -m pip install pyomo

If you encounter issues, 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 “octeract-neural.exe” from the zip package to a directory of your choice. Next, add that directory to your Windows PATH so that Pyomo will be able to find the binary.

To add a Windows binary to the PATH so that Pyomo can discover it, follow these steps:

  1. Locate the directory containing the binary you want to add to the PATH.
  2. Press Win + S, type env and select “Edit the system environment variables” or “Edit environment variables for your account”.
  3. In the System Properties window, click on “Environment Variables”.
  4. In the Environment Variables window, scroll under “System variables” (for all users) or “User variables” (for the current user only) to find the Path variable. Select it and click on “Edit”.
  5. In the Edit Environment Variable window, click “New” and paste the full path to the directory that contains the binary you want to add.
  6. Click “OK” on all windows to close them.
  7. Restart any command prompt or application where you intend to use Pyomo to ensure the new PATH is recognized.

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.