Skip to main content

Python API for AMPL

Project description

AMPLPY: Python API for AMPL

# Install Python API for AMPL
$ python -m pip install amplpy --upgrade

# Install solver modules (e.g., HiGHS, CBC, Gurobi)
$ python -m amplpy.modules install highs cbc gurobi

# Activate your license (e.g., free https://ampl.com/ce license)
$ python -m amplpy.modules activate <license-uuid>

# Import in Python
$ python
>>> from amplpy import AMPL
>>> ampl = AMPL() # instantiate AMPL object
# Minimal example:
from amplpy import AMPL
import pandas as pd
ampl = AMPL()
ampl.eval(r"""
    set A ordered;
    param S{A, A};
    param lb default 0;
    param ub default 1;
    var w{A} >= lb <= ub;
    minimize portfolio_variance:
        sum {i in A, j in A} w[i] * S[i, j] * w[j];
    s.t. portfolio_weights:
        sum {i in A} w[i] = 1;
""")
tickers, cov_matrix = # ... pre-process data in Python
ampl.set["A"] = tickers
ampl.param["S"] = pd.DataFrame(cov_matrix, index=tickers, columns=tickers)
ampl.solve(solver="gurobi", gurobi_options="outlev=1")
assert ampl.solve_result == "solved"
sigma = ampl.get_value("sqrt(sum {i in A, j in A} w[i] * S[i, j] * w[j])")
print(f"Volatility: {sigma*100:.1f}%")
# ... post-process solution in Python

[Documentation] [AMPL Modules for Python] [Available on Google Colab] [AMPL Community Edition]

amplpy is an interface that allows developers to access the features of AMPL from within Python. For a quick introduction to AMPL see Quick Introduction to AMPL.

In the same way that AMPL’s syntax matches naturally the mathematical description of the model, the input and output data matches naturally Python lists, sets, dictionaries, pandas and numpy objects.

All model generation and solver interaction is handled directly by AMPL, which leads to great stability and speed; the library just acts as an intermediary, and the added overhead (in terms of memory and CPU usage) depends mostly on how much data is sent and read back from AMPL, the size of the expanded model as such is irrelevant.

With amplpy you can model and solve large scale optimization problems in Python with the performance of heavily optimized C code without losing model readability. The same model can be deployed on applications built on different languages by just switching the API used.

Documentation

Repositories:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amplpy-0.13.1b0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distributions

amplpy-0.13.1b0-cp312-cp312-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.12 Windows x86-64

amplpy-0.13.1b0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

amplpy-0.13.1b0-cp311-cp311-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

amplpy-0.13.1b0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

amplpy-0.13.1b0-cp310-cp310-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

amplpy-0.13.1b0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

amplpy-0.13.1b0-cp39-cp39-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

amplpy-0.13.1b0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

amplpy-0.13.1b0-cp38-cp38-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.8 Windows x86-64

amplpy-0.13.1b0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

amplpy-0.13.1b0-cp37-cp37m-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.7m Windows x86-64

amplpy-0.13.1b0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

amplpy-0.13.1b0-cp36-cp36m-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.6m Windows x86-64

amplpy-0.13.1b0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

File details

Details for the file amplpy-0.13.1b0.tar.gz.

File metadata

  • Download URL: amplpy-0.13.1b0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0.tar.gz
Algorithm Hash digest
SHA256 97156e34afcfe2a358fd9030331edb24df5b8550f229f225a8cc84119a3c1f5f
MD5 21cfe53d9e649f3f712c9aa8edc59c65
BLAKE2b-256 788c412e696d0eaeea56bea0a3e499b62ab85639eb3015105f4ea3ee9e5726d3

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d26490cdaf4899d243be5cf1b369b2fae6e3eedd6e1f4136b8f5d18cd4715db8
MD5 2f5d1da0ac3d1b51b4bac68a73c8d7d9
BLAKE2b-256 99f636d50365cbe1de483a4ee26536dbd297a5cd646c4fe7af841787c4961777

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.7 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19fce5a02ab429cdcbfb163050f78fae318daa0725833f0a76adb21bc9c86107
MD5 019280c09a386795c4b9b5773c089233
BLAKE2b-256 32da79e6e557940c87a1df455366f4d3b76e8524ebfebcbadaf928799a30e8e9

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6a80a36eeb1a6f1bc476f89dd471d4f699c8ae4e7e96de89c8d88044b0c400d7
MD5 4a06bae16455cf40442d1e2ee1bd229e
BLAKE2b-256 bf6552b8780b93c11abaefe26d0eb30784c1633a76fd9cce1ce9590e1b537f09

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.7 MB
  • Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8920730259ee9969a338dc2f9324e5d3ca56928ce417629bcd6c3220c6fc6227
MD5 c8e37fd127a7c8dcc776bf65e9fddcb2
BLAKE2b-256 c7efedbec44de1cd31d86240d71e4d61a5a3a6668d4a83b92605076750f8a486

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7472f1cdb0f7b6a959706d1980484ce01c208656c83c3a5fd5568424c01f820e
MD5 03889256ce62b0aa1d8cbcb275e0e222
BLAKE2b-256 3bedb304aca5e03f4e67c809e2dc65e6c5c05494776abeaf9a35029d2734d7d6

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c38341080d4a8ec7c18974a15b7b7dbc4effd2eb8b5b9760cff3f50968f5e6d
MD5 ff64dcd20fa804228f6499eb96e3c145
BLAKE2b-256 b1582ad28d013a236e8f6c986a8bad582ad12c8ee0f7f7da8db26327725c204e

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a4bfffffefd1e945735fb96e9b516e05411afabd28e2034942f3bc08223b1511
MD5 54a7e2a0f21b2f91b1de61c6dd3f5c9a
BLAKE2b-256 be382413a5305b970f11cc38a9a181b46a68ecd3ae67b69d94ad86cca2d8ec4a

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6233fc8999d42ca881cfa9eb75c09aff8bfdcf28ea280a921a31f65df9db50f7
MD5 3beffe97efe3b8a34eec7a864cfa311b
BLAKE2b-256 474abe6697fd5c9c2fb92dcb04d37db9773270d8a49a490e7060efa6ddda409c

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ae544952eed53ae66812ff1f980ec6b291616cffe64f6fedfd94552798294e95
MD5 d088884ce395c2d0f1ec9baebb9bff75
BLAKE2b-256 a61c944fb2815b848de3a37591d8709fbc487ef52a38f43765bbe7bc06d529ac

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69904d87de07a0a288000fd64d8459ff7930911e73c90371fbb76175b8c377ff
MD5 4bf86888cecf60cd894d776aad6dcb09
BLAKE2b-256 fe28ab0fb2c7147319e1e7032bd9eb86de8b07eccd38182bfb907f67bf7e5a85

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 337802ffdadc52dbc4cd834ae5a5c4cc2ad9ece3457abb3eeafae9692e96f6a2
MD5 f1714bf0ce0cd0eb17af84bd0767fc54
BLAKE2b-256 743113d3a91aee12419c6e34ef958789d56a81e2ef720e09a39513cdaaa8f80e

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 23799de3a8a5380ab1a5770722bd3cab5229f988ebdd93bec2883c0a9c8e5643
MD5 96a4f9348d977557d068e69c73bb43d2
BLAKE2b-256 95553c86c016ccc547264de1a4defadfd5cd77aab2918856afe3c56e0b9cb1ea

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b27f5826d3f3bb0dca4c0642e583edeba46a46750875e95376e405f14cfeede7
MD5 fa8b62280aa825463fad386d33a72c67
BLAKE2b-256 39635efb19d5a0348cb1fabff65d325903c9c6a1903fd9411e0aee4fdc08f7a3

See more details on using hashes here.

File details

Details for the file amplpy-0.13.1b0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: amplpy-0.13.1b0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.9.1 urllib3/1.26.14 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

File hashes

Hashes for amplpy-0.13.1b0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ceaf5949585f74d6fdb0ae4233ea2559b1bc73e8bf4b0cf4268a0441c853e815
MD5 b90660acf09515364f3da89630fc8a24
BLAKE2b-256 a4423a0e4d2c969f10dc4e71888922f11cb7b65d3280c32715d17c5728b7765b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page