Giter Club home page Giter Club logo

Comments (3)

odow avatar odow commented on June 5, 2024 1

Here's what I think you're after:

julia> using JuMP

julia> function convert_to_quad(model::Model, f::NonlinearExpr)
           g = convert(MOI.ScalarQuadraticFunction{Float64}, moi_function(f))
           return jump_function(model, g)
       end
convert_to_quad (generic function with 1 method)

julia> model = read_from_file("/tmp/model.nl"; use_nlp_block = false)
A JuMP Model
Maximization problem with:
Variables: 2
Objective function type: NonlinearExpr
`NonlinearExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint
`NonlinearExpr`-in-`MathOptInterface.LessThan{Float64}`: 1 constraint
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 2 constraints
`VariableRef`-in-`MathOptInterface.LessThan{Float64}`: 2 constraints
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> for (F, S) in list_of_constraint_types(model)
           if F == NonlinearExpr
               for ci in all_constraints(model, F, S)
                   obj = constraint_object(ci)
                   @constraint(model, convert_to_quad(model, obj.func) in obj.set)
                   delete(model, ci)
               end
           end
       end

julia> set_objective_function(model, convert_to_quad(model, objective_function(model)))

julia> model
A JuMP Model
Maximization problem with:
Variables: 2
Objective function type: QuadExpr
`QuadExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint
`QuadExpr`-in-`MathOptInterface.LessThan{Float64}`: 1 constraint
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 2 constraints
`VariableRef`-in-`MathOptInterface.LessThan{Float64}`: 2 constraints
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> write_to_file(model, "model.mps")

shell> cat model.mps
NAME          
ROWS
 N  OBJ
 L  c1_1
 G  c1
COLUMNS
    x1        c1_1      3
    x1        c1        2
    x1        OBJ       -1
    x2        c1_1      4
    x2        c1        3
    x2        OBJ       -2
RHS
    rhs       c1_1      15
    rhs       c1        7
RANGES
BOUNDS
 LO bounds    x1        1
 UP bounds    x1        10
 LO bounds    x2        1
 UP bounds    x2        10
QUADOBJ
QCMATRIX   c1_1
QCMATRIX   c1
ENDATA

from jump.jl.

odow avatar odow commented on June 5, 2024

MSK_RES_ERR_MPS_INV_FIELD

This suggests that you are telling Mosek to read it as a MPS file. You probably need to pass additional flags to ask it to read a .nl file.

Using amplpy in Python to read my_model.nl

I assume that amp.read is for .mod and .dat files. You probably need different syntax to read a .nl file into AMPL.

convert the nl file to mps file if possible.

You cannot do this. MPS does not support nonlinear, which is what

MathOptInterface.UnsupportedAttribute{MathOptInterface.NLPBlock}: Attribute MathOptInterface.NLPBlock() is not supported by the model.

is telling you.

from jump.jl.

odow avatar odow commented on June 5, 2024

Closing because this is not a bug in JuMP.

If you have follow-up questions, please post on the community forum, https://jump.dev/forum, and we can discuss there 😄

from jump.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.