Comments (3)
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.
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.
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)
- Coefficients of complex variables created with a GenericModel are always Float64
- LinearAlgebra.hermitian is incorrect
- *(::Real, ::Hermitian) is not hermitian HOT 5
- Cannot `convert` an object of type Float64 to an object of type JuMP.NonlinearExpr HOT 3
- Documentation Request: List whether a solver supports Indicator Constraints HOT 4
- Bullet point alignment in bibliography HOT 9
- Multiplication of matrix expression and variables leads to stack overflow and matmul error HOT 4
- Multiple Ranges for variables HOT 3
- Y' when Y is of type ::Matrix{NonlinearExpr} HOT 1
- Poor performance in complementarity models HOT 23
- Add a method for Complex(a,b) HOT 8
- MethodError with empty summations HOT 1
- Nonlinear subexpressions HOT 4
- Should error when trying to mix `NonlinearExpression` and `GenericNonlinearExpr` HOT 1
- Support normalized_coefficient for vector-valued constraints
- Precompilation in CI fails on v1.22 HOT 7
- Fuzzy search on unrecognized keyword arguments to give suggestions HOT 2
- Track failures on nightly HOT 3
- Possibly missing diagnostics for vector of vector of variables HOT 3
- Printing of large vectorized constraints should probably cause output eliding? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jump.jl.