def from_serializable(cls, obj):
        """Deserialize a binary quadratic model.

        Args:
            obj (dict):
                A binary quadratic model serialized by :meth:`~.BinaryQuadraticModel.to_serializable`.

        Returns:
            :obj:`.BinaryQuadraticModel`

        Examples:

            Encode and decode using JSON

            >>> import dimod
            >>> import json
            ...
            >>> bqm = dimod.BinaryQuadraticModel({'a': -1.0, 'b': 1.0}, {('a', 'b'): -1.0}, 0.0, dimod.SPIN)
            >>> s = json.dumps(bqm.to_serializable())
            >>> new_bqm = dimod.BinaryQuadraticModel.from_serializable(json.loads(s))

        See also:
            :meth:`~.BinaryQuadraticModel.to_serializable`

            :func:`json.loads`, :func:`json.load` JSON deserialization functions

        """
        if obj.get("version", {"bqm_schema": "1.0.0"})["bqm_schema"] != "2.0.0":
            return cls._from_serializable_v1(obj)

        variables = [tuple(v) if isinstance(v, list) else v
                     for v in obj["variable_labels"]]

        if obj["use_bytes"]:
            ldata = bytes2array(obj["linear_biases"])
            qdata = bytes2array(obj["quadratic_biases"])
            irow = bytes2array(obj["quadratic_head"])
            icol = bytes2array(obj["quadratic_tail"])
        else:
            ldata = obj["linear_biases"]
            qdata = obj["quadratic_biases"]
            irow = obj["quadratic_head"]
            icol = obj["quadratic_tail"]

        offset = obj["offset"]
        vartype = obj["variable_type"]

        bqm = cls.from_numpy_vectors(ldata,
                                     (irow, icol, qdata),
                                     offset,
                                     str(vartype),  # handle unicode for py2
                                     variable_order=variables)

        bqm.info.update(obj["info"])
        return bqm
def from_serializable ( cls , obj ) : if obj . get ( "version" , { "bqm_schema" : "1.0.0" } ) [ "bqm_schema" ] != "2.0.0" : return cls . _from_serializable_v1 ( obj ) variables = [ tuple ( v ) if isinstance ( v , list ) else v for v in obj [ "variable_labels" ] ] if obj [ "use_bytes" ] : ldata = bytes2array ( obj [ "linear_biases" ] ) qdata = bytes2array ( obj [ "quadratic_biases" ] ) irow = bytes2array ( obj [ "quadratic_head" ] ) icol = bytes2array ( obj [ "quadratic_tail" ] ) else : ldata = obj [ "linear_biases" ] qdata = obj [ "quadratic_biases" ] irow = obj [ "quadratic_head" ] icol = obj [ "quadratic_tail" ] offset = obj [ "offset" ] vartype = obj [ "variable_type" ] bqm = cls . from_numpy_vectors ( ldata , ( irow , icol , qdata ) , offset , str ( vartype ) , variable_order = variables ) bqm . info . update ( obj [ "info" ] ) return bqm
Deserialize a binary quadratic model.

        Args:
            obj (dict):
                A binary quadratic model serialized by :meth:`~.BinaryQuadraticModel.to_serializable`.

        Returns:
            :obj:`.BinaryQuadraticModel`

        Examples:

            Encode and decode using JSON

            >>> import dimod
            >>> import json
            ...
            >>> bqm = dimod.BinaryQuadraticModel({'a': -1.0, 'b': 1.0}, {('a', 'b'): -1.0}, 0.0, dimod.SPIN)
            >>> s = json.dumps(bqm.to_serializable())
            >>> new_bqm = dimod.BinaryQuadraticModel.from_serializable(json.loads(s))

        See also:
            :meth:`~.BinaryQuadraticModel.to_serializable`

            :func:`json.loads`, :func:`json.load` JSON deserialization functions