Skip to content
Merged
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
9 changes: 3 additions & 6 deletions src/FileFormats/MOF/nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ function write_nlpblock(
model::Model,
name_map::Dict{MOI.VariableIndex,String},
) where {T<:Object}
# TODO(odow): is there a better way of checking if the NLPBlock is set?
nlp_block = try
MOI.get(model, MOI.NLPBlock())
catch ex
@assert isa(ex, KeyError)
return # No NLPBlock set.
nlp_block = MOI.get(model, MOI.NLPBlock())
if nlp_block === nothing
return
end
MOI.initialize(nlp_block.evaluator, [:ExprGraph])
variables = MOI.get(model, MOI.ListOfVariableIndices())
Expand Down
5 changes: 3 additions & 2 deletions src/FileFormats/NL/NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ MOI.initialize(::_LinearNLPEvaluator, ::Vector{Symbol}) = nothing
function MOI.copy_to(dest::Model, model::MOI.ModelLike)
mapping = MOI.Utilities.IndexMap()
# Initialize the NLP block.
nlp_block = try
has_nlp = MOI.NLPBlock() in MOI.get(model, MOI.ListOfModelAttributesSet())
nlp_block = if has_nlp
MOI.get(model, MOI.NLPBlock())
catch
else
MOI.NLPBlockData(MOI.NLPBoundsPair[], _LinearNLPEvaluator(), false)
end
if !(:ExprGraph in MOI.features_available(nlp_block.evaluator))
Expand Down
3 changes: 3 additions & 0 deletions src/Utilities/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ end
function _nlp_block(model::MOI.ModelLike)
try
block = MOI.get(model, MOI.NLPBlock())
if block === nothing
return
end
if :ExprGraph in MOI.features_available(block.evaluator)
MOI.initialize(block.evaluator, [:ExprGraph])
end
Expand Down
6 changes: 4 additions & 2 deletions src/Utilities/universalfallback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@ end

# Attributes
function _get(uf::UniversalFallback, attr::MOI.AbstractOptimizerAttribute)
return uf.optattr[attr]
return get(uf.optattr, attr, nothing)
end

_get(uf::UniversalFallback, attr::MOI.AbstractModelAttribute) = uf.modattr[attr]
function _get(uf::UniversalFallback, attr::MOI.AbstractModelAttribute)
return get(uf.modattr, attr, nothing)
end

function _get(
uf::UniversalFallback,
Expand Down
7 changes: 7 additions & 0 deletions test/Utilities/universalfallback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ function test_show()
return
end

function test_missing_attribute()
model = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
@test MOI.get(model, MOI.Test.UnknownModelAttribute()) === nothing
@test MOI.get(model, MOI.TimeLimitSec()) === nothing
return
end

end # module

TestUniversalFallback.runtests()