## Python Optimization Package

git clone git://github.com/APMonitor/apm_python

The APMonitor package is also available through the package manager **pip** in Python.

python pip install APMonitor

Another method to obtain APMonitor is to include the following code snippet at the beginning of a Python script. If APMonitor is not available, it will use the pip module to install it.

try: from APMonitor import * except: # Automatically install APMonitor import pip pip.main(['install','APMonitor']) from APMonitor import *

### Download APM Python Library and Example Problems

The latest APM Python libraries are attached below. Functionality has been tested with Python 2.7 and 3.5. Example applications that use the apm.py library are listed further down on this page.

The development roadmap for this and other libraries are detailed in the release notes. The zipped archive contains the APM Python library **apm.py** and a number of example problems in separate folders. Descriptions of the example problems are provided below.

### Example_hs071: Nonlinear Programming with Python

$$ \min x_1 x_4 (x_1 + x_2 + x_3) + x_3 $$

$$ \mathrm{subject\;to} \quad x_1 x_2 x_3 x_4 \ge 25$$

$$\quad x_1^2 + x_2^2 + x_3^2 + x_4^2 = 40$$

$$\quad 1 \le x_1, x_2, x_3, x_4 \le 5$$

$$\quad x_0 = (1,5,5,1)$$

- Solve this optimization problem from a web-browser interface or download the Python source above. The Python files are contained in folder
*example_hs71*.

### Example_nlc: Nonlinear Control with Python

### Example_tank_mhe/nlc: Nonlinear Estimation and Control with Python

In this case study, a gravity drained tank was operated to generate data. A dynamic model of the process was derived from a material balance. This material balance is displayed below, along with a diagram of the system.

The the unknown parameters *c1* and *c2* need to be determined. The parameter *c1* is the flow into the tank when the valve is fully open. The parameter *c2* is the relationship between the volume of water in the tank and the outlet flow. This model is nonlinear because the outlet flow depends on the square root of the liquid volume. Nonlinear estimation is a technique to determine parameters based on the measurements. The script in **example_tank_mhe** uses the process data and the nonlinear model to determine the optimal parameters *c1* and *c2*.

After an accurate model of the process is obtained, the model can be used in a Nonlinear Control (NLC) application. A PID controller is compared to the NLC response in the folder **example_tank_nlc**.

### Other Applications with Python

- APM IPython Notebook Example on GitHub
- Diabetic Blood Glucose Control
- Distillation Column
- Stirred Reactor