Continuous Integration (CI/CD)¶
AMPL can be easily used in Continuous Integration/Continuous Delivery (CI/CD) platforms in order to test your optimization applications before deploying to production.
The most convenient way is by using the Python modules, even if your optimization application is built using another AMPL API. Since AMPL and all solvers are now available as Python Packages. It is only necessary to have a step which installs amplpy and the modules needed by your application:
python -m pip install amplpy
python -m amplpy.modules install <solver1> <solver2> # install the solvers you need
python -m amplpy.activate <license-uuid> # activate your license
In order to then be able to access AMPL and solvers when using AMPL APIs other than amplpy the only additional step is to add to the environment variable path the paths to the modules installed:
export PATH=$PATH:$(python -m amplpy.modules path)
Below we have examples for two popular CI/CD platforms: GitHub Actions and Azure Pipelines. The setup is very similar for others.
Note
Contact us at support@ampl.com for free support setting up AMPL in your CI/CD platform. You can also ask any questions you may have on our Support Forum.
GitHub Actions¶
Example configuration for GitHub Actions used in the example project amplpyfinance.
File ".github/workflows/test.yaml"
:
name: Test
run-name: ${{ github.actor }} is building "${{ github.ref_name }}"
on: [push]
jobs:
Test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
set -ex
python -m pip install -r requirements.txt
python -m pip install amplpy
python -m amplpy.modules install <solver1> <solver2>
python -m amplpy.activate <license-uuid>
- name: Install package
run: |
python -m pip install .
- name: Test package
run: |
python -m <package-name>.tests
Azure Pipelines¶
Example configuration for Azure Pipelines used in the example project amplpyfinance.
File "azure-pipelines.yml"
:
jobs:
- job: Test
pool: {vmImage: 'ubuntu-latest'}
strategy:
matrix:
Python 3.10:
PYTHON_VERSION: 3.10
steps:
- task: [email protected]
inputs:
versionSpec: $(PYTHON_VERSION)
- bash: python --version
displayName: Check python version
- bash: |
set -ex
python -m pip install -r requirements.txt
python -m pip install amplpy
python -m amplpy.modules install <solver1> <solver2>
python -m amplpy.activate <license-uuid>
displayName: Install dependencies
- bash: |
python -m pip install .
displayName: Install package
- bash: |
python -m <package-name>.tests
displayName: Test package