def add_variable(self, v, bias, vartype=None):
        """Add variable v and/or its bias to a binary quadratic model.

        Args:
            v (variable):
                The variable to add to the model. Can be any python object
                that is a valid dict key.

            bias (bias):
                Linear bias associated with v. If v is already in the model, this value is added
                to its current linear bias. Many methods and functions expect `bias` to be a number
                but this is not explicitly checked.

            vartype (:class:`.Vartype`, optional, default=None):
                Vartype of the given bias. If None, the vartype of the binary
                quadratic model is used. Valid values are :class:`.Vartype.SPIN` or
                :class:`.Vartype.BINARY`.

        Examples:
            This example creates an Ising model with two variables, adds a third,
            and adds to the linear biases of the initial two.

            >>> import dimod
            ...
            >>> bqm = dimod.BinaryQuadraticModel({0: 0.0, 1: 1.0}, {(0, 1): 0.5}, -0.5, dimod.SPIN)
            >>> len(bqm.linear)
            2
            >>> bqm.add_variable(2, 2.0, vartype=dimod.SPIN)        # Add a new variable
            >>> bqm.add_variable(1, 0.33, vartype=dimod.SPIN)
            >>> bqm.add_variable(0, 0.33, vartype=dimod.BINARY)     # Binary value is converted to spin value
            >>> len(bqm.linear)
            3
            >>> bqm.linear[1]
            1.33

        """

        # handle the case that a different vartype is provided
        if vartype is not None and vartype is not self.vartype:
            if self.vartype is Vartype.SPIN and vartype is Vartype.BINARY:
                # convert from binary to spin
                bias /= 2
                self.offset += bias
            elif self.vartype is Vartype.BINARY and vartype is Vartype.SPIN:
                # convert from spin to binary
                self.offset -= bias
                bias *= 2
            else:
                raise ValueError("unknown vartype")

        # we used to do this using self.linear but working directly with _adj
        # is much faster
        _adj = self._adj
        if v in _adj:
            if v in _adj[v]:
                _adj[v][v] += bias
            else:
                _adj[v][v] = bias
        else:
            _adj[v] = {v: bias}

        try:
            self._counterpart.add_variable(v, bias, vartype=self.vartype)
        except AttributeError:
            pass