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:
- GitHub Repository: https://github.com/ampl/amplpy
- PyPI Repository: https://pypi.python.org/pypi/amplpy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for amplpy-0.14.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac297e8db2a5a0ae1201906d25bedf57f407608aeb42956694585d2cfa8b8008 |
|
MD5 | 4b82722c997d1d61a3244aa5f5b6d82a |
|
BLAKE2b-256 | 825a039c98bf0d42fcd7d8c8bfc09f71e1d5850380fea16a3071a3b71c6bc712 |
Hashes for amplpy-0.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66866182f783137a74384a652854fc78593222a3d980a28647f6cc714cd6f8d0 |
|
MD5 | 5896f2555379b378d160581e59176a95 |
|
BLAKE2b-256 | 4049859202a03c2ddab7a7cb433aa546c787a879efb0664654b767269452e131 |
Hashes for amplpy-0.14.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b96fa1d4aa4e0c5f3ca18457e9be6edb4e6b1b0cd2c77fd527fc3efe7f5a1499 |
|
MD5 | a58f3b2e1d3f600ec57182b071c1393d |
|
BLAKE2b-256 | 10faa9d2629635e77b9c43ede28d8f812605066cc1d858e2130feefb7c3457aa |
Hashes for amplpy-0.14.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cfbf7163b6f3bed88504a6aae358d28aa2045a763dd5e5ebd626728f4107ae3 |
|
MD5 | 1bb9cc0de7e1a430b34de7fe63f26094 |
|
BLAKE2b-256 | b0f8aa91435fce2e3f7c404b3f570de01e9114409adc95f8796d8d81086aa8a9 |
Hashes for amplpy-0.14.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d3c8bf0132165d573146be3c3fe1f51c5fb20e2a28f5c9fa524abb7e7c9bf75 |
|
MD5 | 102d1a3e2ac877bfccdd9e6266962902 |
|
BLAKE2b-256 | af604d7df4a6a2e78bb592293c8bb64715bff3f2d76966e28653581d3bfb9755 |
Hashes for amplpy-0.14.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70b4f44d25c99728559aeafb20004d22e0be92519b4de35bc8231305db18629a |
|
MD5 | 5a695ae5002cfa783da6044f938addfe |
|
BLAKE2b-256 | 2685528fad54ea5ac42beb7349398f9cb0a30b8aef0aa9aa23371a3c6849a720 |
Hashes for amplpy-0.14.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c86b6208d276bd891b4e3a83ce5d08a840be449079f649f68ecf10ff3e774e7 |
|
MD5 | a04c4cd876ff0d0d3e288d23f4991c78 |
|
BLAKE2b-256 | a7d4b77934f59ecd230b75265e75de0177e531d0a95ef810635c956e3427e3e1 |
Hashes for amplpy-0.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08c10f97eae88e0d0c2eb5ffbfba7a73fb94593e8511bb4872ab30a9df94d4ca |
|
MD5 | 1770111778f8d7ada7cf6c293eee343a |
|
BLAKE2b-256 | 6c6c3642b1096bf2849e77e9cb45398ec6bd3715fec04a1a6dbfe06819c5d3a4 |
Hashes for amplpy-0.14.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4e5c31dfd2882ea1130c249767c4880918d5f0171836dce0a23907eed982705 |
|
MD5 | c1b43e6d661f48cb180b548178e49f01 |
|
BLAKE2b-256 | fa4ed554c69933698f5468eb8b427e7c9f4a33a33757a962b9d1b3cd762ab2e6 |
Hashes for amplpy-0.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 260bb4529700ed8a9f25e9f07ad8cd12b04790b536ec7cd7adefa71ab8cb3358 |
|
MD5 | c7c3b8263c0c5ccfe05187c942c394a1 |
|
BLAKE2b-256 | 461aeafb33f061dd7c0da9f2628921a7abec86e9e0f9c160151b24949be78c6c |
Hashes for amplpy-0.14.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f2f3d71e1386910aee9c1727810f12a0b331b5dfded8a27e917077ce78d3c4b |
|
MD5 | 685ae32170fe1df5537c7a3831b2cbd4 |
|
BLAKE2b-256 | 1a026963a83a76b87e97058214e359d7fd966bb2eb7937827b067247ab986831 |
Hashes for amplpy-0.14.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db841021615a2758ace59c2e2a1c3a8a9ae4dbd079acd3841aa7aef10a60794a |
|
MD5 | bfa0a4c283b192c32d17a100ad943278 |
|
BLAKE2b-256 | 038fed6ab8f659416cff687ab616b8e5f8abfef9f11a8d954743ff748eb8c920 |
Hashes for amplpy-0.14.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2fc7c7e4ff52f6d4f22f42f6c407c75b221a99bb7ad6037f11dc6a450617855 |
|
MD5 | 04db87e28fadc73f522cadaca7f441d3 |
|
BLAKE2b-256 | 3cd956498c0c64ef07f24d2fe58903131b452a1109990b797738f07c4b9c0209 |
Hashes for amplpy-0.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 064de60556349c5b8c2cca4549099721814b0305510eb4cdd686f0c03abeac48 |
|
MD5 | 01b21208aa2172ae5b86f556ed8e30f2 |
|
BLAKE2b-256 | a89b6975081a23b6a4f279e0055fb8725f701d028086e0e4f4ee9c1ed7415a5b |
Hashes for amplpy-0.14.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da89ec3224c1e4ca6f128d89c2530908dcd1c41ab895e12f883ee2a1f9853610 |
|
MD5 | 31649b67ae14aa6ef36dafe5f40b9661 |
|
BLAKE2b-256 | 108ecb16fe1e363246ad0555cf277f63f7e5b885a5a62746ded9c085cb1a3f31 |
Hashes for amplpy-0.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07ecc2d50644cfc60df6b47f32fef0445c569d5869a1f8a3d68577d0a509d5d7 |
|
MD5 | 2d66289fc80e2bb2fd98705037a4354f |
|
BLAKE2b-256 | 0fa201014d0470071353c6b0f97c76169643039284fafb31b26c8c6615ad78ab |
Hashes for amplpy-0.14.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3f46e90cee84503743bd2bdecc2b71251df97d33e7967bfd8cd757b317d30c1 |
|
MD5 | b19332f9dbed28b756d65e7d39360c16 |
|
BLAKE2b-256 | 7ad89ae7cb9b55782378209b4467a39201e2d2779e3c8715573806deb82532ec |
Hashes for amplpy-0.14.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6918733db7361de8f4d987eb009fe98da5626370321181184dd20226acc7f5b7 |
|
MD5 | 488648a953db4cf649f73afff8e57b81 |
|
BLAKE2b-256 | 76393e40f932289bbcaa5965e42b2405c2b7b02a528060b15e08cd7a0797c1a8 |
Hashes for amplpy-0.14.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 086d96c73e4b6bee18cb809052c1e80d7b933b32d38a369ee9a945b328ed1141 |
|
MD5 | de9ec469a1903979a125a050a07d6006 |
|
BLAKE2b-256 | 969f18c46464ace0d1c19d5df1d86054e2f5c5e357408bc0e9bb5771c8ee9de3 |
Hashes for amplpy-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e774c8edecd43986992772ab30942d4c2f0d0a8bdea546fff9d193790e2abae |
|
MD5 | 3e93c3643e2046a4c272b713716f7f43 |
|
BLAKE2b-256 | 8d267179c6a6e9f0ef3445d439ad740d8c12c4d954fda7ce6cc750cddd55d557 |
Hashes for amplpy-0.14.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 932aa3e9737c048a85fc5afb1d9c547234aa88faed39951fc96b37c8f17ee1d4 |
|
MD5 | 7fd47ee2409edbea3388dc1495ce8799 |
|
BLAKE2b-256 | 6b13e90f0a43c862a4707878daa0f4b7ad6bd2d588fac959dad6865601b7559f |
Hashes for amplpy-0.14.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24b12a808dcb2fca09ffafa58d8c66c9ec0597fa793580c81ea9b4a8c4321190 |
|
MD5 | 0d1b2f86569a1db4063f14ef0ce03104 |
|
BLAKE2b-256 | 8576ca37425425477ef900c599b5606f1000ad98c9a786b376c86d0abec0bae2 |
Hashes for amplpy-0.14.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 887ba40fea2931d5bd74f1928af4f4f5669652083fea1615d695ae7980319eaa |
|
MD5 | 10dff4f42a81c25657ae4f9a95af5f43 |
|
BLAKE2b-256 | e3c5dff9d109309cf961a3258f05f01e068193fea1a8c0e67fc60830cf6d9b20 |
Hashes for amplpy-0.14.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f58adcb120abcc2697655f86f756fc89dabd4a9ebaef95377fe1240645dd98 |
|
MD5 | cd294efceba2bc5f96f167e93fe9d8d6 |
|
BLAKE2b-256 | dae873ae89a52e1add15b55bdb4759faec1a62a88b7a13dbc1bef3340821ab99 |
Hashes for amplpy-0.14.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 184209e6fb494da3b8834817a10ab010ee86cab0a28a4fade9aba41f8a3bf004 |
|
MD5 | e9f8c9f27e310ae6484fae767d868f95 |
|
BLAKE2b-256 | fc2181b2b954bd95ffeefe71fbadb699b0f7d7284905eed0907558976cd59773 |
Hashes for amplpy-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22fb366851eeb599469a92b00f6c254ed26ac64fa78c31805b6896ad787e11d6 |
|
MD5 | f81891ffa24631068a0f88dd9b9ab65c |
|
BLAKE2b-256 | 0320f41d43b40b4829a49ab5d8b0832bc3b4b832dad1faf7ce2666d9be056ed7 |
Hashes for amplpy-0.14.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c45a617a7b2f3985a875b47efe65dc63d55c3caa5ece5c2b32cbcafd8f9f866a |
|
MD5 | d696699faf39ab995d991e0c4c27f526 |
|
BLAKE2b-256 | 75116e71f38d04544b92b5a43045495db858cee8041556b8434ce8929463de71 |
Hashes for amplpy-0.14.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c985e41614f4e6fd47764d047d407a7d7ee89323ec38b2b88724a1cd203bc0d7 |
|
MD5 | 994664a64e8c2d1a1049b9e65cb1b09d |
|
BLAKE2b-256 | 27a861e5b2146cff03a90b45093add9cf5aa2b0da6d6c4817a291ded8d67dbc0 |
Hashes for amplpy-0.14.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec98409495649014b2936b0cb1822338d52dab67cdccf157c35d8b864a06ec35 |
|
MD5 | 672c108621b1f3b697fad156ff802397 |
|
BLAKE2b-256 | 72fe9728bbed3689a84b9e33561d25df6e58e74563057e2676b035dbffe89f06 |
Hashes for amplpy-0.14.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29aead2df7443b5170dee4cb75041f881b3513f07a54be9d3a5edf43afeef316 |
|
MD5 | 35feca5a05929270aac0e01a19730eef |
|
BLAKE2b-256 | de673d661264444a6f1654c9152bc8b97960080bd05402663dec43c84e8bb0cb |
Hashes for amplpy-0.14.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab01cd6b1995256577ad958b1452071a8b3940b7610f4d5c5aa2075562141ce9 |
|
MD5 | 43fc21d4c5b0dbb146d843896a9e0346 |
|
BLAKE2b-256 | 93eb14e88b754989746ec32f20e2d12f3b8e9f5e64dd365c871701a3eb9f89b4 |
Hashes for amplpy-0.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f993718a74e16b248747a20da9b34b4eb119b1f3e0d299381110d0cee626ac9 |
|
MD5 | 113014df4f6f73ecd391a0c41ea8618c |
|
BLAKE2b-256 | 5311d6e55b1a56d7592c7bc9fe826c0023a1723e21951aa3f658f744c0e2489d |
Hashes for amplpy-0.14.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a42bbd916d9cdcad04c28f05bc242f42fd9da2c42c4bdacb00d6cc269ce0f9d6 |
|
MD5 | ac30fe6ccef8ae9db25f769cd9015ad6 |
|
BLAKE2b-256 | 6f64fbae12cc068cd75c3403513be0c8d1a173d0de786ce0e9f8652e3846661e |
Hashes for amplpy-0.14.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bf80d89436bff565c6704048501071dad34b5585291517eceecf672857b3fe3 |
|
MD5 | bd62135f474b25d8204209d91b20839a |
|
BLAKE2b-256 | c86a83b9142e81d5fa65ca756d3ffe51b33d2381c5998a673e7a5f14c4674f44 |
Hashes for amplpy-0.14.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df53f5febc7fb6757cbd45407beee67df3348b92876c3d09e54cd2e72be4b6c9 |
|
MD5 | 0301667eaef2c47e453fa5bd50416ad6 |
|
BLAKE2b-256 | 55b618cee8c5258db522204b11a0fd17a6a6c5bd5b450114ef8eaec29cd246df |
Hashes for amplpy-0.14.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c41a7c5995b2fd071ecc88723b251462696b87a9ce22914244e0708b654dbcb |
|
MD5 | beb50848f54b0f7bfddb248ce61ff2d9 |
|
BLAKE2b-256 | 5874bd0c6e48e6cb179b300a685d9e6d3b0e422ef95c7c33472bfe4815abb255 |
Hashes for amplpy-0.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9efc546c32d44394e625a577bc7b53b39a67593854617e7dab86aba6e95d34c |
|
MD5 | d09e9c24154b1da15a722f434992495c |
|
BLAKE2b-256 | 158b5959c546897cbdc89b77ba3a3d56c96ff69651d315d579be0e5b6ca1264f |
Hashes for amplpy-0.14.0-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8825cf10fb5cc4c513e310980209847681ddf6154ac8dd4b1d76df8a52123bb |
|
MD5 | d49f73a78af14f7f8556534f40909590 |
|
BLAKE2b-256 | 99c8a7ccd64a89b8c5766f5f26c4b285911de1bac144cc0c2fce5e35e3dfbdfe |
Hashes for amplpy-0.14.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 093196bed2a7cd8f0a5a88e6083857adae737ba846b679986d6ef2bc29164fa2 |
|
MD5 | 833c916c21c48e18116a40f901591550 |
|
BLAKE2b-256 | 616db6c3b109a6223c2f442d2bff248946653dfabf2a064935ace3deda26634e |
Hashes for amplpy-0.14.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6854a05b720c32aa7347c4348350a6cb76f32e8a65e4e74a77622a2a552b2325 |
|
MD5 | 87664cf0187f55d945b005fda6e6db02 |
|
BLAKE2b-256 | 744fc520c9fec81c205bdfafaf84ee8831bf42bbe29e58e02282fc062a5695b5 |