Metadata-Version: 2.4 Name: amplpy Version: 0.17.0 Summary: Python API for AMPL Home-page: http://ampl.com/ Download-URL: https://github.com/ampl/amplpy Author: AMPL Optimization Inc. Author-email: devteam@ampl.com License: BSD-3 Platform: any Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Console Classifier: Topic :: Software Development Classifier: Topic :: Scientific/Engineering Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Science/Research Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: POSIX Classifier: Operating System :: Unix Classifier: Operating System :: MacOS Classifier: Operating System :: Microsoft :: Windows Classifier: Programming Language :: C Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: 3.14 Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta Classifier: Programming Language :: Python :: Implementation :: CPython Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: ampltools>=0.7.5 Dynamic: author Dynamic: author-email Dynamic: classifier Dynamic: description Dynamic: description-content-type Dynamic: download-url Dynamic: home-page Dynamic: license Dynamic: license-file Dynamic: platform Dynamic: requires-dist Dynamic: summary # AMPLPY: Python API for AMPL ```python # 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 # Import in Python $ python >>> from amplpy import AMPL >>> ampl = AMPL() # instantiate AMPL object ``` ```python # 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](https://amplpy.readthedocs.io/)] [[AMPL Modules for Python](https://dev.ampl.com/ampl/python/modules.html)] [[Available on Google Colab](https://colab.ampl.com/)] [[AMPL Community Edition](http://ampl.com/ce)] `amplpy` is an interface that allows developers to access the features of [AMPL](https://ampl.com) from within Python. For a quick introduction to AMPL see [Quick Introduction to AMPL](https://dev.ampl.com/ampl/introduction.html). 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 - http://amplpy.ampl.com ## Repositories: * GitHub Repository: https://github.com/ampl/amplpy * PyPI Repository: https://pypi.python.org/pypi/amplpy