JuliaOpt / CoinOptServices.jl

Julia interface to COIN-OR Optimization Services https://projects.coin-or.org/OS
Other
16 stars 4 forks source link

Fails with JuMP example mle.jl (xml/parsing) #8

Closed sschnug closed 8 years ago

sschnug commented 8 years ago

My setup:

 Version 0.4.0 (2015-10-08 06:20 UTC)
 Official http://julialang.org/ release
 |  x86_64-unknown-linux-gnu

julia> Pkg.installed()
Dict{ASCIIString,VersionNumber} with 48 entries:
  "ImmutableArrays"   => v"0.0.10"
  "ArrayViews"        => v"0.6.4"
  "DataStructures"    => v"0.3.13"
  "Compat"            => v"0.7.6"
  "Calculus"          => v"0.1.13"
  "GZip"              => v"0.2.18"
  "MathProgBase"      => v"0.3.18"
  "StatsFuns"         => v"0.1.4"
  "DataFrames"        => v"0.6.10"
  "Showoff"           => v"0.0.6"
  "Distributions"     => v"0.8.7"
  "Clp"               => v"0.1.1"
  "FixedPointNumbers" => v"0.0.12"
  "SHA"               => v"0.1.2"
  "DualNumbers"       => v"0.1.5"
  "ReverseDiffSparse" => v"0.2.11"
  "KernelDensity"     => v"0.1.2"
  "Iterators"         => v"0.1.9"
  "ColorTypes"        => v"0.1.7"
  "Gadfly"            => v"0.3.17"
  "Lora"              => v"0.4.4"
  "Dates"             => v"0.4.4"
  "Contour"           => v"0.0.8"
  "PDMats"            => v"0.3.6"
  "Optim"             => v"0.4.3"
  "SortingAlgorithms" => v"0.0.6"
  "Docile"            => v"0.5.19"
  "WoodburyMatrices"  => v"0.1.2"
  "Grid"              => v"0.4.0"
  "JSON"              => v"0.5.0"
  "StatsBase"         => v"0.7.4"
  "Hexagons"          => v"0.0.4"
  "Distances"         => v"0.2.1"
  "Loess"             => v"0.0.4"
  "BinDeps"           => v"0.3.18"
  "CoinOptServices"   => v"0.0.6"
  "Cbc"               => v"0.1.8"
  "Reexport"          => v"0.0.3"
  "URIParser"         => v"0.1.1"
  "NaNMath"           => v"0.1.1"
  "ReverseDiffSource" => v"0.0.6"
  "JuMP"              => v"0.10.2"
  "Ipopt"             => v"0.1.17"
  "Compose"           => v"0.3.17"
  "DataArrays"        => v"0.2.19"
  "Colors"            => v"0.5.4"
  "Codecs"            => v"0.1.5"
  "LightXML"          => v"0.2.1"

Failing example (mle.jl from repo + changes to use CoinOptServices):

#  Copyright 2015, Iain Dunning, Joey Huchette, Miles Lubin, and contributors
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
#  file, You can obtain one at http://mozilla.org/MPL/2.0/.
using JuMP, CoinOptServices

# Use nonlinear optimization to compute the maximum likelihood estimate (MLE)
# of the parameters of a normal distribution
# aka the sample mean and variance

n = 1000
data = randn(n)

m = Model(solver = OsilSolver())

@defVar(m, μ, start = 0.0)
@defVar(m, σ >= 0.0, start = 1.0)

@setNLObjective(m, Max, (n/2)*log(1/(2π*σ^2))-sum{(data[i]-μ)^2, i=1:n}/(2σ^2))

solve(m)

println("μ = ", getValue(μ))
println("mean(data) = ", mean(data))
println("σ^2 = ", getValue(σ)^2)
println("var(data) = ", var(data))
println("MLE objective: ", getObjectiveValue(m))

# constrained MLE?
@addNLConstraint(m, μ == σ^2)

solve(m)
println("\nWith constraint μ == σ^2:")
println("μ = ", getValue(μ))
println("σ^2 = ", getValue(σ)^2)

println("Constrained MLE objective: ", getObjectiveValue(m))

Ouput / Error

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="OSrL.xslt"?>
<osrl xmlns="os.optimizationservices.org"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="os.optimizationservices.org http://www.optimizationservices.org/schemas/2.0/OSrL.xsd" >
<general>
<generalStatus type="error">
</generalStatus>
<message>encountered a spurious character in the lexer
The first character is: 
See line number: 28
</message>
</general>
</osrl>

WARNING: /home/sascha/.julia/v0.4/CoinOptServices/.osil/results.osrl is empty
ERROR: LoadError: UndefRefError: access to undefined reference
 in getsolution at /home/sascha/.julia/v0.4/CoinOptServices/src/probmod.jl:8
 in solvenlp at /home/sascha/.julia/v0.4/JuMP/src/nlp.jl:571
 in solve at /home/sascha/.julia/v0.4/JuMP/src/solvers.jl:62
 in include at ./boot.jl:261
 in include_from_node1 at ./loading.jl:304
 in process_options at ./client.jl:308
 in _start at ./client.jl:411
while loading /home/sascha/Projects/pyMINLP/test3.jl, in expression starting on line 21

Very interesting project! I'm trying to mimic this within a python-project (using OSServices & translating to XML; only a small portion of functionality; early stage) and stumbled upon the above error when trying to compare the instance-xml's.

mlubin commented 8 years ago

@sschnug, have you looked at using Pyomo? It has a built-in NL file writer which is much more reliable than OSiL for connecting to solvers.

tkelman commented 8 years ago

Can you post the /home/sascha/.julia/v0.4/CoinOptServices/.osil/problem.osil to gist.github.com and link to it here?

To save you some headaches, if you're working in Python I'd recommend using Pyomo to write .nl files. OS has many bugs, see #6 as one example.

sschnug commented 8 years ago

Gist of problem.osil

EDIT: Not sure if it matters: this example seems to be one of few (or the only one), that's calling solve(m) twice and add a constraint between both calls!

@mlubin & @tkelman Thank you both for the mentioning of Pyomo, which i was aware of. If i'm right, Pyomo works in the same style as Ampl which means, that you need to leave your programming-language and work with some custom-language which i don't like at all (and which i think is the reason for a lot of people using tools like JuMP).

(I just closed this issue by accident)

mlubin commented 8 years ago

@sschnug, Pyomo was designed to be standalone like AMPL, though it's possible to use it embedded inside a normal python script. You'll have to consult their documentation.

sschnug commented 8 years ago

@mlubin Thanks for mentioning this possibility. I think i will give it another try.

Nonetheless i like the approach of CoinOptServices (linking to the huge world of Coin-projects), even if it is kind of experimental (or dependent on the maturity of other tools).

tkelman commented 8 years ago

I missed that you uploaded the osil file via an edit, github didn't send a notification. There was a bug in handling of the MathConst π which I just fixed. If you still have issues let me know.