E-SE0010 — Calling a function already applied by the decorator
Error Type |
|
|---|---|
Phase |
calling a function already applied by the decorator API |
Python exception |
|
Message
The function `{name}` was already applied by the `@problem.update` decorator and cannot be called again.
Its updates are already reflected in the problem.
Possible fix: use the problem object you decorated directly.
({name} is the name of the original decorated function)
Cause
When @problem.update processes a function, it runs the function body exactly once to update the problem and replaces the function’s name with a placeholder object that cannot be called.
This error is raised when that placeholder is called afterwards, typically because the code tries to invoke the decorated function by hand.
problem = jm.Problem("My Problem")
@problem.update
def build(problem: jm.DecoratedProblem):
w = problem.Float(ndim=1)
x = problem.BinaryVar(shape=(w.len_at(0),))
problem += jm.sum(w * x)
build() # `build` was already applied by the decorator
Fix
Do not call the decorated function: its updates are already reflected in the problem, and the decorator does not return a new problem object.
Continue working with the original problem object you decorated, for example by evaluating it with instance data.
instance = problem.eval(instance_data)