FAQs

What is AMPL?

  1. AMPL is a modelling language for describing production, distribution, blending, scheduling and many other kinds of problems known generally as large-scale optimization or mathematical programming.

  2. AMPL’s familiar algebraic notation and interactive command environment are designed to help formulate models, communicate with a wide variety of solvers (e.g., Gurobi, CPLEX, etc.), and examine solutions. AMPL connects to most open-source and commercial solvers and allows you to switch easily between them.

  3. AMPL has APIs for several popular programming languages (e.g., Python, R, etc.) and it allows you to only model once in AMPL and interact with it using an API for a language you are familiar with, and possibly deploy to a completely different language with minimal effort since the model remains the same.

  4. You can use AMPL for free and forever with open-source solvers with a Community Edition License including for commercial purposes. You can also start 30-day trials for individual commercial solvers. We also offer a few other free licenses for you to start for free now.

How to install AMPL?

After downloading your AMPL & Solvers bundle from the AMPL Portal, please follow the instructions below that correspond to your operating system:

How do cloud licenses work?

Instead of using long term licenses that require static hardware we use short-term leases which give the flexibility of moving the license between different machines or containers.

These leases are stored in a ampl.lic file that is replaced every time the lease is renewed. Each lease lasts 5 minutes and it is automatically renewed.

In order to renew a lease, the current license file and a fingerprint are sent to one of our REST API endpoints hosted across multiple cloud providers such as AWS and Azure.

If everything is ok with the request, a new lease is returned in the response and AMPL.lic file is replaced. There is no automatic enforcement of license limits as we just log the renewal.

Even though this mechanism was designed with Docker containers in mind, it also works natively on Windows and macOS virtual and physical machines too. The only requirement is an internet connection.

Which information is collected?

The fingerprint information sent in each request includes among other details the following:

  • number of CPU cores on the underlying machine

  • number of CPU threads available (e.g., Docker containers may be running restricted to a subset of CPU threads)

With the information obtained in the fingerprint we are able to count for any given moment:

  • Total number of concurrent active leases

  • Total number of CPU threads available across all concurrent active leases

  • Total number of different underlying machines with concurrent active leases

  • Total number of CPU cores across all machines with concurrent active leases

What happens if the limits are exceeded?

If a license is exceeding its limitations for long periods of time users are then contacted to figure out what happened and eventually upgrade the license limits to the customer needs. Since we just log the lease request and each lease lasts 5 minutes, exceeding license limits for short-periods of time is expected for instance when containers are being created and destroyed quickly.

How to check the status of AMPL cloud services?

You can check the status of AMPL cloud services at https://status.ampl.com/.

How to use AMPL with Docker containers?

We do not provide a base docker image as we give the user total freedom about which base image to use. In this example, we use the image python:3.9-slim-bullseye as base image. We then use curl and tar for downloading and installing some modules that you may need.

In the Dockefile below, we install the complete bundle with AMPL and all modules. This is the easiest approach if you are not concerned about image size or if you want to try all solvers we provide. We also install amplpy so that the Python API for AMPL is also ready to be used.

# Use any image as base image
FROM python:3.9-slim-bullseye
# Install curl in order to download the modules necessary
RUN apt-get update && apt-get install -y curl

# Install full bundle (includes AMPL and all solvers)
RUN cd /opt/ && curl -OL https://ampl.com/dl/amplce/ampl.linux64.tgz && \
    tar oxzvf ampl.linux64.tgz && rm ampl.linux64.tgz

# Add installation directory to the environment variable PATH
ENV PATH="/opt/ampl.linux-intel64/:${PATH}"

# Install amplpy
RUN pip3 install amplpy --no-cache-dir

In the Dockerfile example below, we install the modules for AMPL, Gurobi, COPT, COIN-OR solvers, and HiGHS. This is the recommended approach if image size is something is you concerned about.

# Use any image as base image
FROM python:3.9-slim-bullseye
# Install curl in order to download the modules necessary
RUN apt-get update && apt-get install -y curl

# Install individual modules (alternative to installing the full bundle)
ARG MODULES_URL=https://ampl.com/dl/modules
# Download ampl-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/ampl-module.linux64.tgz && \
    tar oxzvf ampl-module.linux64.tgz && rm ampl-module.linux64.tgz
# Download gurobi-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/gurobi-module.linux64.tgz && \
    tar oxzvf gurobi-module.linux64.tgz && rm gurobi-module.linux64.tgz
# Download copt-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/copt-module.linux64.tgz && \
    tar oxzvf copt-module.linux64.tgz && rm copt-module.linux64.tgz
# Download coin-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/coin-module.linux64.tgz && \
    tar oxzvf coin-module.linux64.tgz && rm coin-module.linux64.tgz
# Download highs-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/highs-module.linux64.tgz && \
    tar oxzvf highs-module.linux64.tgz && rm highs-module.linux64.tgz

# Add installation directory to the environment variable PATH
ENV PATH="/opt/ampl.linux-intel64/:${PATH}"

# Install amplpy
RUN pip3 install amplpy --no-cache-dir

When running the container you need to set the environment variable AMPLKEY_UUID with the license UUID of your cloud license (or AMPL CE license), and then run amplkey activate before starting any AMPL session. Alternatively, you can invoke amplkey activate --uuid xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx.

In order to make the Docker image smaller, you may want to do a multi-stage build so that you can just copy the ampl.linux-intel64 directory from the first stage. You can do that as follows:

# Use any image as base image
FROM python:3.9-slim-bullseye
# Install curl in order to download the modules necessary
RUN apt-get update && apt-get install -y curl

# Install individual modules (alternative to installing the full bundle)
ARG MODULES_URL=https://ampl.com/dl/modules
# Download ampl-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/ampl-module.linux64.tgz && \
    tar oxzvf ampl-module.linux64.tgz && rm ampl-module.linux64.tgz
# Download gurobi-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/gurobi-module.linux64.tgz && \
    tar oxzvf gurobi-module.linux64.tgz && rm gurobi-module.linux64.tgz
# Download copt-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/copt-module.linux64.tgz && \
    tar oxzvf copt-module.linux64.tgz && rm copt-module.linux64.tgz
# Download coin-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/coin-module.linux64.tgz && \
    tar oxzvf coin-module.linux64.tgz && rm coin-module.linux64.tgz
# Download highs-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/highs-module.linux64.tgz && \
    tar oxzvf highs-module.linux64.tgz && rm highs-module.linux64.tgz

# Start a second stage copying just ampl.linux-intel64
FROM python:3.9-slim-bullseye
COPY --from=0 /opt/ampl.linux-intel64 /opt/ampl.linux-intel64

# Add installation directory to the environment variable PATH
ENV PATH="/opt/ampl.linux-intel64/:${PATH}"

# Install amplpy
RUN pip3 install amplpy --no-cache-dir

In case you want to use non-root containers, you need to set the environment variables AMPLKEY_RUNTIME_DIR with a path to a temporary location where amplkey temporary files should be written to, and AMPL_LICFILE with the location where the short-term licenses will be stored. This is necessary if the non-root user can’t write to /opt/ampl.linux-intel64.

# Use any image as base image
FROM python:3.9-slim-bullseye
# Install curl in order to download the modules necessary
RUN apt-get update && apt-get install -y curl

# Install individual modules (alternative to installing the full bundle)
ARG MODULES_URL=https://ampl.com/dl/modules
# Download ampl-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/ampl-module.linux64.tgz && \
    tar oxzvf ampl-module.linux64.tgz && rm ampl-module.linux64.tgz
# Download gurobi-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/gurobi-module.linux64.tgz && \
    tar oxzvf gurobi-module.linux64.tgz && rm gurobi-module.linux64.tgz
# Download copt-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/copt-module.linux64.tgz && \
    tar oxzvf copt-module.linux64.tgz && rm copt-module.linux64.tgz
# Download coin-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/coin-module.linux64.tgz && \
    tar oxzvf coin-module.linux64.tgz && rm coin-module.linux64.tgz
# Download highs-module.linux64.tgz
RUN cd /opt/ && curl -OL ${MODULES_URL}/highs-module.linux64.tgz && \
    tar oxzvf highs-module.linux64.tgz && rm highs-module.linux64.tgz

# Start a second stage copying just ampl.linux-intel64
FROM python:3.9-slim-bullseye
COPY --from=0 /opt/ampl.linux-intel64 /opt/ampl.linux-intel64

# Add installation directory to the environment variable PATH
ENV PATH="/opt/ampl.linux-intel64/:${PATH}"

# Install amplpy
RUN pip3 install amplpy --no-cache-dir

# Add non-root user (optional)
ARG USERNAME=guest
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
# Change to non-root privilege
USER ${USERNAME}

# Environment variables for amplkey (necessary if the non-root user can't write to /opt/ampl.linux-intel64)
ENV AMPLKEY_RUNTIME_DIR /tmp/ampl/
ENV AMPL_LICFILE /tmp/ampl/ampl.lic

You can build this image with docker build . --tag ampl-container and you can run it as follows:

$ docker run --rm -it -e AMPLKEY_UUID=xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx ampl-container bash
[email protected]:/$ amplkey activate
2022/05/12 14:42:08 Wrote 958 bytes to /tmp/ampl/ampl.lic
[email protected]:/$ ampl
ampl: option version;
option version 'AMPL Version 20220505 (Linux-5.4.0-1077-azure, 64-bit)\
Licensed to Trial amplkey licgen.\
Temporary license expires 20220531.\
Using license file "/tmp/ampl/ampl.lic".\
';
ampl: quit;
[email protected]:/$ python
Python 3.9.12 (main, May 11 2022, 08:03:15)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from amplpy import AMPL
>>> ampl = AMPL()
>>> ampl.eval('option version;')
option version 'AMPL Version 20220505 (Linux-5.4.0-1077-azure, 64-bit)\
Licensed to Trial amplkey licgen.\
Temporary license expires 20220531.\
Using license file "/tmp/ampl/ampl.lic".\
';
>>>

How to add AMPL installation directory to PATH/Path?

Windows

On Windows, you can add the path to AMPL installation directory (e.g., "C:\ampl.mswin64\") to the environment variable Path as described in https://www.computerhope.com/issues/ch000549.htm.

Linux

On Linux, you can add the path to AMPL installation directory (e.g., "/opt/ampl.linux-intel64/") to the environment variable PATH with:

export PATH="/complete/path/to/ampl.linux-intel64/":$PATH

You can add this line to ~/.profile or ~/.bashrc.

macOS

On macOS, you can add the path to AMPL installation directory (e.g., "/Users/username/bin/ampl.macos64/") to the environment variable PATH with:

export PATH="/complete/path/to/ampl.macos64/":$PATH

You can add this line to ~/.zshrc.

Python

On any python script you can add the path to AMPL installation directory to the environment variable PATH/Path as follows:

import os
os.environ["PATH"] += os.pathsep + "/complete/path/to/ampl/installation/directory/"

Note: on Windows you should replace "PATH" by "Path".

Other help resources