dimod.decorators.vartype_argument

vartype_argument(*arg_names)[source]

Ensures the wrapped function receives valid vartype argument(s).

One or more argument names can be specified as a list of string arguments.

Parameters:*arg_names (list[str], argument names, optional, default='vartype') – Names of the constrained arguments in decorated function.
Returns:Function decorator.

Examples

>>> from dimod.decorators import vartype_argument
>>> @vartype_argument()
... def f(x, vartype):
...     print(vartype)
...
>>> f(1, 'SPIN')
Vartype.SPIN
>>> f(1, vartype='SPIN')
Vartype.SPIN
>>> @vartype_argument('y')
... def f(x, y):
...     print(y)
...
>>> f(1, 'SPIN')
Vartype.SPIN
>>> f(1, y='SPIN')
Vartype.SPIN
>>> @vartype_argument('z')
... def f(x, **kwargs):
...     print(kwargs['z'])
...
>>> f(1, z='SPIN')
Vartype.SPIN

Note

The decorated function can explicitly list (name) vartype arguments constrained by vartype_argument() or it can use a keyword arguments dict.

See also

as_vartype()