Skip to content

Commit

Permalink
new c-api
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgen-lentz committed Sep 29, 2024
1 parent fa747d4 commit 9bc061f
Show file tree
Hide file tree
Showing 39 changed files with 604 additions and 81 deletions.
2 changes: 1 addition & 1 deletion docs/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pydata-sphinx-theme==0.7.1
ampl-sphinx-theme
sphinx==4.2.0
sphinx==5.0.0
myst_parser>=0.17.0
4 changes: 2 additions & 2 deletions docs/source/reference/rcon_entitycpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Constraint
constraint is scalar, its values can be accessed via functions like
:meth:`~.Constraint.body` and :meth:`~.Constraint.dual`.
All the AMPL suffixes for constraints (see
https://www.ampl.com/NEW/suffbuiltin.html)
http://www.ampl.com/NEW/suffbuiltin.html)
are available through methods of this class with the same name (and methods
of ConstraintInstance for indexed constraints).

Expand All @@ -32,7 +32,7 @@ Constraint

Check if the constraint is a logical constraint. The available suffixes
differ between logical and non logical constraints. See
https://www.ampl.com/NEW/suffbuiltin.html for a list of the available
http://www.ampl.com/NEW/suffbuiltin.html for a list of the available
suffixes for algebraic constraints. The suffixes available for logical
constraints are marked on the method description by "Valid only for logical
constraints".
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/rcon_instancecpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ConstraintInstance
This class represent an instance of a constraint.

In general, all AMPL suffixes for a constraint are available through methods
with the same name in this class. See https://www.ampl.com/NEW/suffbuiltin.html
with the same name in this class. See http://www.ampl.com/NEW/suffbuiltin.html
for a list of the available suffixes.

Note that, since this class represents instances of both algebraic and logical
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/robj_entitycpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Objective
the properties (corresponding to AMPL suffixes) of the objective instance
can be accessed through methods like :meth:`~.Objective.value`.
The methods have the same name of the corresponding AMPL suffixes.
See https://www.ampl.com/NEW/suffbuiltin.html for a list of the available
See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available
suffixes.

All these methods throw an error if called on an entity which has been deleted
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/robj_instancecpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ObjectiveInstance
the properties (corresponding to AMPL suffixes) of the objective instance
can be accessed through methods like :meth:`~.ObjectiveInstance.value`.
The methods have the same name of the corresponding AMPL suffixes.
See https://www.ampl.com/NEW/suffbuiltin.html for a list of the available
See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available
suffixes.

All these methods throw an error if called on an entity which has been deleted
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/rvar_entitycpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Variable
variable, all the properties of the variable instance can be accessed
through methods like :meth:`~.Variable.value`. The methods have the
same name of the corresponding AMPL suffixes.
See https://www.ampl.com/NEW/suffbuiltin.html for a list of the available
See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available
suffixes.

All these methods throw an error if called on an entity which has been deleted
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/rvar_instancecpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ VariableInstance
of use when dealing with scalar variables.

All AMPL suffixes for an algebraic variable are available through methods with
the same name in this class. See https://www.ampl.com/NEW/suffbuiltin.html
the same name in this class. See http://www.ampl.com/NEW/suffbuiltin.html
for a list of the available suffixes.

All the accessors in this class throw an error if the instance
Expand Down
58 changes: 58 additions & 0 deletions rAMPL/.github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: build-and-test
run-name: ${{ github.actor }} is building "${{ github.ref_name }}"
on: [push]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- run: |
set -ex
python updatelib.py
bash build.sh
mkdir -p upload/{release,doc}
cp rAMPL_*.tar.gz upload/release/
cp rAMPL_*.tar.gz upload/release/rAMPL.tar.gz
cp -r docs/build/html upload/doc/R
- uses: actions/upload-artifact@v3
with:
name: drop
path: upload/

test:
needs: build
strategy:
matrix:
include:
- os: ubuntu-latest
bundle: https://portal.ampl.com/dl/amplce/ampl.linux64.tgz
- os: macos-latest
bundle: https://portal.ampl.com/dl/amplce/ampl.macos64.tgz
- os: windows-latest
bundle: https://portal.ampl.com/dl/amplce/ampl.mswin64.zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- uses: actions/download-artifact@v3
with:
name: drop
- name: Copy package
shell: bash
run: cp release/* .
- name: Install Rcpp and testthat
run: bash dependencies.sh
- name: Install package
run: bash install.sh
- name: Install AMPL
run: bash download-ampl.sh ${{ matrix.bundle }}
- name: Test package
shell: bash
run: SKIP_BIG_TESTS=1 PATH="`pwd`/ampl:$PATH" bash test.sh 2>&1
17 changes: 17 additions & 0 deletions rAMPL/.readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

version: 2

build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py

python:
install:
- requirements: docs/requirements.txt
15 changes: 15 additions & 0 deletions rAMPL/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Package: rAMPL
Title: AMPL API for R
Version: 2.0.12.0-20230210
Author: Filipe Brandao
Maintainer: Filipe Brandão <[email protected]>
Description: AMPL API for R.
Depends: R (>= 3.2.3)
License: BSD-3
Encoding: UTF-8
LinkingTo: Rcpp
Imports: Rcpp
RoxygenNote: 6.0.1
Suggests: testthat
NeedsCompilation: yes
Packaged: 2024-09-29 17:36:23 UTC; lentz
29 changes: 29 additions & 0 deletions rAMPL/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2020, AMPL Optimization inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions rAMPL/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
useDynLib(rAMPL)
exportPattern("^[^\\.]")
import(Rcpp)

53 changes: 53 additions & 0 deletions rAMPL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### rAMPL

[![Build Status](https://dev.azure.com/ampldev/rAMPL/_apis/build/status/ampl.rAMPL?branchName=master)](https://dev.azure.com/ampldev/rAMPL/_build/latest?definitionId=10&branchName=master) [![build-and-test](https://github.com/ampl/rAMPL/actions/workflows/build-and-test.yaml/badge.svg)](https://github.com/ampl/rAMPL/actions/workflows/build-and-test.yaml)

AMPL API is an interface that allows developers to access the features of the
AMPL interpreter from within a programming language. 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 read
back from AMPL, the size of the model as such is irrelevant. Functions for
directly assigning data to AMPL parameters and sets are provided, which can
be used instead of the normal AMPL data reading procedures. AMPL API has been
written with usability in mind, and it is easy to access its functionalities
from C++, Java, C#, MATLAB, Python, and R.

The AMPL API can function as an add-on to any existing AMPL installation. If
you do not yet have an AMPL installation on the computer where you will be
working with the API. Use our [Community Edition](http://ampl.com/ce)
to download a working version that can be installed quickly.

#### Documentation

- http://rAMPL.readthedocs.io

#### Setup

In order to install the latest version of the R API you just need to run:
```
> install.packages("Rcpp", type="source")
> install.packages("https://ampl.com/dl/API/rAMPL.tar.gz", repos=NULL)
```

Note: this package requires R development tools on Windows and macOS, which can be installed as follows:
* Windows: https://cran.r-project.org/bin/windows/Rtools/
* macOS: https://cran.r-project.org/bin/macosx/tools/
* On Linux, this package requires a C++ compiler such as g++.

Alternatively, you can download, build, and install the package locally:
```
$ git clone [email protected]:ampl/rAMPL.git
$ cd rAMPL
$ python updatelib.py
$ cd ..
$ R CMD build rAMPL
$ R CMD INSTALL rAMPL_<version>.tar.gz
```

#### License

BSD-3

***
Copyright © 2023 AMPL Optimization inc. All rights reserved.
97 changes: 97 additions & 0 deletions rAMPL/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
variables:
BUNDLES_URL: 'https://portal.ampl.com/dl/amplce/'
LINUX32_BUNDLE_NAME: 'ampl.linux32.tgz'
LINUX64_BUNDLE_NAME: 'ampl.linux64.tgz'
MACOS64_BUNDLE_NAME: 'ampl.macos64.tgz'
MSWIN64_BUNDLE_NAME: 'ampl.mswin64.zip'

stages:
- stage: build
displayName: 'Build'
jobs:
- job: macos
pool: {vmImage: 'macos-latest'}
steps:
- task: UsePythonVersion@0
- bash: |
set -ex
python updatelib.py
bash build.sh
mkdir -p upload/{macos,release,doc}
cp rAMPL_*.tar.gz upload/macos/
cp rAMPL_*.tar.gz upload/release/
cp rAMPL_*.tar.gz upload/release/rAMPL.tar.gz
cp -r docs/build/html upload/doc/R
displayName: Build package
- task: PublishBuildArtifacts@1
inputs: {artifactName: 'drop', pathtoPublish: 'upload'}

- stage: test
displayName: 'Test'
dependsOn: build
jobs:
- job: linux
pool: {vmImage: 'Ubuntu-20.04'}
variables: {AMPL_URL: '$(BUNDLES_URL)/$(LINUX64_BUNDLE_NAME)'}
steps:
- task: DownloadBuildArtifacts@0
inputs: {artifactName: 'drop', downloadPath: '.'}
- bash: cp drop/release/* .
displayName: Copy package
- bash: sudo bash dependencies.sh
displayName: Install Rcpp and testthat
- bash: sudo bash install.sh
displayName: Install package
- bash: bash download-ampl.sh $AMPL_URL
displayName: Install AMPL
- bash: sudo SKIP_BIG_TESTS=1 PATH="`pwd`/ampl:$PATH" bash test.sh
displayName: Test package
- job: macos
pool: {vmImage: 'macos-latest'}
variables: {AMPL_URL: '$(BUNDLES_URL)/$(MACOS64_BUNDLE_NAME)'}
steps:
- task: DownloadBuildArtifacts@0
inputs: {artifactName: 'drop', downloadPath: '.'}
- bash: cp drop/release/* .
displayName: Copy package
- bash: bash dependencies.sh
displayName: Install Rcpp and testthat
- bash: bash install.sh
displayName: Install package
- bash: bash download-ampl.sh $AMPL_URL
displayName: Install AMPL
- bash: SKIP_BIG_TESTS=1 PATH="`pwd`/ampl:$PATH" bash test.sh
displayName: Test package
# - job: windows
# pool: {vmImage: 'windows-2022'}
# variables: {AMPL_URL: '$(BUNDLES_URL)/$(MSWIN64_BUNDLE_NAME)'}
# steps:
# - task: DownloadBuildArtifacts@0
# inputs: {artifactName: 'drop', downloadPath: '.'}
# - bash: cp drop/release/* .
# displayName: Copy package
# # - bash: |
# # # Debug the following issue on azure pipelines:
# # # "C:/rtools40/mingw64/bin/"g++ -std=gnu++11 -shared -static-libgcc -o rAMPL.dll tmp.def RcppExports.o rampl.o rcon_entity.o rcon_instance.o renvironment.o robj_entity.o robj_instance.o rparam_entity.o rset_entity.o rset_instance.o rvar_entity.o rvar_instance.o utils.o -L../inst/libs/i386 -L../inst/libs/x64 -lampl -LC:/PROGRA~1/R/R-40~1.3/bin/x64 -lR
# # # /usr/bin/sh: line 8: "C:/rtools40/mingw64/bin/"g++ -std=gnu++11 : No such file or directory
# # # no DLL was created
# # set -ex
# # grep " -shared " -R `R RHOME`
# # cat `R RHOME`/etc/x64/Makeconf
# # cat `R RHOME`/etc/i386/Makeconf
# # cat `R RHOME`/share/make/winshlib.mk
# # displayName: Debug azure-pipelines issue
# - bash: |
# set -ex
# cat `R RHOME`/share/make/winshlib.mk
# sed -i 's/\$(SHLIB_LD)/c:\/rtools40\/mingw64\/bin\/g++/g' `R RHOME`/share/make/winshlib.mk
# cat `R RHOME`/share/make/winshlib.mk
# displayName: Hack to fix azure-pipelines issue
# - bash: bash dependencies.sh
# displayName: Install Rcpp and testthat
# - bash: bash install.sh
# displayName: Install package
# - bash: bash download-ampl.sh $AMPL_URL
# displayName: Install AMPL
# - bash: SKIP_BIG_TESTS=1 PATH="`pwd`/ampl:$PATH" bash test.sh
# displayName: Test package
25 changes: 25 additions & 0 deletions rAMPL/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
cd `dirname $0`
BASEDIR=`pwd`
set -ex

if [[ "$(python -V)" =~ "Python 3" ]]; then
PYTHON="python"
else
PYTHON="python3"
fi

cd docs
if [ ! -d "venv" ]; then
$PYTHON -m pip install virtualenv
$PYTHON -m virtualenv venv
source venv/bin/activate
$PYTHON -m pip install -r requirements-dev.txt
deactivate
fi
source venv/bin/activate
make html
deactivate
cd $BASEDIR
rm -rf rAMPL_*.tar.gz
R CMD build .
6 changes: 6 additions & 0 deletions rAMPL/dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
BASEDIR=`dirname $0`
cd $BASEDIR
set -ex

R --no-save -q -e "install.packages(c('Rcpp', 'testthat'), repos='http://cran.us.r-project.org', INSTALL_opts=c('--no-multiarch'))"
Loading

0 comments on commit 9bc061f

Please sign in to comment.