<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def as_vartype(vartype):
 """Cast various inputs to a valid vartype object. Args: vartype (:class:`.Vartype`/str/set):
 Variable type. Accepted input values: * :class:`.Vartype.SPIN`, ``'SPIN'``, ``{-1, 1}`` * :class:`.Vartype.BINARY`, ``'BINARY'``, ``{0, 1}`` Returns: :class:`.Vartype`: Either :class:`.Vartype.SPIN` or :class:`.Vartype.BINARY`. See also: :func:`~dimod.decorators.vartype_argument` """

    if isinstance(vartype, Vartype):
        return vartype

    try:
        if isinstance(vartype, str):
            vartype = Vartype[vartype]
        elif isinstance(vartype, frozenset):
            vartype = Vartype(vartype)
        else:
            vartype = Vartype(frozenset(vartype))

    except (ValueError, KeyError):
        raise TypeError(("expected input vartype to be one of: "
                         "Vartype.SPIN, 'SPIN', {-1, 1}, "
                         "Vartype.BINARY, 'BINARY', or {0, 1}."))

    return vartype