417417function MOI. optimize! (model:: Optimizer )
418418 model. diff = nothing
419419 MOI. optimize! (model. optimizer)
420-
421- # do not fail. interferes with MOI.Tests.linear12test
422- if ! in (MOI. get (model. optimizer, MOI. TerminationStatus ()), (MOI. LOCALLY_SOLVED, MOI. OPTIMAL))
423- @warn " problem status: $(MOI. get (model. optimizer, MOI. TerminationStatus ())) "
424- return
425- end
426-
427420 return
428421end
429422
@@ -486,6 +479,10 @@ The output problem data differentials can be queried with the
486479attributes [`BackwardOutObjective`](@ref) and [`BackwardOutConstraint`](@ref).
487480"""
488481function backward (model:: Optimizer )
482+ st = MOI. get (model. optimizer, MOI. TerminationStatus ())
483+ if ! in (st, (MOI. LOCALLY_SOLVED, MOI. OPTIMAL))
484+ error (" Trying to compute the forward differentiation on a model with termination status $(st) " )
485+ end
489486 diff = _diff (model)
490487 for (vi, value) in model. input_cache. dx
491488 MOI. set (diff, BackwardInVariablePrimal (), model. index_map[vi], value)
@@ -510,6 +507,10 @@ The output solution differentials can be queried with the attribute
510507[`ForwardOutVariablePrimal`](@ref).
511508"""
512509function forward (model:: Optimizer )
510+ st = MOI. get (model. optimizer, MOI. TerminationStatus ())
511+ if ! in (st, (MOI. LOCALLY_SOLVED, MOI. OPTIMAL))
512+ error (" Trying to compute the forward differentiation on a model with termination status $(st) " )
513+ end
513514 diff = _diff (model)
514515 if model. input_cache. objective != = nothing
515516 MOI. set (diff, ForwardInObjective (), MOI. Utilities. map_indices (model. index_map, model. input_cache. objective))
0 commit comments