<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_networkx_graph(cls, G, vartype=None, node_attribute_name='bias', edge_attribute_name='bias'):
 """Create a binary quadratic model from a NetworkX graph. Args: G (:obj:`networkx.Graph`):
 A NetworkX graph with biases stored as node/edge attributes. vartype (:class:`.Vartype`/str/set, optional):
 Variable type for the binary quadratic model. Accepted input values: * :class:`.Vartype.SPIN`, ``'SPIN'``, ``{-1, 1}`` * :class:`.Vartype.BINARY`, ``'BINARY'``, ``{0, 1}`` If not provided, the `G` should have a vartype attribute. If `vartype` is provided and `G.vartype` exists then the argument overrides the property. node_attribute_name (hashable, optional, default='bias'):
 Attribute name for linear biases. If the node does not have a matching attribute then the bias defaults to 0. edge_attribute_name (hashable, optional, default='bias'):
 Attribute name for quadratic biases. If the edge does not have a matching attribute then the bias defaults to 0. Returns: :obj:`.BinaryQuadraticModel` Examples: -1 """

        if vartype is None:
            if not hasattr(G, 'vartype'):
                msg = ("either 'vartype' argument must be provided or "
                       "the given graph should have a vartype attribute.")
                raise ValueError(msg)
            vartype = G.vartype

        linear = G.nodes(data=node_attribute_name, default=0)
        quadratic = G.edges(data=edge_attribute_name, default=0)
        offset = getattr(G, 'offset', 0)

        return cls(linear, quadratic, offset, vartype)