Skip to content

NLP parser assumes ::Model and violates MethodError principle #2402

@odow

Description

@odow

_process_NL_expr gets called from the @NL macros, and doesn't have any type requirements:

function _process_NL_expr(model, ex)

but it eventually calls a _process_NL_expr_runtime which are restricted to ::Model.
function _parse_NL_expr_runtime(m::Model, x::Real, tape, parent, values)

Thus, someone (e.g., BilevelJuMP, x-ref: joaquimg/BilevelJuMP.jl#57) using this machinery with an <:AbstractModel encounters a MethodError:
https://discourse.julialang.org/t/methoderror-no-method-matching-parse-nl-expr-runtime-bilevel-problem/51681

We could either add a type-restriction to _process_NL_expr and have a fallback with an informative error message, or we could probably relax the type-restrictions, and see what happens. It probably means relaxing this as well to AbstractVariableRef:

JuMP.jl/src/parse_nlp.jl

Lines 187 to 188 in 1e6b5d8

function _parse_NL_expr_runtime(m::Model, x::VariableRef, tape, parent, values)
if owner_model(x) !== m

cc @pulsipher who might be messing with this stuff

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions