Skip to content

Commit

Permalink
Rewrite and overhaul of AmplNLWriter. (#125)
Browse files Browse the repository at this point in the history
* WIP: begin a rewrite and overhaul of AmplNLWriter.

Ideally, some, or all of this would be migrated into
MOI.FileFormats as an NL submodule.

This needs many more tests before merging.

This implementation is simplier than the current one, because it
doesn't try to detect or simplify linear expressions.

* Remove MathProgBase

* More updates

* More fixes

* More fixes

* More fixes

* More fixes

* Fix on Julia 1.0 and add comments

* More fixes

* More fixes

* Delete rev_opcode.jl

* More fixes

* Typos

* Add another test

* Update MOI_wrapper.jl

* Check ExprGraph available

* features_available

* Fix typo

* Change Optimizer to the copy_to interface

* Fix MINLPTests

* Fix part II
  • Loading branch information
odow authored Apr 11, 2021
1 parent 236f7ab commit 97d5e22
Show file tree
Hide file tree
Showing 20 changed files with 2,281 additions and 2,292 deletions.
2 changes: 0 additions & 2 deletions .solverdata/.gitignore

This file was deleted.

5 changes: 1 addition & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
name = "AmplNLWriter"
uuid = "7c4d4715-977e-5154-bfe0-e096adeac482"
version = "0.6.1"
version = "0.7.0"

[deps]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
MathProgBase = "fdba3010-5040-5b88-9595-932c9decdf73"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Ipopt = "0.6"
Ipopt_jll = "3.13.2"
MathOptInterface = "0.9.13"
MathProgBase = "~0.5.0, ~0.6, ~0.7"
julia = "1"

[extras]
Expand Down
68 changes: 30 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# AmplNLWriter.jl

This [Julia](https://github.com/JuliaLang/julia) package is an interface between
[MathOptInterface.jl](https://github.com/jump-dev/MathOptInterface.jl) and
[AMPL-enabled solvers](http://ampl.com/products/solvers/all-solvers-for-ampl/).
AmplNLWriter.jl is an interface between [MathOptInterface.jl](https://github.com/jump-dev/MathOptInterface.jl)
and [AMPL-enabled solvers](http://ampl.com/products/solvers/all-solvers-for-ampl/).

A list of AMPL-enabled solvers is available [here](http://ampl.com/products/solvers/all-solvers-for-ampl/).

*Development of AmplNLWriter.jl is community driven and has no official connection with the AMPL modeling language or AMPL Optimization Inc.*
*Development of AmplNLWriter.jl is community driven and has no official
connection with the AMPL modeling language or AMPL Optimization Inc.*

[![Build Status](https://github.com/jump-dev/AmplNLWriter.jl/workflows/CI/badge.svg?branch=master)](https://github.com/jump-dev/AmplNLWriter.jl/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/jump-dev/AmplNLWriter.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jump-dev/AmplNLWriter.jl)

## Installation

AmplNLWriter.jl can be installed using the Julia package manager with the
following command:
The package can be installed with `Pkg.add`.

```julia
import Pkg
Expand All @@ -23,25 +20,27 @@ Pkg.add("AmplNLWriter")

## Usage

AmplNLWriter.jl provides `AmplNLWriter.Optimizer` as a usable solver in JuMP.
The following Julia code uses the Bonmin solver in JuMP via AmplNLWriter.jl:
To call Ipopt via AmplNLWriter.jl, use:
```julia
using JuMP, AmplNLWriter, Ipopt_jll
model = Model(() -> AmplNLWriter.Optimizer(Ipopt_jll.amplexe))
```

Replace `Ipopt_jll` with `Bonmin_jll` or `Couenne_jll` as appropriate.

**Note: the `_jll` packages require Julia 1.3 or later.**

You can also pass a string pointing to an AMPL-compatible solver executable. For
example, if the `bonmin` executable is on the system path, it as follows:
```julia
using JuMP, AmplNLWriter
model = Model(() -> AmplNLWriter.Optimizer("bonmin"))
```

You can then model and solve your optimization problem as usual. See
[JuMP.jl](https://github.com/jump-dev/JuMP.jl/blob/master/README.md) for more
details.

The `AmplNLWriter.Optimizer()` constructor requires as the first argument the
name of the solver command needed to run the desired solver.
If the solver is not on the path, the full path to the solver will need to be
passed in.

For example, if the `bonmin` executable is on the system path, you can use
this solver using `AmplNLWriter.Optimizer("bonmin")`. If the solver is not on
the path, the full path to the solver will need to be passed in. This solver
executable must be an AMPL-compatible solver.
## Options

The second (optional) argument to `AmplNLWriter.Optimizer()` is a
`Vector{String}` of solver options. These options are appended to the solve
Expand All @@ -50,7 +49,7 @@ you are using. Generally, they will be of the form `"key=value"`, where `key` is
the name of the option to set and `value` is the desired value.

For example, to set the NLP log level to 0 in Bonmin, you would run
`AmplNLWriter.Optimizer("bonmin", ["bonmin.nlp_log_level=0"])`.
`AmplNLWriter.Optimizer(Bonmin_jll.amplexe, ["bonmin.nlp_log_level=0"])`.

For a list of options supported by your solver, check the solver's
documentation, or run `/path/to/solver -=` at the command line, e.g., run
Expand Down Expand Up @@ -78,28 +77,21 @@ A list of available options for the respective `.opt` files can be found here:
- [Bonmin](https://github.com/coin-or/Bonmin/blob/master/Bonmin/test/bonmin.opt) (plus Ipopt options)
- [Couenne](https://github.com/coin-or/Couenne/blob/master/Couenne/src/couenne.opt) (plus Ipopt and Bonmin options)

## Guides for specific solvers
## SCIP

### Bonmin/Couenne/Ipopt
To use SCIP, you must first compile the `scipampl` binary, which is a version of
SCIP with support for the AMPL .nl interface.

**NOTE: AmplNLWriter v0.4.0 introduced a breaking change by removing
`BonminNLSolver`, `CouenneNLSolver`, and `IpoptNLSolver`. Users are now expected
to pass the path of the solver executable to `AmplNLWriter.Optimizer`.**

The easiest way to obtain a solver executable for Bonmin, Couenne, or Ipopt is
to download one from [AMPL](https://ampl.com/products/solvers/open-source/).

### SCIP

To use SCIP with AmplNLWriter.jl, you must first compile the `scipampl` binary
which is a version of SCIP with support for the AMPL .nl interface. To do this,
you can follow the instructions [here](http://zverovich.net/2012/08/07/using-scip-with-ampl.html),
To do this, you can follow the instructions [here](http://zverovich.net/2012/08/07/using-scip-with-ampl.html),
which we have tested on OS X and Linux.

After doing this, you can access SCIP through
`AmplNLWriter.Optimizer("/path/to/scipampl")`. Options can be specified for SCIP
using a `scip.set` file, where each line is of the form `key = value`. For
example, the following `scip.set` file will set the verbosity level to 0:
`AmplNLWriter.Optimizer("/path/to/scipampl")`.

Options can be specified for SCIP using a `scip.set` file, where each line is of
the form `key = value`.

For example, the following `scip.set` file will set the verbosity level to 0:
```
display/verblevel = 0
```
Expand Down
15 changes: 15 additions & 0 deletions gen/gen.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This script builds the list of recognized ASL opcodes using the header files
# in ASL_jll. Only re-run it if AMPL adds new opcodes (which is unlikely).

using ASL_jll

open(joinpath(dirname(@__DIR__), "src", "opcode.jl"), "w") do io
println("""
# Do not modify. This file is automatically created by the script in `gen.jl`.
""")
filename = joinpath(ASL_jll.artifact_dir, "include", "opcode.hd")
for line in readlines(filename)
items = split(line, c -> c == '\t' || c == ' '; keepempty = false)
println(io, "const ", items[2], " = ", items[3])
end
end
Loading

0 comments on commit 97d5e22

Please sign in to comment.