Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNMY: [FileFormats.MOF] change parse_as_nlpblock to false by default #2295

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function get_options(m::Model)
return get(
m.model.ext,
:MOF_OPTIONS,
Options(false, false, MOI.Nonlinear.SparseReverseMode(), true),
Options(false, false, MOI.Nonlinear.SparseReverseMode(), false),
)
end

Expand All @@ -140,15 +140,15 @@ Keyword arguments are:
- `differentiation_backend::MOI.Nonlinear.AbstractAutomaticDifferentiation = MOI.Nonlinear.SparseReverseMode()`:
automatic differentiation backend to use when reading models with nonlinear
constraints and objectives.
- `parse_as_nlpblock::Bool=true`: if `true` parse `"ScalarNonlinearFunction"`
- `parse_as_nlpblock::Bool=false`: if `true` parse `"ScalarNonlinearFunction"`
into an `MOI.NLPBlock`. If `false`, `"ScalarNonlinearFunction"` are parsed as
`MOI.ScalarNonlinearFunction` functions.
"""
function Model(;
print_compact::Bool = false,
warn::Bool = false,
differentiation_backend::MOI.Nonlinear.AbstractAutomaticDifferentiation = MOI.Nonlinear.SparseReverseMode(),
parse_as_nlpblock::Bool = true,
parse_as_nlpblock::Bool = false,
)
model = MOI.Utilities.UniversalFallback(InnerModel{Float64}())
model.model.ext[:MOF_OPTIONS] =
Expand Down
12 changes: 5 additions & 7 deletions test/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function test_HS071()
end

function test_read_HS071()
model = MOF.Model()
model = MOF.Model(; parse_as_nlpblock = true)
MOI.read_from_file(model, joinpath(@__DIR__, "nlp.mof.json"))
@test MOI.get(model, MOI.ListOfConstraintTypesPresent()) ==
Tuple{Type,Type}[(MOI.VariableIndex, MOI.Interval{Float64})]
Expand Down Expand Up @@ -283,7 +283,7 @@ function test_nonlinear_readingwriting()
MOI.set(model, MOI.ConstraintName(), con, "con")
MOI.write_to_file(model, TEST_MOF_FILE)
# Read the model back in.
model2 = MOF.Model()
model2 = MOF.Model(; parse_as_nlpblock = true)
MOI.read_from_file(model2, TEST_MOF_FILE)
block = MOI.get(model2, MOI.NLPBlock())
MOI.initialize(block.evaluator, [:ExprGraph])
Expand Down Expand Up @@ -748,8 +748,7 @@ variables: x
minobjective: ScalarNonlinearFunction(exp(x))
""",
["x"],
String[];
parse_as_nlpblock = false,
String[],
)
end

Expand All @@ -760,8 +759,7 @@ variables: x
c1: ScalarNonlinearFunction(exp(x)^2) <= 1.0
""",
["x"],
["c1"];
parse_as_nlpblock = false,
["c1"],
)
end

Expand Down Expand Up @@ -1423,7 +1421,7 @@ function test_parse_nonlinear_objective_only()
}""",
)
seekstart(io)
model = MOF.Model()
model = MOF.Model(; parse_as_nlpblock = true)
read!(io, model)
block = MOI.get(model, MOI.NLPBlock())
@test block isa MOI.NLPBlockData
Expand Down