E-SE0007 — Decorated function takes no arguments

Error Type

Syntax Error

Phase

defining a problem with the decorator API

Python exception

TypeError (builtin)

Message

A decorated function must take the problem to build or update as its first argument, but this one takes no arguments.

Possible fix: add a parameter such as `problem: jm.DecoratedProblem`.

Cause

The function decorated with @problem.update or @jijmodeling.Problem.define declares no parameters at all. The decorator API calls the function with the problem being built as its first argument, so the function must declare a first parameter to receive it.

@jm.Problem.define("My Problem")
def myprob():  # no parameter to receive the problem
    ...

Fix

Add a first parameter, conventionally declared as problem: jm.DecoratedProblem, and build the model through it.

@jm.Problem.define("My Problem")
def myprob(problem: jm.DecoratedProblem):
    w = problem.Float(ndim=1)
    x = problem.BinaryVar(shape=(w.len_at(0),))
    problem += jm.sum(w * x)