E-SE0013 — Decorated function parameter annotation does not match its kind
Error Type |
|
|---|---|
Phase |
applying |
Python exception |
|
Message
The parameter `{name}` is annotated as `{actual}`, but the problem defines `{name}` as a `{expected}`.
Possible fix: change the annotation to `{expected}`, or rename the parameter to refer to a `{actual}`.
Cause
A parameter of a function decorated with @problem.update is resolved either as the problem itself or by name against the decision variables, placeholders, category labels, and named expressions already defined in the problem. When the parameter also carries a type annotation (jm.DecisionVar, jm.Placeholder, jm.CategoryLabel, or jm.NamedExpr), it is checked against the kind of the variable actually found under that name. This error means the annotation and the variable’s real kind disagree — eg. the parameter is annotated jm.DecisionVar but the name actually refers to a placeholder. This error is also raised when a completely unrelated class is used or when the first parameter is annotated with anything other than DecoratedProblem.
Fix
Either correct the annotation to match the variable’s real kind, or rename the parameter to refer to a variable of the annotated kind:
problem = jm.Problem("example")
@problem.update
def _(problem: jm.DecoratedProblem):
b = problem.Placeholder("b", dtype=float)
@problem.update
def _(problem: jm.DecoratedProblem, b: jm.Placeholder): # not jm.DecisionVar
problem += b <= 1