Write .NL file containing JuMP model

Dear all,

I would ask you if there exists an easy way to write the .nl file corresponding to a JuMP problem. I already checked the solution proposed in https://discourse.julialang.org/t/how-to-write-nl-file-containing-jump-problem-using-amplnlwriter-jl/2954, but it seems no more working.

Thanks very much. Best regards,
Luca

2 Likes

Try write_to_file(model, "model.nl")

This isnt working for me, no matter which Optimizer I use.

Writing to .lp or .mps files is fine, but those are rejected by AMPL solvers. Where writing to .nl files results in weird formatting (that causes parse errors when I try to feed it to a solver.)

This is what my .nl file looks like, when I generate it with JuMP.write_to_file(model, "pentomino.nl")

g3 1 1 0
 7865 9126 1 0 12 0
 0 1
 0 0
 0 0 0
 0 0 0 1
 7865 0 0 0 0
 18919288 7865
 0 0
 0 0 0 0 0
C0
n0
C1

Hi @ink,

What’s the error? And with what solver? What happens if you use AmplNLWriter.jl?

Do you have a reproducible example? Can you send me the pentomino.nl file that gets written? Your Jacobian looks very dense.

I use AmplNLWriter with Bonmin_jll and it printed the same .nl file as when I just use HiGHS.Optimizer (without AmplNLWriter). I exported the model “normally” with JuMP.write_to_file(model, nl_path) - but when trying to load this file into AMPL in python (which supposedly accepts .nl files) with ampl.read(nl_filename), it threw a parse error. (The .nl file looks like it’s missing spaces or something, I’m not sure, I’ve never used this format before.)

I’ll try and prepare a minimal reproducible example, sure, since my codes are like 300+ lines long atm. Thank you for your interest in helping !

It’s also possible that ampl simply doesn’t accept .nl files at all? I know it prefers its own .mod and .dat files, but those are not trivial to generate with JuMP - I have to generate them manually from Julia by printing strings, which is kind of annoying (and error prone).

Edit: worth mentioning, my problem is linear. So I want to use specialized NL solvers like CPLEX and stuff, not Bonmin and those ones.

I haven’t used AMPLs Python API.

There might be a bug in how we’re writing the nl file or you might be calling AMPL wrong. Contact their support?

Why go via nl? Why not CPLEX.jl?

1 Like

Thanks for the help in DMs, seems that AMPL’s Python API doesn’t support the .nl file format at all, that’s where the problem lies.

To anwser why not CPLEX directly: I have an AMPL license which provides online CPLEX solving, but don’t have a CPLEX license personally, and my model is much too big for the free version (1000x1000 max), that’s why I used AMPL - and I was told it would read .nl files, not just .mod and .dat files, which was my mistake! Problem closed :grinning_face_with_smiling_eyes: