Closed rlacjfjin closed 11 months ago
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.
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
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 :smile:
As the title suggests, I am currently using the write_to_file function from JuMP to create the my_model.nl file. I then want to solve this model using other solvers. Here are my attempts and results:
scip -f my_model.nl - No issues.
ipopt my_model.nl - No issues.
mosek my_model.nl - Error encountered: Reading started.
MOSEK error 1101 (MSK_RES_ERR_MPS_INV_FIELD): Field number 1 is invalid.
Using amplpy in Python to read my_model.nl:
My model may be used JuMP expression,NLexpression,constraint,NLconstraint functions, and my_model.nl file is:
I want to do:
MathOptInterface.UnsupportedAttribute{MathOptInterface.NLPBlock}: Attribute MathOptInterface.NLPBlock() is not supported by the model.
Can you help me? Thanks.